In Telegram bot to add buttons in Python?

How to add a button in the normal request via requests'"token"/sendMessage?chat_id="chatid"&keyboardbutton to&text=1111')
thus not working, just sends the text without creating buttons
April 7th 20 at 10:42
1 answer
April 7th 20 at 10:44
To send to the server only the keyboard(Inlinekeyboard, replykeyboard and it seems like there are more types), so the keyboard should be a list converted to json object and added to the field reply_markup
import requests
import json

token = <Your token>
URL = '' + token
r1 = requests.get(URL + '/getUpdates').json()
chat_id = r1['result'][-1]['message']['from']['id']
reply_markup = {
 'inline_keyboard': [[{'text': 'text1', 'callback_data': 'Return value 1'},
 {'text': 'text2', 'callback_data': 'Return value 1'}]]}

data = {'chat_id': chat_id, 'text': 'text', 'reply_markup': json.dumps(reply_markup)}
r2 = + '/sendMessage', data=data)

Also, you will have to receive and process the return value and pressing any of the buttons to know what the user pressed. It is denoted as callbackquery

Find more questions by tags PythonBotsTelegram