1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00
This commit is contained in:
pieter 2015-07-03 01:54:53 +02:00
parent 523c7d433a
commit 886899a3e3

View File

@ -50,7 +50,7 @@ def listener(*messages):
"""
for m in messages:
chatid = m.chat.id
if m.content_type == 'text'
if m.content_type == 'text':
text = m.text
tb.send_message(chatid, text)
@ -146,7 +146,7 @@ def echo_messages(*messages):
"""
for m in messages:
chatid = m.chat.id
if m.content_type == 'text'
if m.content_type == 'text':
text = m.text
bot.send_message(chatid, text)
```
@ -182,24 +182,24 @@ bot = telebot.TeleBot(TOKEN)
# Handle /start and /help
@bot.message_handler(commands=['start', 'help'])
def command_help(message):
bot.send_message(message.chat.id, "Hello, did someone call for help?")
bot.reply_to(message, "Hello, did someone call for help?")
# Handles all messages which text matches the regex regexp.
# See https://en.wikipedia.org/wiki/Regular_expression
# This regex matches all sent url's.
@bot.message_handler(regexp='((https?):((//)|(\\\\))+([\w\d:#@%/;$()~_?\+-=\\\.&](#!)?)*)')
def command_url(message):
bot.send_message(message.chat.id, "I shouldn't open that url, should I?")
bot.reply_to(message, "I shouldn't open that url, should I?")
# Handle all sent documents of type 'text/plain'.
@bot.message_handler(func=lambda message: message.document.mime_type == 'text/plain', content_types=['document'])
def command_handle_document(message):
bot.send_message(message.chat.id, "Document received, sir!")
bot.reply_to(message, "Document received, sir!")
# Default command handler. A lambda expression which always returns True is used for this purpose.
@bot.message_handler(func=lambda message: True, content_types=['audio', 'video', 'document', 'text', 'location', 'contact', 'sticker'])
def default_command(message):
bot.send_message(message.chat.id, "This is the default command handler.")
bot.reply_to(message, "This is the default command handler.")
```
* And finally, call bot.polling()
```python