X Tutup
Skip to content

replykeyboardmarkup doesn't work with string keyboard buttons #268

@rahiel

Description

@rahiel

According to the docs:

This object represents one button of the reply keyboard. For simple text buttons String can be used instead of this object to specify text of the button. Optional fields are mutually exclusive.

So the buttons can be types str or KeyboardButton.

But currently replykeyboardmarkup.py assumes they are of type KeyboardButton and fails with str buttons, see here . (AttributeError: 'str' object has no attribute 'to_dict')

Code to reproduce:

import telegram

def main():
    bot = telegram.Bot(token=TOKEN)
    update_id = None

    while True:
        update_id = serve(bot, update_id)

def serve(bot, update_id):
    reply_markup = telegram.ReplyKeyboardMarkup([["Yes", "No"]])
    for update in bot.get_updates(offset=update_id, timeout=3.):
        chat_id = update.message.chat_id
        update_id = update.update_id + 1
        message = update.message.text.encode('utf-8')

        if (message):
            bot.send_message(chat_id=chat_id, text="Want to crash?", reply_markup=reply_markup)

    return update_id

if __name__ == '__main__':
    main()

Metadata

Metadata

Assignees

Labels

⚙️ bot-apiaffected functionality: bot-api

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    X Tutup