How to change payload and title of button dynamically and how to add number of buttons dynamically

This is a question about Python rather then Rasa, but you can do this:

books = get_books_from_file() # dynamically get a list of all available books in your XLSX

for book in books:
    if book in product_group:
        languages = get_languages_from_file(book) #  dynamically get a list of all available languages for this book in your XLSX
        buttons = []

        for language in languages:
            button = {"payload": '/intent_language{"language":"' + language + '"}', "title": language.title()
            buttons.append(button)

Compact form:

for book in get_books_from_file():
    if book in product_group:
        buttons = []
        for language in get_languages_from_file(book):
           buttons.append({"payload": '/intent_language{"language":"' + language + '"}', "title": language.title())

You have to implement get_books_from_file() and get_languages_from_file() yourself since I don’t have access to your data schema and therefore cannot write them. If you need help for that, please post on StackOverflow since this is a general coding problem unrelated to Rasa.

Hope this helps :slight_smile:

2 Likes