smartnode/telebot

How to use buttons?

Closed this issue · 4 comments

Can somebody show examples how to use keyboard buttons & inline buttons?

Reply markup

You just need to send json string as reply_markup

const char *reply_markup = "{\"keyboard\":[[\"Yes\",\"No\"],[\"Maybe\"],[\"0\",\"1\",\"3\"]],\"one_time_keyboard\":True}"
ret = telebot_send_message(handle, chat_id, "Does it work", "HTML", false, false, message_id, reply_markup);

Inline keyboard

Here is JSON example of keyboards
3-row example

[[{"text":"text 1","callback_data":"1"},{"text":"Some button text 2","url":"https://elmurod.net"},{"text":"Some button text 3","callback_data":"3"}]]

2-row, 2+1 columns

[[{"text":"Text 1","callback_data":"1"},{"text":"Link 1","url":"https://elmurod.net"}],[{"text":"Text2","callback_data":"2"}]] 

I have try to send by first method simple json and it's fail:
[DEBUG][telebot_core_curl_perform:142]Response: {"ok":true,"result":[{"update_id":760823970, "message":{"message_id":56,"from":{"id":115948583,"is_bot":false,"first_name":"\u0421\u0430\u043c\u0443\u0438\u043b \u0413\u0435\u0440\u043c\u0430\u043d\u043e\u0432\u0438\u0447","last_name":"\u0410\u0440\u043a\u0430\u043d\u0443\u043c","username":"Arcanum7","language_code":"ru"},"chat":{"id":115948583,"first_name":"\u0421\u0430\u043c\u0443\u0438\u043b \u0413\u0435\u0440\u043c\u0430\u043d\u043e\u0432\u0438\u0447","last_name":"\u0410\u0440\u043a\u0430\u043d\u0443\u043c","username":"Arcanum7","type":"private"},"date":1603264033,"text":"/start","entities":[{"offset":0,"length":6,"type":"bot_command"}]}}]} Number of updates: 1 Самуил Германович: /start [ERROR][telebot_core_curl_perform:137]Wrong HTTP response received, response: 400

i had use this code:

if (strstr(message.text, "/start"))
    {
        const char* reply_markup = "{\"keyboard\":[[\"Yes\",\"No\"],[\"Maybe\"],[\"0\",\"1\",\"3\"]],\"one_time_keyboard\":True}";
        ret_proc = telebot_send_message(handle, message.chat->id, "Does it work", "HTML", false, false, updates[index].message.message_id, reply_markup);
     }

upd: how to use telebot_reply_keyboard_markup stuct?

and it work:
const char* reply_markup = " { \"keyboard\": [[{\"text\": \"1\"}],[{ \"text\": \"2\"},{ \"text\": \"3\"}]] } ";

last Q? for this issue - how to use telebot_reply_keyboard_markup ?
write pure json in c - it is very interesting existential experience, yep...

I don't have time to work on this project. I believe it would be better keyboards as data structure...