Skip to content

Commit 47ce846

Browse files
committed
Added TeleBot#reply_to(message, text)
Added examples dir and an EchoBot sample.
1 parent e3025f4 commit 47ce846

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

‎examples/echo_bot.py‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# This is a simple echo bot using the decorator mechanism.
2+
# It echoes any incoming text messages.
3+
4+
import telebot
5+
6+
API_TOKEN = '<api_token>'
7+
8+
bot = telebot.TeleBot(API_TOKEN)
9+
10+
# Handle '/start' and '/help'
11+
@bot.message_handler(commands=['help, start'])
12+
def send_welcome(message):
13+
bot.reply_to(message, """\
14+
Hi there, I am EchoBot.
15+
I am here to echo your kind words back to you. Just say anything nice and I'll say the exact same thing to you!\
16+
""")
17+
18+
# Handle all other messages with content_type 'text' (content_types defaults to ['text'])
19+
@bot.message_handler(func=lambda message: True)
20+
def echo_message(message):
21+
bot.reply_to(message, message.text)
22+
23+
bot.polling()
24+
25+
while True:
26+
pass

‎telebot/__init__.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ def send_chat_action(self, chat_id, action):
220220
"""
221221
return apihelper.send_chat_action(self.token, chat_id, action)
222222

223+
def reply_to(self, message, text, **kwargs):
224+
return self.send_message(message.chat.id, text, reply_to_message_id=message.message_id, **kwargs)
225+
223226
def message_handler(self, commands=None, regexp=None, func=None, content_types=['text']):
224227
"""
225228
Message handler decorator.

0 commit comments

Comments
 (0)