如何检测邮件是否包含内联键盘

时间:2017-09-11 11:32:55

标签: telegram-bot

Telegram bot使用频道中的消息执行某些任务。它应该跳过带有内联按钮的消息(例如,使用投票按钮)。

有没有办法确定发布的消息是否包含内联键盘?

Message对象似乎不包含任何类似内容。 editReplyMarkup 只能更换键盘...

更清楚。

这是序数信息:

这是带按钮的消息: enter image description here

1 个答案:

答案 0 :(得分:0)

僵尸程序如何处理邮件? 您必须检查Update对象中的类型。

UPD:

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:{message_id:20,new_chat_members:[],new_chat_member:无,日期:0000000001,delete_chat_photo:False, from:{id:000000005,username:username,first_name:name,language_code:en-US},entities:[{offset:0,length: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:{message_id:21,new_chat_members:[], new_chat_member:无,日期:1505211901,delete_chat_photo:错误,来自:{id:000000005,用户名:botname, first_name:test},entities:[],chat:{id:000000005,username:username,first_name:name,type:private}, new_chat_photo:[],group_chat_created:False,照片:[],supergroup_chat_created:False,text:请选择:, channel_chat_created:False},data:2,id:0000000000000000094,from:{id:000000005,username:username, first_name:name,language_code:en-US}},update_id:000000005}

相关问题