JustinaPetr / Weatherbot_Tutorial

276 stars 447 forks source link

rasa_slack_connector.py vs from rasa_core.channels.slack import SlackInput #2

Closed TomLaMantia closed 6 years ago

TomLaMantia commented 6 years ago

Is there a reason you wrote a slightly different version of the rasa slack connector?

I believe your SlackBot class needs to implement additional methods in order to handle button functionality, correct?

However, I cannot get the rasa_core.channels.slack SlackBot and SlackInput to work - your classes seem to require additional slack tokens that the former is missing.

Can you explain why you re-implemented your class and what methods must be implemented to add button functionality?

Thanks :)

JustinaPetr commented 6 years ago

Hey @TomLaMantia,

By the time I started recording the tutorial, rasa_core didn't include an in-built Slack connector, that's why I wrote my own. My SlackBot class is very simple and you are absolutely right that it needs additional methods to handle button functionality because now it can only send simple messages (I should definitely update that 😄 ).

A current Slack connector created by Rasa devs should definitely work. This is what I did to test it out: 1) I have created a custom action which sends a question 'Does it make you happy' and two - buttons 'Yes' and 'No':

class ActionMood(Action):
    def name(self):
        return 'action_mood'

    def run(self, dispatcher, tracker, domain):
        response = 'Does it make you happy?'
        buttons = [{"payload":"Yes","title":"Yes","type":"button"}, {"payload":"No","title":"No :(","type":"button"}]
        dispatcher.utter_button_message(response, buttons)

Here for each button 'title' is what will be written on a displayed button, while 'payload' is what response will be parsed and sent to rasa interpreter once a user clicks a button.

2) I have enabled interactive events on Slack App configuration page and provided a request URL, which was the same I used to enable event subscriptions, so that a response payload would be passed to rasa interpreter:

app_conf

This is necessary because your app needs to know where to send a POST request once a user clicks a button. And that's it - a bot was able to send messages with buttons and parse the reponse after a button was clicked.

Can you show me how you implement the buttons and do you provide a request URL in interactive events section on your slack app configuration page?

TomLaMantia commented 6 years ago

Hey @JustinaPetr

You are absolutely right - the built-in slack connector does work! My issue was that inside their SlackInput class, the method webhook() is given the route /webbook instead of /slack/events as in the weatherbot:

@slack_webhook.route("/webhook", methods=['GET', 'POST']) vs @slack_webhook.route('/slack/events', methods = ['POST']) on the weatherbot's event() method

I implemented the buttons in a similar way to what you showed. However, if you have a simple utterance action, you can define the buttons in your weather_domain.yml as follows:

utter_ask_mood:
  - text: "How are you today?"
    buttons:
    - title: "I'm great, thanks for asking!"
      payload: "I'm great, thanks for asking!"
    - title: "I'm having a bad day..."
      payload: "I'm having a bad day..."

where title is the text on the button and payload is what is sent to the bot for intent classification/entity recognition. Then, you can have an additional intent to recognize user utterances that inform the bot of the user's mood!

In the case of custom actions that extend the Action class, the dispatcher.utter_button_message(response, buttons) workflow will do the trick!

EDIT: Yes, I provide a request URL in the interactive events section of my slack configuration. You will need both the requests URL and Options load URL. In my case, foo.ngrok.io/webhook.

One more thing: The built in SlackInput class only requires the Bot User OAuth Access Token and name of the channel that the bot should post in (you can also direct message it). If you use the built-in connector, then bot token (xoxp-...-...) and Slack verification tokens are not required.

Great work on the weatherbot tutorial. I am enhancing/porting an existing bot from Google DialogueFlow to Rasa, and this gave me a great intro to rasa-core! Thanks a lot :)