Search code examples
pythonpython-3.xtelegram-bottelepot

style inline keyboard in telepot


can I put the inline keyboard buttons on multiple lines with telepot?
if I can do it, how can I do it?


I tried this example to learn how to use the InlineKeyboard,
but i didn't find other documentation about inlline keyboard in telepot (except for the official docs)

import sys
import time
import telepot
from telepot.namedtuple import ReplyKeyboardMarkup, KeyboardButton


def on_chat_message(msg):
    content_type, chat_type, chat_id = telepot.glance(msg)
    print('Chat Message:', content_type, chat_type, chat_id)

    if content_type == 'text':
        if msg['text'] == '/key':
            bot.sendMessage(chat_id, 'testing custom keyboard',
                            reply_markup=ReplyKeyboardMarkup(
                                keyboard=[
                                    [KeyboardButton(text="btn1"), KeyboardButton(text="btn2"),KeyboardButton(text="btn3"), KeyboardButton(text="btn4")]
                                ]
                            ))


TOKEN = sys.argv[1]  # get token from command-line

bot = telepot.Bot(TOKEN)
print('Listening ...')
bot.message_loop({'chat': on_chat_message}, run_forever=True)

please i need a help

Thanks


Solution

  • solved!
    example code:

    bot.sendMessage(chat_id, 'testing custom keyboard',reply_markup = InlineKeyboardMarkup(inline_keyboard=[
                                        [InlineKeyboardButton(text="btn1",callback_data='I have Nothing To do'), InlineKeyboardButton(text="btn2",callback_data='0'),InlineKeyboardButton(text="btn3",callback_data='0'), InlineKeyboardButton(text="btn4",callback_data='0')],
                                        [InlineKeyboardButton(text="btn1",callback_data='yep')]
                                    ]
                                ))
    

    result:
    keyboard result