Send slots values in JSON in active state

Hi,

I have to send the value of the slots to another person in JSON format. How can I do that, can anyone help me with this?

I have to send text/reply from bot in particular key. Is that possible?

@Juste @juste_petr @akelad @Ghostvv

You can use tracker data for getting active slot information. For testing , just make a function which returns

tracker.slots

and how to send those slot values to some other person through API in JSON format?

Sorry I don’t understand by other person. You want to send just the slot values. You can create an action for it! I think you can create an API for it using flask but i’m not sure how to do it!

Hi @abhishakskilrock,

I do something similar… having slots means that you are working with a FormAction. In a custom FormAction you can define:

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

This method is executed after all slots a properly filled which actually allows you to do something like:

    headers = {
        'Content-Type': "application/json",
        'Accept': "application/json",
        'Authorization': "Bearer ....",
    }
    payload = json.dumps(tracker.slots)
    response = requests.request("POST", url, data=payload, headers=headers)
    response_as_json = json.loads(response.text)
    return response_as_json

Keep in mind that you have to check if tracker.slots can be serialized in this way and catch it properly if not.

Does that help you?

Regards

Yeah, Problem have been resolved earlier. BTW Thanks for post. It will help others.

1 Like