mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
Added TeleBot#reply_to(message, text)
Added examples dir and an EchoBot sample.
This commit is contained in:
parent
e3025f4154
commit
47ce846ce1
26
examples/echo_bot.py
Normal file
26
examples/echo_bot.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
# This is a simple echo bot using the decorator mechanism.
|
||||||
|
# It echoes any incoming text messages.
|
||||||
|
|
||||||
|
import telebot
|
||||||
|
|
||||||
|
API_TOKEN = '<api_token>'
|
||||||
|
|
||||||
|
bot = telebot.TeleBot(API_TOKEN)
|
||||||
|
|
||||||
|
# Handle '/start' and '/help'
|
||||||
|
@bot.message_handler(commands=['help, start'])
|
||||||
|
def send_welcome(message):
|
||||||
|
bot.reply_to(message, """\
|
||||||
|
Hi there, I am EchoBot.
|
||||||
|
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!\
|
||||||
|
""")
|
||||||
|
|
||||||
|
# Handle all other messages with content_type 'text' (content_types defaults to ['text'])
|
||||||
|
@bot.message_handler(func=lambda message: True)
|
||||||
|
def echo_message(message):
|
||||||
|
bot.reply_to(message, message.text)
|
||||||
|
|
||||||
|
bot.polling()
|
||||||
|
|
||||||
|
while True:
|
||||||
|
pass
|
@ -220,6 +220,9 @@ class TeleBot:
|
|||||||
"""
|
"""
|
||||||
return apihelper.send_chat_action(self.token, chat_id, action)
|
return apihelper.send_chat_action(self.token, chat_id, action)
|
||||||
|
|
||||||
|
def reply_to(self, message, text, **kwargs):
|
||||||
|
return self.send_message(message.chat.id, text, reply_to_message_id=message.message_id, **kwargs)
|
||||||
|
|
||||||
def message_handler(self, commands=None, regexp=None, func=None, content_types=['text']):
|
def message_handler(self, commands=None, regexp=None, func=None, content_types=['text']):
|
||||||
"""
|
"""
|
||||||
Message handler decorator.
|
Message handler decorator.
|
||||||
|
Loading…
Reference in New Issue
Block a user