【发布时间】:2017-09-12 22:51:50
【问题描述】:
Telegram 机器人使用频道中的消息执行一些任务。它应该跳过带有内嵌按钮的消息(例如,带有投票按钮)。
有没有办法确定发布的消息是否包含内联键盘?
Message 对象似乎不包含类似的东西。 editReplyMarkup 只能换键盘了……
为了更清楚。
【问题讨论】:
标签: telegram-bot
Telegram 机器人使用频道中的消息执行一些任务。它应该跳过带有内嵌按钮的消息(例如,带有投票按钮)。
有没有办法确定发布的消息是否包含内联键盘?
Message 对象似乎不包含类似的东西。 editReplyMarkup 只能换键盘了……
为了更清楚。
【问题讨论】:
标签: telegram-bot
机器人如何处理消息?
您必须检查输入 Update 对象。
更新:
from telegram import InlineKeyboardButton, InlineKeyboardMarkup
from telegram.ext import Updater, CommandHandler, CallbackQueryHandler
def start(bot, update):
print(update)
keyboard = [[InlineKeyboardButton("one", callback_data='1'),
InlineKeyboardButton("two", callback_data='2')],
[InlineKeyboardButton("tree", callback_data='3')]]
reply_markup = InlineKeyboardMarkup(keyboard)
update.message.reply_text('Please choose:', reply_markup=reply_markup)
def button(bot, update):
print(update)
query = update.callback_query
bot.edit_message_text(text="Your choose: %s" % query.data,
chat_id=query.message.chat_id,
message_id=query.message.message_id)
up = Updater('***TOKEN***')
up.dispatcher.add_handler(CommandHandler('start', start))
up.dispatcher.add_handler(CallbackQueryHandler(button))
up.start_polling()
返回不同的
消息:
{消息:{message_id:20,new_chat_members:[],new_chat_member:无,日期:0000000001,delete_chat_photo:假, 来自:{id:000000005,用户名:用户名,名字:姓名,语言代码:en-US},实体:[{偏移量:0,长度:6, type: bot_command}], chat: {id: 000000005, username: username, first_name: name, type: private}, new_chat_photo: [], group_chat_created: False, photo: [], supergroup_chat_created: False, text: /start, channel_chat_created: False}, update_id: 000000051}
内联:
{callback_query:{chat_instance:-0000000000000000060,消息:{message_id:21,new_chat_members:[], new_chat_member:无,日期:1505211901,delete_chat_photo:False,来自:{id:000000005,用户名:botname, 名字:测试},实体:[],聊天:{id:000000005,用户名:用户名,名字:名字,类型:私人}, new_chat_photo: [], group_chat_created: False, photo: [], supergroup_chat_created: False, text: 请选择:, channel_chat_created:False},数据:2,id:0000000000000000094,来自:{id:000000005,用户名:用户名, first_name: 姓名, language_code: en-US}}, update_id: 000000005}
【讨论】:
inline 和not inline 对象之间的区别吗?我为小例子编辑了帖子