Skip to content

Commit 04f8433

Browse files
committed
Added vCard field to Contact
1 parent d4b5bd4 commit 04f8433

File tree

8 files changed

+44
-5
lines changed

8 files changed

+44
-5
lines changed

telegram/bot.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,7 @@ def send_contact(self,
10931093
phone_number=None,
10941094
first_name=None,
10951095
last_name=None,
1096+
vcard=None,
10961097
disable_notification=False,
10971098
reply_to_message_id=None,
10981099
reply_markup=None,
@@ -1111,6 +1112,8 @@ def send_contact(self,
11111112
phone_number (:obj:`str`, optional): Contact's phone number.
11121113
first_name (:obj:`str`, optional): Contact's first name.
11131114
last_name (:obj:`str`, optional): Contact's last name.
1115+
vcard (:obj:`str`, optional): Additional data about the contact in the form of a vCard,
1116+
0-2048 bytes
11141117
contact (:class:`telegram.Contact`, optional): The contact to send.
11151118
disable_notification (:obj:`bool`, optional): Sends the message silently. Users will
11161119
receive a notification with no sound.
@@ -1141,11 +1144,14 @@ def send_contact(self,
11411144
phone_number = contact.phone_number
11421145
first_name = contact.first_name
11431146
last_name = contact.last_name
1147+
vcard = contact.vcard
11441148

11451149
data = {'chat_id': chat_id, 'phone_number': phone_number, 'first_name': first_name}
11461150

11471151
if last_name:
11481152
data['last_name'] = last_name
1153+
if vcard:
1154+
data['vcard'] = vcard
11491155

11501156
return url, data
11511157

telegram/files/contact.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,27 @@ class Contact(TelegramObject):
2929
first_name (:obj:`str`): Contact's first name.
3030
last_name (:obj:`str`): Optional. Contact's last name.
3131
user_id (:obj:`int`): Optional. Contact's user identifier in Telegram.
32+
vcard (:obj:`str`): Optional. Additional data about the contact in the form of a vCard
3233
3334
Args:
3435
phone_number (:obj:`str`): Contact's phone number.
3536
first_name (:obj:`str`): Contact's first name.
3637
last_name (:obj:`str`, optional): Contact's last name.
3738
user_id (:obj:`int`, optional): Contact's user identifier in Telegram.
39+
vcard (:obj:`str`, optional): Additional data about the contact in the form of a vCard
3840
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
3941
4042
"""
4143

42-
def __init__(self, phone_number, first_name, last_name=None, user_id=None, **kwargs):
44+
def __init__(self, phone_number, first_name, last_name=None, user_id=None, vcard=None,
45+
**kwargs):
4346
# Required
4447
self.phone_number = str(phone_number)
4548
self.first_name = first_name
4649
# Optionals
4750
self.last_name = last_name
4851
self.user_id = user_id
52+
self.vcard = vcard
4953

5054
self._id_attrs = (self.phone_number,)
5155

telegram/inline/inlinequeryresultcontact.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class InlineQueryResultContact(InlineQueryResult):
3333
phone_number (:obj:`str`): Contact's phone number.
3434
first_name (:obj:`str`): Contact's first name.
3535
last_name (:obj:`str`): Optional. Contact's last name.
36+
vcard (:obj:`str`): Optional. Additional data about the contact in the form of a vCard,
37+
0-2048 bytes
3638
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
3739
to the message.
3840
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
@@ -46,6 +48,8 @@ class InlineQueryResultContact(InlineQueryResult):
4648
phone_number (:obj:`str`): Contact's phone number.
4749
first_name (:obj:`str`): Contact's first name.
4850
last_name (:obj:`str`, optional): Contact's last name.
51+
vcard :obj:`str`, optional): Additional data about the contact in the form of a vCard,
52+
0-2048 bytes
4953
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
5054
to the message.
5155
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
@@ -62,6 +66,7 @@ def __init__(self,
6266
phone_number,
6367
first_name,
6468
last_name=None,
69+
vcard=None,
6570
reply_markup=None,
6671
input_message_content=None,
6772
thumb_url=None,
@@ -76,6 +81,8 @@ def __init__(self,
7681
# Optionals
7782
if last_name:
7883
self.last_name = last_name
84+
if vcard:
85+
self.vcard = vcard
7986
if reply_markup:
8087
self.reply_markup = reply_markup
8188
if input_message_content:

telegram/inline/inputcontactmessagecontent.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,23 @@ class InputContactMessageContent(InputMessageContent):
2828
phone_number (:obj:`str`): Contact's phone number.
2929
first_name (:obj:`str`): Contact's first name.
3030
last_name (:obj:`str`): Optional. Contact's last name.
31+
vcard (:obj:`str`): Optional. Additional data about the contact in the form of a vCard,
32+
0-2048 bytes
3133
3234
Args:
3335
phone_number (:obj:`str`): Contact's phone number.
3436
first_name (:obj:`str`): Contact's first name.
3537
last_name (:obj:`str`, optional): Contact's last name.
38+
vcard (:obj:`str`, optional): Additional data about the contact in the form of a vCard,
39+
0-2048 bytes
3640
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
3741
3842
"""
3943

40-
def __init__(self, phone_number, first_name, last_name=None, **kwargs):
44+
def __init__(self, phone_number, first_name, last_name=None, vcard=None, **kwargs):
4145
# Required
4246
self.phone_number = phone_number
4347
self.first_name = first_name
4448
# Optionals
4549
self.last_name = last_name
50+
self.vcard = vcard

tests/test_bot.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,15 @@ def test_send_contact(self, bot, chat_id):
132132
phone_number = '+11234567890'
133133
first_name = 'Leandro'
134134
last_name = 'Toledo'
135+
vcard = 'vCard'
135136
message = bot.send_contact(chat_id=chat_id, phone_number=phone_number,
136-
first_name=first_name, last_name=last_name)
137+
first_name=first_name, last_name=last_name, vcard=vcard)
137138

138139
assert message.contact
139140
assert message.contact.phone_number == phone_number
140141
assert message.contact.first_name == first_name
141142
assert message.contact.last_name == last_name
143+
assert message.contact.vcard == vcard
142144

143145
@pytest.mark.skipif(os.getenv('APPVEYOR'), reason='No game made for Appveyor bot (''yet)')
144146
@flaky(3, 1)

tests/test_contact.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class TestContact(object):
3333
first_name = 'Leandro'
3434
last_name = 'Toledo'
3535
user_id = 23
36+
vcard = 'vCard'
3637

3738
def test_de_json_required(self, bot):
3839
json_dict = {'phone_number': self.phone_number, 'first_name': self.first_name}
@@ -43,19 +44,22 @@ def test_de_json_required(self, bot):
4344

4445
def test_de_json_all(self, bot):
4546
json_dict = {'phone_number': self.phone_number, 'first_name': self.first_name,
46-
'last_name': self.last_name, 'user_id': self.user_id}
47+
'last_name': self.last_name, 'user_id': self.user_id,
48+
'vcard': self.vcard}
4749
contact = Contact.de_json(json_dict, bot)
4850

4951
assert contact.phone_number == self.phone_number
5052
assert contact.first_name == self.first_name
5153
assert contact.last_name == self.last_name
5254
assert contact.user_id == self.user_id
55+
assert contact.vcard == self.vcard
5356

5457
def test_send_with_contact(self, monkeypatch, bot, chat_id, contact):
5558
def test(_, url, data, **kwargs):
5659
phone = data['phone_number'] == contact.phone_number
5760
first = data['first_name'] == contact.first_name
5861
last = data['last_name'] == contact.last_name
62+
vcard = data['vcard'] == contact.vcard
5963
return phone and first and last
6064

6165
monkeypatch.setattr('telegram.utils.request.Request.post', test)
@@ -74,6 +78,7 @@ def test_to_dict(self, contact):
7478
assert contact_dict['first_name'] == contact.first_name
7579
assert contact_dict['last_name'] == contact.last_name
7680
assert contact_dict['user_id'] == contact.user_id
81+
assert contact_dict['vcard'] == contact.vcard
7782

7883
def test_equality(self):
7984
a = Contact(self.phone_number, self.first_name)

tests/test_inlinequeryresultcontact.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def inline_query_result_contact():
3030
TestInlineQueryResultContact.phone_number,
3131
TestInlineQueryResultContact.first_name,
3232
last_name=TestInlineQueryResultContact.last_name,
33+
vcard=TestInlineQueryResultContact.vcard,
3334
thumb_url=TestInlineQueryResultContact.thumb_url,
3435
thumb_width=TestInlineQueryResultContact.thumb_width,
3536
thumb_height=TestInlineQueryResultContact.thumb_height,
@@ -43,6 +44,7 @@ class TestInlineQueryResultContact(object):
4344
phone_number = 'phone_number'
4445
first_name = 'first_name'
4546
last_name = 'last_name'
47+
vcard = 'vCard'
4648
thumb_url = 'thumb url'
4749
thumb_width = 10
4850
thumb_height = 15
@@ -55,6 +57,7 @@ def test_expected_values(self, inline_query_result_contact):
5557
assert inline_query_result_contact.phone_number == self.phone_number
5658
assert inline_query_result_contact.first_name == self.first_name
5759
assert inline_query_result_contact.last_name == self.last_name
60+
assert inline_query_result_contact.vcard == self.vcard
5861
assert inline_query_result_contact.thumb_url == self.thumb_url
5962
assert inline_query_result_contact.thumb_width == self.thumb_width
6063
assert inline_query_result_contact.thumb_height == self.thumb_height
@@ -74,6 +77,8 @@ def test_to_dict(self, inline_query_result_contact):
7477
inline_query_result_contact.first_name)
7578
assert (inline_query_result_contact_dict['last_name'] ==
7679
inline_query_result_contact.last_name)
80+
assert (inline_query_result_contact_dict['vcard'] ==
81+
inline_query_result_contact.vcard)
7782
assert (inline_query_result_contact_dict['thumb_url'] ==
7883
inline_query_result_contact.thumb_url)
7984
assert (inline_query_result_contact_dict['thumb_width'] ==

tests/test_inputcontactmessagecontent.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,21 @@
2626
def input_contact_message_content():
2727
return InputContactMessageContent(TestInputContactMessageContent.phone_number,
2828
TestInputContactMessageContent.first_name,
29-
last_name=TestInputContactMessageContent.last_name)
29+
last_name=TestInputContactMessageContent.last_name,
30+
vcard=TestInputContactMessageContent.vCard)
3031

3132

3233
class TestInputContactMessageContent(object):
3334
phone_number = 'phone number'
3435
first_name = 'first name'
3536
last_name = 'last name'
37+
vCard = 'My vCard text'
3638

3739
def test_expected_values(self, input_contact_message_content):
3840
assert input_contact_message_content.first_name == self.first_name
3941
assert input_contact_message_content.phone_number == self.phone_number
4042
assert input_contact_message_content.last_name == self.last_name
43+
assert input_contact_message_content.vCard == self.vCard
4144

4245
def test_to_dict(self, input_contact_message_content):
4346
input_contact_message_content_dict = input_contact_message_content.to_dict()
@@ -49,3 +52,5 @@ def test_to_dict(self, input_contact_message_content):
4952
input_contact_message_content.first_name)
5053
assert (input_contact_message_content_dict['last_name'] ==
5154
input_contact_message_content.last_name)
55+
assert (input_contact_message_content_dict['vcard'] ==
56+
input_contact_message_content.vcard)

0 commit comments

Comments
 (0)