Telegram bot api keyboard

孤人 提交于 2019-12-07 02:50:40

问题


I have problem with Telegram Bot Api and with "ReplyKeyboard". I'm using Python 2.7 and I send post request:

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

keyboard in this format:

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

But in Telegram I don't see keyboard. What problem can be?


回答1:


According to the Bot API documentations, a custom keyboard requires a reply_markup parameter, whose value is a JSON-serialized specification of the keyboard. Assuming your TelegramAPI.post() function does not JSON-serialize for you, I would try the following:

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))

Note that text has to be non-empty.



来源:https://stackoverflow.com/questions/34315778/telegram-bot-api-keyboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!