Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Telegram bot api keyboard

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?

like image 768
cmashinho Avatar asked Dec 16 '15 15:12

cmashinho


1 Answers

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.

like image 148
Nick Lee Avatar answered Nov 11 '22 00:11

Nick Lee