mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-03-13 19:27:58 +01:00
Adding Contact model
This commit is contained in:
parent
dadad120fc
commit
0c7f649f41
3 changed files with 29 additions and 2 deletions
|
@ -17,7 +17,7 @@ from audio import Audio
|
||||||
from document import Document
|
from document import Document
|
||||||
from sticker import Sticker
|
from sticker import Sticker
|
||||||
from video import Video
|
from video import Video
|
||||||
# from contact import Contact
|
from contact import Contact
|
||||||
from location import Location
|
from location import Location
|
||||||
from chataction import ChatAction
|
from chataction import ChatAction
|
||||||
# from inputfile import InputFile
|
# from inputfile import InputFile
|
||||||
|
|
|
@ -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))
|
|
@ -95,6 +95,12 @@ class Message(object):
|
||||||
else:
|
else:
|
||||||
video = None
|
video = None
|
||||||
|
|
||||||
|
if 'contact' in data:
|
||||||
|
from telegram import Contact
|
||||||
|
contact = Contact.newFromJsonDict(data['contact'])
|
||||||
|
else:
|
||||||
|
contact = None
|
||||||
|
|
||||||
if 'location' in data:
|
if 'location' in data:
|
||||||
from telegram import Location
|
from telegram import Location
|
||||||
location = Location.newFromJsonDict(data['location'])
|
location = Location.newFromJsonDict(data['location'])
|
||||||
|
@ -130,7 +136,7 @@ class Message(object):
|
||||||
photo=photo,
|
photo=photo,
|
||||||
sticker=sticker,
|
sticker=sticker,
|
||||||
video=video,
|
video=video,
|
||||||
contact=data.get('contact', None),
|
contact=contact,
|
||||||
location=location,
|
location=location,
|
||||||
new_chat_participant=new_chat_participant,
|
new_chat_participant=new_chat_participant,
|
||||||
left_chat_participant=left_chat_participant,
|
left_chat_participant=left_chat_participant,
|
||||||
|
|
Loading…
Add table
Reference in a new issue