【发布时间】:2020-04-30 09:42:26
【问题描述】:
【问题讨论】:
标签: bots telegram python-telegram-bot
【问题讨论】:
标签: bots telegram python-telegram-bot
我强烈建议使用具有广泛 Wiki 的 python-telegram-bot 库。 code snippets 中描述了您想要的解决方案。
您可以手动发送操作:
bot.send_chat_action(chat_id=chat_id, action=telegram.ChatAction.TYPING)
或者创建一个装饰器,然后可以将其用于您希望在处理时显示该操作的任何函数:
from functools import wraps
def send_typing_action(func):
"""Sends typing action while processing func command."""
@wraps(func)
def command_func(update, context, *args, **kwargs):
context.bot.send_chat_action(chat_id=update.effective_message.chat_id, action=ChatAction.TYPING)
return func(update, context, *args, **kwargs)
return command_func
@send_typing_action
def my_handler(update, context):
pass # Will send 'typing' action while processing the request.
【讨论】: