Suggest answer from stories

I would like to suggest to my chatbot users buttons that match the next step of my story. As an example, my chatbot begins with a simple question : How do you feel ? I created stories for 2 cases : I'm good / I'm sad.

However, I know these two answers will change in the future and handle a new path (let’s say : I feel extremelly well).

How can I create an answer suggestion that takes into account the next message in my stories ?

You do this in responses not stories. Here’s an example. When a possible response changes in the future, you update the response issues and re-train.

1 Like

Ok, thanks for your response ! But, responses somewhat follow stories. Is there any way to avoid duplicating code by generating automatically buttons with datas from stories ?

Hey @bourrel the only way to generate it dynamically is to use custom actions.

since there is no code where you write your stories, if you add a new story you have to manually put a button to initially that specific story.

Alternatively, could map all of you desired paths into a python dict, and programmatically (Through rasa actions) make your bot read the list before showing the buttons. You still would have to do some manual work which is to write down the story info into that python dict

You could right a class like this:

class Options:
    ''' All the other option the Bot might show '''

    def general_options(self, display_message, buttons)-> Dict:
        '''
        Return/display a dict with the options based on input
        display_message : utter to be displayed
        buttons: A dict with all the buttons of the utter
        '''
        result_list = []
        for elements in buttons:
            for title, payload in elements.items():
                result_list.append({title:payload}) # append titles and pyload as dict

        message = {
            "text": display_message,
            "quick_replies":

                buttons
        }

        return message

and then run your function like this:

    def run(self, dispatcher,tracker,domain):
        
        display_message = 'how do you feel today ?'
        buttons =[
            {
                "content_type": "text",
                "title": "good",
                "payload": "good" # go to bad story
            },
            {
                "content_type": "text",
                "title": "bad",
                "payload": "bad" # go to bad story
            }
            # Add more buttons here

        ]
        

        message = Options().general_options(display_message, buttons)

if you create another story, you would just have to add that to your buttons list, like so:

    def run(self, dispatcher,tracker,domain):
        
        display_message = 'how do you feel today ?'
        buttons =[
            {
                "content_type": "text",
                "title": "good",
                "payload": "good"
            },
            {
                "content_type": "text",
                "title": "bad",
                "payload": "bad"
            },

            # New story added

            {
                    "content_type": "text",
                    "title": "extremely well",
                    "payload": "I feel extremely well" # go to extremely well story
            },

        ]
        

        message = Options().general_options(display_message, buttons)

Hope that helps, Cheer

1 Like