diff --git a/telegram/__init__.py b/telegram/__init__.py index 5ae7ce6a0..4ba5705c4 100644 --- a/telegram/__init__.py +++ b/telegram/__init__.py @@ -17,7 +17,7 @@ from audio import Audio from document import Document from sticker import Sticker from video import Video -# from contact import Contact +from contact import Contact from location import Location from chataction import ChatAction # from inputfile import InputFile diff --git a/telegram/contact.py b/telegram/contact.py index e69de29bb..c0928e2fd 100644 --- a/telegram/contact.py +++ b/telegram/contact.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python + + +class Contact(object): + def __init__(self, **kwargs): + param_defaults = { + 'phone_number': None, + 'first_name': None, + 'last_name': None, + 'user_id': None + } + + for (param, default) in param_defaults.iteritems(): + setattr(self, param, kwargs.get(param, default)) + + @staticmethod + def newFromJsonDict(data): + return Contact(phone_number=data.get('phone_number', None), + first_name=data.get('first_name', None), + last_name=data.get('last_name', None), + user_id=data.get('user_id', None)) diff --git a/telegram/message.py b/telegram/message.py index fca6d8e86..f5432609a 100644 --- a/telegram/message.py +++ b/telegram/message.py @@ -95,6 +95,12 @@ class Message(object): else: video = None + if 'contact' in data: + from telegram import Contact + contact = Contact.newFromJsonDict(data['contact']) + else: + contact = None + if 'location' in data: from telegram import Location location = Location.newFromJsonDict(data['location']) @@ -130,7 +136,7 @@ class Message(object): photo=photo, sticker=sticker, video=video, - contact=data.get('contact', None), + contact=contact, location=location, new_chat_participant=new_chat_participant, left_chat_participant=left_chat_participant,