我正在从电报中试用bot API,并且正在使用包装器python-telegram-bot
。目前,我的机器人在直接发起与机器人的对话时能够按照预期的方式运行。但是,当在小组中使用该机器人或仅在与其他人的普通聊天中提及该机器人时,该机器人似乎根本看不到该消息。
使用电报bot父亲,我已启用join to groups
,我尝试启用和禁用inline mode
(对此问题没有影响。)>
我拥有的代码是这样的:(代码是从基本的wiki示例改编而成的]
# Imports from telegram import InlineQueryResultArticle, ParseMode, \ InputTextMessageContent from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, InlineQueryHandler, Handler, ConversationHandler, CallbackQueryHandler from telegram.utils.helpers import escape_markdown from telegram import MessageEntity, ChatAction # functions def start(update, context): """Send a message when the command /start is issued.""" update.message.reply_text('Let\'s start') def help(update, context): """Send a message when the command /help is issued.""" update.message.reply_text('Help!') def error(update, context): """Log Errors caused by Updates.""" logger.warning('Update "%s" caused error "%s"', update, context.error) def process(update, context): print(f'got this ==> {update.message.text}') query = update.message.text output = "Some output here" update.message.reply_text(output) def run_bot(): # Create the Updater and pass it your bot's token. # Make sure to set use_context=True to use the new context based callbacks # Post version 12 this will no longer be necessary updater = Updater("TOKEN_HERE", use_context=True) # Get the dispatcher to register handlers dp = updater.dispatcher # on different commands - answer in Telegram dp.add_handler(CommandHandler("start", start)) dp.add_handler(CommandHandler("help", help)) # on noncommand i.e message dp.add_handler(MessageHandler(Filters.text & (~Filters.command), process)) # log all errors dp.add_error_handler(error) # Start the Bot updater.start_polling() # Block until the user presses Ctrl-C or the process receives SIGINT, # SIGTERM or SIGABRT. This should be used most of the time, since # start_polling() is non-blocking and will stop the bot gracefully. updater.idle()
然后我只运行
run_bot()
。
我正在从电报中试用bot API,并且正在使用包装器python-telegram-bot。目前,我的机器人在直接发起与机器人的对话时能够按照预期的方式运行。 ...
与BotFather对话,并<。为什么?好吧,official page可以回答:
以隐私模式运行的漫游器不会接收人们发送给该论坛的所有消息。相反,它将仅接收:以斜杠“ /”开头的消息(请参见上面的命令)
- 回复机器人自己的消息
- 服务消息(添加或删除组中的人员,等等)
- 来自其成员所在频道的消息
也建议您检查FAQ of this topic。
记住要过滤要答复的邮件,否则您可能最终向该组发送垃圾邮件。