telegram-bot - pyTelegramBotAPI - 如何创建使用按钮更新的消息?
问题描述
我最近尝试创建一条消息,当按下内联键盘中的按钮时更新,但没有成功。
我正在使用 pyTelegramBotAPI,我可以让机器人用键盘发送消息,但我无法让各种按钮工作。
你能帮助我吗?:<
解决方案
为了创建多选项选择(即按钮),您使用InlineKeyboardButton
对象
options = []
# buttons
options.append(InlineKeyboardButton('One', callback_data='1'))
options.append(InlineKeyboardButton('Two', callback_data='2'))
options.append(InlineKeyboardButton('Three', callback_data='3'))
reply_markup = InlineKeyboardMarkup([options])
update.message.reply_text(response.message, reply_markup=reply_markup)
确保设置对应CallbackQueryHandler
的处理用户选择
updater.dispatcher.add_handler(CallbackQueryHandler(main_handler, pass_chat_data=True, pass_user_data=True))
在上面的示例中,该方法main_handler(update, context)
将负责处理用户输入。
随意查看TelegramBotDemo GitHub 存储库以查看完整实现
推荐阅读
- c# - 转换(字典
>) value).Values),它是由 IValueConverter 显示在列表框中的数组的集合 - identityserver4 - 无法到达 ConsentController
- sharepoint - 用于自动填充用户数据的 InfoPath 表单
- php - 如何存储 csv 文件 laravel 5 php?
- asp.net-core - Razor Pages 锚标记生成不正确的 URL
- javascript - 使用nodejs的命令行工具取一个词作为参数,然后并行读取3个文件的内容
- javascript - PAC 文件是编译还是解释?
- python - Python - 将集合与集合列表相交的最快/替代方法
- ruby-on-rails - 在代码中使用模型和迁移
- ssl - 如何解决 *builder.code.codershub.org 使用不受支持的协议。ERR_SSL_VERSION_OR_CIPHER_MISMATCH*?