Passing Metadata to Custom Action

I’m building a rasa bot and I would like to test it before asking the API developers to integrate it. I am currently trying to pass input params in the metadata section and use them in a custom action. However, I’m no sure how to get the metadata into the custom action… I don’t want to build a whole customer connector just to test the metadata function in my custom action , I just want to pass some metadata from a post request to an action.

Here’s what I’m doing so far in actions.py :

class ActionSayHi(Action):

def name(self):

  return "action_say_hi"

def run(self, dispatcher, tracker, domain):

  events = tracker.events[::-1]
  user_events = []
  for e in events:
      print(e.get('metadata', 'Nothing'))

  dispatcher.utter_message(message="Hey there!")
  return []

Then I run “rasa run actions” and “rasa run --enable-api” and in a third terminal I run

curl -s localhost:5005/webhooks/rest/webhook -d ‘{ “sender”: “RasaTest”, “message”: “hi” , “metadata” : {“name”: “Tester”, “time” : “2021-01-10T11:25:43.511Z” }}’

And the action server prints :
{}
Nothing
Nothing
Nothing

Though I’m sure this is working because I do get the dispatcher message on the terminal.

Do I really have to set up a whole Flask server and rest API and custom connector just to develop the code in a way I can test???

Okay I figured it out! So I followed this solution and then added the --connector argument to the curl so now it looks like

rasa run --enable-api --connector “rest_test.RestInputOK”

and i’m getting the metadata to my action server woohooo! Hope this helps anyone who is having a similar issue :slight_smile: