Skip to content

Commit 738e321

Browse files
committed
Merge branch 'master' into jobqueue-rework
2 parents b08d41d + 4f101a7 commit 738e321

File tree

11 files changed

+39
-233
lines changed

11 files changed

+39
-233
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
- id: yapf
55
files: ^(telegram|tests)/.*\.py$
66
- repo: git://github.com/pre-commit/pre-commit-hooks
7-
sha: adbb569fe9a64ad9bce3b53a77f1bc39ef31f682
7+
sha: 6dfcb89af3c9b4d172cc2e5a8a2fa0f54615a338
88
hooks:
99
- id: flake8
1010
files: ^telegram/.*\.py$

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy