Skip to content

Commit be508f1

Browse files
committed
message.py: implement reply_text
1 parent d8211ec commit be508f1

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

telegram/message.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ def __init__(self, message_id, from_user, date, chat, **kwargs):
140140
self.channel_chat_created = bool(kwargs.get('channel_chat_created', False))
141141
self.pinned_message = kwargs.get('pinned_message')
142142

143+
self.bot = kwargs.get('bot')
144+
143145
@property
144146
def chat_id(self):
145147
"""int: Short for :attr:`Message.chat.id`"""
@@ -244,3 +246,12 @@ def _totimestamp(dt_obj):
244246
except AttributeError:
245247
# Python 3 (< 3.3) and Python 2
246248
return int(mktime(dt_obj.timetuple()))
249+
250+
def reply_text(self, *args, **kwargs):
251+
"""Shortcut for ``bot.sendMessage(update.message.chat_id, *args, **kwargs)``"""
252+
253+
if not self.bot:
254+
raise RuntimeError('Missing reference to telegram.Bot instance. '
255+
'Use telegram.Bot.create_references to create this reference.')
256+
257+
self.bot.sendMessage(self.chat_id, *args, **kwargs)

0 commit comments

Comments
 (0)