【问题标题】:Telegram bot api keyboard电报机器人 api 键盘
【发布时间】:2016-03-22 19:27:56
【问题描述】:

我对 Telegram Bot Api 和“ReplyKeyboard”有疑问。我正在使用 Python 2.7 并发送发布请求:

TelegramAPI.post(TELEGRAM_URL + "sendMessage", data=dict(chat_id=CHAT_ID, text="", keyboard={'keyboard': keyboard, 'one_time_keyboard': False, 'resize_keyboard': True})

这种格式的键盘:

[["A button"], ["B button"]]

但在 Telegram 中我看不到键盘。可能是什么问题?

【问题讨论】:

  • 您使用的是什么包装器?你能分享TelegramAPI的文档吗?

标签: python tornado telegram telegram-bot python-telegram-bot


【解决方案1】:

根据Bot API documentations,自定义键盘需要reply_markup参数,其值是键盘的JSON序列化规范。假设您的 TelegramAPI.post() 函数没有为您进行 JSON 序列化,我会尝试以下操作:

import json

json_keyboard = json.dumps({'keyboard': [["A button"], ["B button"]], 
                            'one_time_keyboard': False, 
                            'resize_keyboard': True})

TelegramAPI.post(TELEGRAM_URL + "sendMessage", 
                 data=dict(chat_id=CHAT_ID, 
                           text="Has to be non-empty", 
                           reply_markup=json_keyboard))

注意text 不能为空。

【讨论】:

    猜你喜欢
    • 2018-03-23
    • 2020-10-08
    • 1970-01-01
    • 2018-09-25
    • 2017-08-01
    • 2022-10-05
    • 2016-10-22
    • 2017-12-10
    • 2017-02-14
    相关资源
    最近更新 更多