Reputation: 21
I have this part of code (Python) that I'm using in my Telegram bot:
def reply(msg=None, img=None):
if msg:
resp = urllib2.urlopen(BASE_URL + 'sendMessage', urllib.urlencode({
'chat_id': str(chat_id),
'text': msg.encode('utf-8'),
'disable_web_page_preview': 'true',
# 'reply_to_message_id': str(message_id),
'reply_markup': json.dumps({'keyboard': [bline1, bline2], 'resize_keyboard': True}),
})).read()
For this part everything works fine. The question is: how to use inline_keyboard intead of regular keyboard?
I understand that it is a noob question, but it would be great if someone could help me.
Thanks!
Upvotes: 1
Views: 2978
Reputation: 2323
since the Inline Keyboard is just a different json object, I'd say you only have to build it with json.dumps
instead of your current build. Following your example, something like this should make the trick:
def reply(msg=None, img=None):
if msg:
resp = urllib2.urlopen(BASE_URL + 'sendMessage', urllib.urlencode({
'chat_id': str(chat_id),
'text': msg.encode('utf-8'),
'disable_web_page_preview': 'true',
# 'reply_to_message_id': str(message_id),
'reply_markup': json.dumps({'inline_keyboard': [[{'text': bline1, 'callback_data': bline1}, {'text': bline2, 'callback_data': bline2}]]}),
})).read()
Upvotes: 2