1

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!

1 Answer 1

2

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()
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, but unfortunately it's not working - the bot just stop responding, I've tried this. Stil couldn't find out what is the problem.
json_keyboard = json.dumps({keym: [[{'text': 'b2', 'callback_data': '6'}]]}) - this approach worked, thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.