Fetch custom payload in actions.py

Given below is my payload to rasa server:

{ “sender”: “shaurya”, “projectname”: “RASA”, “message”: “list users in Claim_Center” }

I am able to fetch sender and message from this payload, but not projectname. How to fetch these keys from custom payload?

You can pass the data on a metadata key. You can then retrieve the metadata in action_session_start on the session_started_metadata slot. An example is shown here.

Thanks @stephens. It is working as expected.

Also, something I didn’t found on the documentation (maybe i didn’t search properly) is that the metadata can obtained in each event.

class MyAction(Action):
    # ....
    async def run(
        self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict
    ) -> List[Dict[Text, Any]]:
        tracker.events[-1].get("metadata").get("your-custom-data")

You only need to make sure that the event is an user event. We get the last one by running something like:

def is_user_event(event: Dict[Text, Any]):
    return event.get("event") == "user"

latest_user_event = next(filter(is_user_event, reversed(tracker.events)), None)