How to use inline_keyboard instead of keyboard in Telegram bot (Python)?
<p>I have this part of code (Python) that I'm using in my Telegram bot:</p>

<pre><code>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()
</code></pre>

<p>For this part everything works fine. The question is: how to use inline_keyboard intead of regular keyboard?</p>

<p>I understand that it is a noob question, but it would be great if someone could help me.</p>

<p>Thanks!</p>

<p>since the <a href="https://core.telegram.org/bots/api#inlinekeyboardmarkup" rel="nofollow">Inline Keyboard</a> is just a different json object, I'd say you only have to build it with <code>json.dumps</code> instead of your current build. Following your example, something like this should make the trick:</p>

<pre><code>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()
</code></pre>

python keyboard telegram telegram-bot