How to set slots in the initial request

Hi, I am trying to create a simple bot. When the user launches the bot, I want to save some slot variables that are specific to the user like locale, device type, user type etc. These values will be used later in custom action webhook calls. I am using the endpoint: http://localhost:5005/webhooks/rest/webhook. I tried the initial request like this and tried to read the slot values in custom action. But the values are not present.

{ “sender”:“user1”, “message”:"/greet{‘name’:‘user1’, ‘language’:‘de_DE’}" }

Do I have to make changes in stories.yml and domain.yml? Is it possible to set these values without any entity extraction/custom actions? The “greet” intent does not have any entities defined.

Thank you.

class ActionSetData(Action):
    def name(self) -> Text:
        return "action_set_data"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
        name= next(tracker.get_latest_entity_values("name"), None)
        language= next(tracker.get_latest_entity_values("language"), None)
        return [SlotSet("name", name), SlotSet("language", language)]

You need a custom action.

1 Like

Thank you @ILG2021 for you reply. I tried the customer set data action but the values are coming as None. The values that I want to store in slots are not part of any entities in the greet message. These are the values specific to the user’s profile. Is there any way to save these values in slots during the first api call to rasa server.

ok. Do you send the message by /set_data{‘name’:‘user1’, ‘language’:‘de_DE’} and add the rule:

rule: set data
  - intent: set_data
  - action: action_set_data

when you send message by /set_data{‘name’:‘user1’, ‘language’:‘de_DE’}, set_data will be recogize as a intent, and the json after set_data will be extracted as entities. I have use these in my project and works ok. You should use /set_data before you use the slot.

1 Like