Search code examples
pythonslack-apirasa-core

How to create the interactive button in slack


I am trying to build chatbot using Rasa-core integrating with slack, don't have any clear idea about creating a button in slack and user and bot conversation.

So if anyone could help me with this, it would be much appreciated.


Solution

  • You can define buttons in the template section of your domain file, e.g.:

    slots:
      game:
        type: text
    
    templates:
        utter_ask_for_game:
        - text: "Would you like to play a game?"
          buttons:
          - title: "Chess"
            payload: '/choose{"game": "Chess"}'
          - title: "Falken's Maze"
            payload: "/choose{"game": "Falken\'s Maze"}"
          - title: "Thermonuclear War"
            payload: '/choose{"game": "Thermonuclear War"}'
    

    This is the Slack example implemented as shown in the Rasa Core docs. It asks the user "Would you like to play a game?" and offers three buttons for three different games. Depending on which button the user selects, the intent choose is triggered with different slot values. Depending on whether the slot value is set you can then go down different story paths, or trigger custom actions. Note, that you might choose a different slot type, e.g. categorical. Using the categorical type, you can have different stories depending on the value of your slots.