mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-03-25 00:07:41 +01:00
use run_async decorator in example
This commit is contained in:
parent
63a8700258
commit
2ec56abe7e
1 changed files with 12 additions and 1 deletions
|
@ -11,7 +11,9 @@ inserted into the update queue for the bot to handle.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from telegram.boteventhandler import BotEventHandler
|
from telegram import BotEventHandler
|
||||||
|
from telegram.boteventhandler import run_async
|
||||||
|
from time import sleep
|
||||||
import re
|
import re
|
||||||
|
|
||||||
global last_chat_id
|
global last_chat_id
|
||||||
|
@ -35,9 +37,18 @@ def anyMessageHandler(bot, update):
|
||||||
def unknownCommandHandler(bot, update):
|
def unknownCommandHandler(bot, update):
|
||||||
bot.sendMessage(update.message.chat_id, text='Command not recognized!')
|
bot.sendMessage(update.message.chat_id, text='Command not recognized!')
|
||||||
|
|
||||||
|
@run_async
|
||||||
def messageHandler(bot, update):
|
def messageHandler(bot, update):
|
||||||
|
"""
|
||||||
|
Example for an asynchronous handler. It's not guaranteed that replies will
|
||||||
|
be in order when using @run_async
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Save last chat_id to use in reply handler
|
||||||
global last_chat_id
|
global last_chat_id
|
||||||
last_chat_id = update.message.chat_id
|
last_chat_id = update.message.chat_id
|
||||||
|
|
||||||
|
sleep(2) # IO-heavy operation here
|
||||||
bot.sendMessage(update.message.chat_id, text=update.message.text)
|
bot.sendMessage(update.message.chat_id, text=update.message.text)
|
||||||
|
|
||||||
def errorHandler(bot, error):
|
def errorHandler(bot, error):
|
||||||
|
|
Loading…
Add table
Reference in a new issue