Skip to content

Commit cb6ddfd

Browse files
committed
Merge remote-tracking branch 'origin/master' into urllib3
2 parents bda0244 + 9338f93 commit cb6ddfd

File tree

10 files changed

+38
-232
lines changed

10 files changed

+38
-232
lines changed

CHANGES.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
**2016-06-10**
2+
3+
*Released 4.2.1*
4+
5+
- Fix ``CallbackQuery.to_dict()`` bug (thanks to @jlmadurga)
6+
- Fix ``editMessageText`` exception when receiving a ``CallbackQuery``
7+
18
**2016-05-28**
29

310
*Released 4.2*

README.rst

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,7 @@ code and building on top of it.
129129

130130
- `timerbot <https://github.com/python-telegram-bot/python-telegram-bot/blob/master/examples/timerbot.py>`_ uses the ``JobQueue`` to send timed messages.
131131

132-
- `clibot <https://github.com/python-telegram-bot/python-telegram-bot/blob/master/examples/clibot.py>`_ has a command line interface.
133-
134-
Examples using only the pure API:
135-
136-
- `echobot <https://github.com/python-telegram-bot/python-telegram-bot/blob/master/examples/legacy/echobot.py>`_ replies back messages.
137-
138-
- `roboed <https://github.com/python-telegram-bot/python-telegram-bot/blob/master/examples/legacy/roboed.py>`_ talks to `Robô Ed <http://www.ed.conpet.gov.br/br/converse.php>`_.
132+
- `echobot <https://github.com/python-telegram-bot/python-telegram-bot/blob/master/examples/legacy/echobot.py>`_ uses only the pure API to echo messages.
139133

140134
Look at the examples on the `wiki <https://github.com/python-telegram-bot/python-telegram-bot/wiki/Examples>`_ to see other bots the community has built.
141135

examples/clibot.py

Lines changed: 0 additions & 164 deletions
This file was deleted.

examples/legacy/echobot.py renamed to examples/echobot.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33
#
4-
# Simple Bot to reply to Telegram messages
4+
# Simple Bot to reply to Telegram messages. This is built on the API wrapper, see
5+
# echobot2.py to see the same example built on the telegram.ext bot framework.
56
# This program is dedicated to the public domain under the CC0 license.
6-
77
import logging
88
import telegram
99
from telegram.error import NetworkError, Unauthorized
1010
from time import sleep
1111

1212

13+
update_id = None
14+
1315
def main():
16+
global update_id
1417
# Telegram Bot Authorization Token
1518
bot = telegram.Bot('TOKEN')
1619

@@ -25,28 +28,25 @@ def main():
2528

2629
while True:
2730
try:
28-
update_id = echo(bot, update_id)
31+
echo(bot)
2932
except NetworkError:
3033
sleep(1)
3134
except Unauthorized:
3235
# The user has removed or blocked the bot.
3336
update_id += 1
3437

3538

36-
def echo(bot, update_id):
37-
39+
def echo(bot):
40+
global update_id
3841
# Request updates after the last update_id
3942
for update in bot.getUpdates(offset=update_id, timeout=10):
4043
# chat_id is required to reply to any message
4144
chat_id = update.message.chat_id
4245
update_id = update.update_id + 1
43-
message = update.message.text
4446

45-
if message:
47+
if update.message: # your bot can receive updates without messages
4648
# Reply to the message
47-
bot.sendMessage(chat_id=chat_id, text=message)
48-
49-
return update_id
49+
bot.sendMessage(chat_id=chat_id, text=update.message.text)
5050

5151

5252
if __name__ == '__main__':
File renamed without changes.

examples/legacy/roboed.py

Lines changed: 0 additions & 38 deletions
This file was deleted.

telegram/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
from .bot import Bot
8383

8484
__author__ = 'devs@python-telegram-bot.org'
85-
__version__ = '4.2.0'
85+
__version__ = '4.2.1'
8686
__all__ = ['Audio', 'Bot', 'Chat', 'ChatMember', 'ChatAction', 'ChosenInlineResult',
8787
'CallbackQuery', 'Contact', 'Document', 'Emoji', 'File', 'ForceReply',
8888
'InlineKeyboardButton', 'InlineKeyboardMarkup', 'InlineQuery', 'InlineQueryResult',

telegram/bot.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,14 +1009,14 @@ def answerCallbackQuery(self, callback_query_id, text=None, show_alert=False, **
10091009
return result
10101010

10111011
@log
1012+
@message
10121013
def editMessageText(self,
10131014
text,
10141015
chat_id=None,
10151016
message_id=None,
10161017
inline_message_id=None,
10171018
parse_mode=None,
10181019
disable_web_page_preview=None,
1019-
reply_markup=None,
10201020
**kwargs):
10211021
"""Use this method to edit text messages sent by the bot or via the bot
10221022
(for inline bots).
@@ -1043,6 +1043,10 @@ def editMessageText(self,
10431043
A JSON-serialized object for an inline keyboard.
10441044
10451045
Keyword Args:
1046+
reply_markup (Optional[:class:`telegram.ReplyMarkup`]): Additional
1047+
interface options. A JSON-serialized object for an inline
1048+
keyboard, custom reply keyboard, instructions to hide reply
1049+
keyboard or to force a reply from the user.
10461050
timeout (Optional[float]): If this value is specified, use it as
10471051
the definitive timeout (in seconds) for urlopen() operations.
10481052
@@ -1070,15 +1074,8 @@ def editMessageText(self,
10701074
data['parse_mode'] = parse_mode
10711075
if disable_web_page_preview:
10721076
data['disable_web_page_preview'] = disable_web_page_preview
1073-
if reply_markup:
1074-
if isinstance(reply_markup, ReplyMarkup):
1075-
data['reply_markup'] = reply_markup.to_json()
1076-
else:
1077-
data['reply_markup'] = reply_markup
1078-
1079-
result = request.post(url, data, timeout=kwargs.get('timeout'))
10801077

1081-
return Message.de_json(result)
1078+
return url, data
10821079

10831080
@log
10841081
@message

telegram/callbackquery.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,14 @@ def de_json(data):
4343
data['message'] = Message.de_json(data.get('message'))
4444

4545
return CallbackQuery(**data)
46+
47+
def to_dict(self):
48+
"""
49+
Returns:
50+
dict:
51+
"""
52+
data = super(CallbackQuery, self).to_dict()
53+
54+
# Required
55+
data['from'] = data.pop('from_user', None)
56+
return data

tests/test_photo.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,14 @@ class PhotoTest(BaseTest, unittest.TestCase):
3535

3636
def setUp(self):
3737
self.photo_file = open('tests/data/telegram.jpg', 'rb')
38-
self.photo_file_id = 'AgADAQADvb8xGx8j9QcpZDKxYoFK3bfX1i8ABFX_dgMWoKDuQugAAgI'
38+
self.photo_file_id = 'AgADAQADgEsyGx8j9QfmDMmwkPBrFcKRzy8ABHW8ul9nW7FoNHYBAAEC'
3939
self.photo_file_url = 'https://raw.githubusercontent.com/python-telegram-bot/python-telegram-bot/master/tests/data/telegram.jpg'
4040
self.width = 300
4141
self.height = 300
4242
self.thumb = {
4343
'width': 90,
4444
'height': 90,
45-
'file_id':
46-
'AgADAQADvb8xGx8j9QcpZDKxYoFK3bfX1i8ABBxRLXFhLnhIQ-gAAgI',
45+
'file_id': 'AgADAQADgEsyGx8j9QfmDMmwkPBrFcKRzy8ABD64nkFkjujeNXYBAAEC',
4746
'file_size': 1478
4847
}
4948
self.file_size = 10209

0 commit comments

Comments
 (0)