Python Telegram Bot 发送带有操作的消息
Python Telegram Bot Send message with action
我在 python 3 中使用 python 电报机器人库,我写了这段代码:
from telegram import *
from telegram.ext import *
bot.send_chat_action(chat_id=update.message.chat_id ,
action = telegram.ChatAction.TYPING)
bot.sendMessage(chat_id=update.message.chat_id, text="Hi")
此代码将正确地向客户端发送消息,但我希望当机器人向客户端发送消息时,在客户端屏幕上方(在电报信使中)显示但是 Typing...
。
我在 sendMessage 方法中使用 action = telegram.ChatAction.TYPING
作为选项,
但它不起作用,我找不到我的问题。
有指南吗?
问题出在库上,写import telegram
而不是from telegram import *
。
为确保ChatAction
对用户可见,调用ChatAction
方法后需要延迟几秒:
from telegram import *
from telegram.ext import *
from time import sleep
from random import random
bot.sendChatAction(chat_id=update.message.chat_id ,
action = telegram.ChatAction.TYPING)
sleep(random() * 2 + 3.)
bot.sendMessage(chat_id=update.message.chat_id, text="Hi")
我在 python 3 中使用 python 电报机器人库,我写了这段代码:
from telegram import *
from telegram.ext import *
bot.send_chat_action(chat_id=update.message.chat_id ,
action = telegram.ChatAction.TYPING)
bot.sendMessage(chat_id=update.message.chat_id, text="Hi")
此代码将正确地向客户端发送消息,但我希望当机器人向客户端发送消息时,在客户端屏幕上方(在电报信使中)显示但是 Typing...
。
我在 sendMessage 方法中使用 action = telegram.ChatAction.TYPING
作为选项,
但它不起作用,我找不到我的问题。
有指南吗?
问题出在库上,写import telegram
而不是from telegram import *
。
为确保ChatAction
对用户可见,调用ChatAction
方法后需要延迟几秒:
from telegram import *
from telegram.ext import *
from time import sleep
from random import random
bot.sendChatAction(chat_id=update.message.chat_id ,
action = telegram.ChatAction.TYPING)
sleep(random() * 2 + 3.)
bot.sendMessage(chat_id=update.message.chat_id, text="Hi")