how to set a slot in a custom action in rasa
Asked Answered
M

1

5

I'm new to rasa framework. I started developing a simple chatbot and i have created three slots for my chatbot. So my bot need to identify the current location and save it in the slots. My current location is taking from the conversation and i can save it in to the slots in the story.

But then i have a custom action that find the weather weather from an API call and i need to save the weather status and humidity in the relevant slots.

class ActionSomeRespThree(Action):

    def name(self) -> Text:
        return "action_some_resp_three"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:

        cityName = tracker.get_slot('city')
Murther answered 13/8, 2019 at 4:33 Comment(0)
P
14

You can simply use setSlot method in events.

from rasa_sdk.events import SlotSet

Then in you run method, you can set your value in relevant slot.

Imagine you slot name for humidity is weather_humidity. Then imagine your humidity value from the API is extracted for a variable called humidity. Then in your custom action run method, simply set the slot value with below line.

SlotSet("weather_humidity", humidity)

Make sure that you have defined the slot values in your domain.yml file.

Pre answered 13/8, 2019 at 4:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.