gpt4 book ai didi

bots - 假装 Telegram Bot 正在打字?

转载 作者:行者123 更新时间:2023-12-05 08:50:34 29 4
gpt4 key购买 nike

如何让机器人假装它正在输入消息?

当机器人假装输入时,聊天中会出现以下文本:

enter image description here

我使用 python aiogram框架,但对 native Telegram API 的建议也会有所帮助。

最佳答案

我认真地建议使用具有广泛 Wiki 的 python-telegram-bot 库。 code snippets 中描述了您想要的解决方案。 .

您可以手动发送操作:

bot.send_chat_action(chat_id=chat_id, action=telegram.ChatAction.TYPING)

或者创建一个装饰器,然后可以将其用于您希望在处理时显示该操作的任何函数:

from functools import wraps
from telegram import (ChatAction)

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.

关于bots - 假装 Telegram Bot 正在打字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61520440/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com