我严重建议使用 python-telegram-bot
库,它有一个广泛的Wiki。 你想要的解决方案在 代码段.
你可以手动发送动作。
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.