Pass variable to slot through buttons in custom action

Hi, I’m trying to pass variable to slot using buttons:

            sourcelang = "French"
            buttons = [
                {"payload": '/change_language{"lang": "sourcelang"}', "title": "Yes"},
                {"payload": '/deny{"lang":"self.bot_lang"}', "title": "No"}
            ]

But when i click button “Yes”, slot value is set to “sourcelang”, not to “French”. Rasa expects property name enclosed in double quotes. How can i pass variable sourcelang?

You can implement it the following way,

sourcelang = "French"
buttons = [
        {"payload": '/change_language{"lang": "'+sourcelang+'"}', "title": "Yes"},
        {"payload": '/deny{"lang":"'+self.bot_lang+'"}', "title": "No"}
          ]
1 Like

Yes! That’s exactly what I meant and it works perfectly. Thanks!

You can mark it as a solution so others with the same problem can find it useful as well

1 Like