Skip to content

Commit 6e15804

Browse files
committed
API updates Oct and Nov
1 parent d791a6e commit 6e15804

7 files changed

Lines changed: 60 additions & 51 deletions

File tree

telegram/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
from .base import TelegramObject
2525
from .user import User
26-
from .groupchat import GroupChat
26+
from .chat import Chat
2727
from .photosize import PhotoSize
2828
from .audio import Audio
2929
from .voice import Voice
@@ -54,5 +54,5 @@
5454
'InputFile', 'ReplyMarkup', 'ForceReply', 'ReplyKeyboardHide',
5555
'ReplyKeyboardMarkup', 'UserProfilePhotos', 'ChatAction',
5656
'Location', 'Contact', 'Video', 'Sticker', 'Document', 'File',
57-
'Audio', 'PhotoSize', 'GroupChat', 'Update', 'ParseMode', 'Message',
57+
'Audio', 'PhotoSize', 'Chat', 'Update', 'ParseMode', 'Message',
5858
'User', 'TelegramObject', 'NullHandler', 'Voice']

telegram/bot.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,7 @@ def sendMessage(self,
191191
192192
Args:
193193
chat_id:
194-
Unique identifier for the message recipient - telegram.User or
195-
telegram.GroupChat id.
194+
Unique identifier for the message recipient - telegram.Chat id.
196195
parse_mode:
197196
Send Markdown, if you want Telegram apps to show bold, italic and
198197
inline URLs in your bot's message. For the moment, only Telegram
@@ -234,10 +233,10 @@ def forwardMessage(self,
234233
235234
Args:
236235
chat_id:
237-
Unique identifier for the message recipient - User or GroupChat id.
236+
Unique identifier for the message recipient - Chat id.
238237
from_chat_id:
239238
Unique identifier for the chat where the original message was sent
240-
- User or GroupChat id.
239+
- Chat id.
241240
message_id:
242241
Unique message identifier.
243242
@@ -268,7 +267,7 @@ def sendPhoto(self,
268267
269268
Args:
270269
chat_id:
271-
Unique identifier for the message recipient - User or GroupChat id.
270+
Unique identifier for the message recipient - Chat id.
272271
photo:
273272
Photo to send. You can either pass a file_id as String to resend a
274273
photo that is already on the Telegram servers, or upload a new
@@ -319,7 +318,7 @@ def sendAudio(self,
319318
320319
Args:
321320
chat_id:
322-
Unique identifier for the message recipient - User or GroupChat id.
321+
Unique identifier for the message recipient - Chat id.
323322
audio:
324323
Audio file to send. You can either pass a file_id as String to
325324
resend an audio that is already on the Telegram servers, or upload
@@ -366,7 +365,7 @@ def sendDocument(self,
366365
367366
Args:
368367
chat_id:
369-
Unique identifier for the message recipient - User or GroupChat id.
368+
Unique identifier for the message recipient - Chat id.
370369
document:
371370
File to send. You can either pass a file_id as String to resend a
372371
file that is already on the Telegram servers, or upload a new file
@@ -405,7 +404,7 @@ def sendSticker(self,
405404
406405
Args:
407406
chat_id:
408-
Unique identifier for the message recipient - User or GroupChat id.
407+
Unique identifier for the message recipient - Chat id.
409408
sticker:
410409
Sticker to send. You can either pass a file_id as String to resend
411410
a sticker that is already on the Telegram servers, or upload a new
@@ -441,7 +440,7 @@ def sendVideo(self,
441440
442441
Args:
443442
chat_id:
444-
Unique identifier for the message recipient - User or GroupChat id.
443+
Unique identifier for the message recipient - Chat id.
445444
video:
446445
Video to send. You can either pass a file_id as String to resend a
447446
video that is already on the Telegram servers, or upload a new
@@ -490,7 +489,7 @@ def sendVoice(self,
490489
491490
Args:
492491
chat_id:
493-
Unique identifier for the message recipient - User or GroupChat id.
492+
Unique identifier for the message recipient - Chat id.
494493
voice:
495494
Audio file to send. You can either pass a file_id as String to
496495
resend an audio that is already on the Telegram servers, or upload
@@ -529,7 +528,7 @@ def sendLocation(self,
529528
530529
Args:
531530
chat_id:
532-
Unique identifier for the message recipient - User or GroupChat id.
531+
Unique identifier for the message recipient - Chat id.
533532
latitude:
534533
Latitude of location.
535534
longitude:
@@ -565,7 +564,7 @@ def sendChatAction(self,
565564
566565
Args:
567566
chat_id:
568-
Unique identifier for the message recipient - User or GroupChat id.
567+
Unique identifier for the message recipient - Chat id.
569568
action:
570569
Type of action to broadcast. Choose one, depending on what the user
571570
is about to receive:
Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,25 @@
1717
# You should have received a copy of the GNU Lesser Public License
1818
# along with this program. If not, see [http://www.gnu.org/licenses/].
1919

20-
"""This module contains a object that represents a Telegram GroupChat"""
20+
"""This module contains a object that represents a Telegram Chat"""
2121

2222
from telegram import TelegramObject
2323

2424

25-
class GroupChat(TelegramObject):
26-
"""This object represents a Telegram GroupChat.
25+
class Chat(TelegramObject):
26+
"""This object represents a Telegram Chat.
2727
2828
Attributes:
2929
id (int):
30-
title (str):
31-
type (str):
30+
type (str): Can be 'private', 'group', 'supergroup' or 'channel'
31+
title (str): Title, for channels and group chats
32+
username (str): Username, for private chats and channels if available
33+
first_name (str): First name of the other party in a private chat
34+
last_name (str): Last name of the other party in a private chat
3235
3336
Args:
3437
id (int):
35-
title (str):
38+
type (str):
3639
**kwargs: Arbitrary keyword arguments.
3740
3841
Keyword Args:
@@ -41,24 +44,27 @@ class GroupChat(TelegramObject):
4144

4245
def __init__(self,
4346
id,
44-
title,
47+
type,
4548
**kwargs):
4649
# Required
4750
self.id = int(id)
48-
self.title = title
51+
self.type = type
4952
# Optionals
50-
self.type = kwargs.get('type', '')
53+
self.title = kwargs.get('title', '')
54+
self.username = kwargs.get('username', '')
55+
self.first_name = kwargs.get('first_name', '')
56+
self.last_name = kwargs.get('last_name', '')
5157

5258
@staticmethod
5359
def de_json(data):
5460
"""
5561
Args:
56-
data (str):
62+
data (dict):
5763
5864
Returns:
59-
telegram.GroupChat:
65+
telegram.Chat:
6066
"""
6167
if not data:
6268
return None
6369

64-
return GroupChat(**data)
70+
return Chat(**data)

telegram/message.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from datetime import datetime
2323
from time import mktime
2424

25-
from telegram import (Audio, Contact, Document, GroupChat, Location, PhotoSize,
25+
from telegram import (Audio, Contact, Document, Chat, Location, PhotoSize,
2626
Sticker, TelegramObject, User, Video, Voice)
2727

2828

@@ -60,7 +60,7 @@ class Message(TelegramObject):
6060
message_id (int):
6161
from_user (:class:`telegram.User`):
6262
date (:class:`datetime.datetime`):
63-
chat (:class:`telegram.User` or :class:`telegram.GroupChat`):
63+
chat (:class:`telegram.User` or :class:`telegram.Chat`):
6464
**kwargs: Arbitrary keyword arguments.
6565
6666
Keyword Args:
@@ -116,6 +116,12 @@ def __init__(self,
116116
self.new_chat_photo = kwargs.get('new_chat_photo')
117117
self.delete_chat_photo = bool(kwargs.get('delete_chat_photo', False))
118118
self.group_chat_created = bool(kwargs.get('group_chat_created', False))
119+
self.supergroup_chat_created = bool(kwargs.get(
120+
'supergroup_chat_created', False))
121+
self.migrate_to_chat_id = int(kwargs.get('migrate_to_chat_id', 0))
122+
self.migrate_from_chat_id = int(kwargs.get('migrate_from_chat_id', 0))
123+
self.channel_chat_created = bool(kwargs.get('channel_chat_created',
124+
False))
119125

120126
@property
121127
def chat_id(self):
@@ -126,7 +132,7 @@ def chat_id(self):
126132
def de_json(data):
127133
"""
128134
Args:
129-
data (str):
135+
data (dict):
130136
131137
Returns:
132138
telegram.Message:
@@ -136,10 +142,7 @@ def de_json(data):
136142

137143
data['from_user'] = User.de_json(data.get('from'))
138144
data['date'] = datetime.fromtimestamp(data['date'])
139-
if 'first_name' in data.get('chat', ''):
140-
data['chat'] = User.de_json(data.get('chat'))
141-
elif 'title' in data.get('chat', ''):
142-
data['chat'] = GroupChat.de_json(data.get('chat'))
145+
data['chat'] = Chat.de_json(data.get('chat'))
143146
data['forward_from'] = \
144147
User.de_json(data.get('forward_from'))
145148
data['forward_date'] = \
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# You should have received a copy of the GNU General Public License
1717
# along with this program. If not, see [http://www.gnu.org/licenses/].
1818

19-
"""This module contains a object that represents Tests for Telegram GroupChat"""
19+
"""This module contains a object that represents Tests for Telegram Chat"""
2020

2121
import os
2222
import unittest
@@ -27,8 +27,8 @@
2727
from tests.base import BaseTest
2828

2929

30-
class GroupChatTest(BaseTest, unittest.TestCase):
31-
"""This object represents Tests for Telegram GroupChat."""
30+
class ChatTest(BaseTest, unittest.TestCase):
31+
"""This object represents Tests for Telegram Chat."""
3232

3333
def setUp(self):
3434
self.id = -28767330
@@ -42,36 +42,36 @@ def setUp(self):
4242
}
4343

4444
def test_group_chat_de_json_empty_json(self):
45-
"""Test GroupChat.de_json() method"""
46-
print('Testing GroupChat.de_json() - Empty JSON')
45+
"""Test Chat.de_json() method"""
46+
print('Testing Chat.de_json() - Empty JSON')
4747

48-
group_chat = telegram.GroupChat.de_json({})
48+
group_chat = telegram.Chat.de_json({})
4949

5050
self.assertEqual(group_chat, None)
5151

5252
def test_group_chat_de_json(self):
53-
"""Test GroupChat.de_json() method"""
54-
print('Testing GroupChat.de_json()')
53+
"""Test Chat.de_json() method"""
54+
print('Testing Chat.de_json()')
5555

56-
group_chat = telegram.GroupChat.de_json(self.json_dict)
56+
group_chat = telegram.Chat.de_json(self.json_dict)
5757

5858
self.assertEqual(group_chat.id, self.id)
5959
self.assertEqual(group_chat.title, self.title)
6060
self.assertEqual(group_chat.type, self.type)
6161

6262
def test_group_chat_to_json(self):
63-
"""Test GroupChat.to_json() method"""
64-
print('Testing GroupChat.to_json()')
63+
"""Test Chat.to_json() method"""
64+
print('Testing Chat.to_json()')
6565

66-
group_chat = telegram.GroupChat.de_json(self.json_dict)
66+
group_chat = telegram.Chat.de_json(self.json_dict)
6767

6868
self.assertTrue(self.is_json(group_chat.to_json()))
6969

7070
def test_group_chat_to_dict(self):
71-
"""Test GroupChat.to_dict() method"""
72-
print('Testing GroupChat.to_dict()')
71+
"""Test Chat.to_dict() method"""
72+
print('Testing Chat.to_dict()')
7373

74-
group_chat = telegram.GroupChat.de_json(self.json_dict)
74+
group_chat = telegram.Chat.de_json(self.json_dict)
7575

7676
self.assertTrue(self.is_dict(group_chat.to_dict()))
7777
self.assertEqual(group_chat['id'], self.id)

tests/test_update.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def setUp(self):
3838
'last_name': "S.",
3939
'username': "leandrotoledo"},
4040
'chat': {'id': 12173560,
41+
'type': 'private',
4142
'first_name': "Leandro",
4243
'last_name': "S.",
4344
'username': "leandrotoledo"},

tests/test_updater.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
sys.path.append('.')
4040

41-
from telegram import Update, Message, TelegramError, User, GroupChat, Updater
41+
from telegram import Update, Message, TelegramError, User, Chat, Updater
4242
from telegram.dispatcher import run_async
4343
from tests.base import BaseTest
4444
from threading import Lock, Thread
@@ -359,7 +359,7 @@ def test_webhook(self):
359359

360360
# Now, we send an update to the server via urlopen
361361
message = Message(1, User(1, "Tester"), datetime.now(),
362-
GroupChat(1, "Test Group"))
362+
Chat(1, "group", title="Test Group"))
363363

364364
message.text = "Webhook Test"
365365
update = Update(1)
@@ -416,7 +416,7 @@ def test_webhook_no_ssl(self):
416416

417417
# Now, we send an update to the server via urlopen
418418
message = Message(1, User(1, "Tester 2"), datetime.now(),
419-
GroupChat(1, "Test Group 2"))
419+
Chat(1, 'group', title="Test Group 2"))
420420

421421
message.text = "Webhook Test 2"
422422
update = Update(1)

0 commit comments

Comments
 (0)