Get custom parameter in bot webhook and access it in the actions

Hello,

I want to pass a custom parameter, e.g.: “token” when a request is sent to my Rasa backend. This custom parameter I then want to access from a custom action. Is that somehow possible?

An example request:

{
  "sender": "sender1",
  "message": "How much money do I have on my bank account? ",
  "token": "123456"
}

Concerning the code in my actions.py, I am currently just trying out and using the example code from the documentation.

Thanks!

Hey @threxx. I think you should use the “metadata” object to transport custom data. Look here: https://rasa.com/docs/rasa/connectors/custom-connectors

1 Like

Hey, thanks for the input. As far as I understood I need to implement a custom connector then as well? Or is there a way to access the metadata in an action without it?

If you’re using the REST channel it supports the metadata object as shown in the link provided above by @Butusov

This somehow does not work for me. Let me show you my code, maybe I am doing something wrong:

my request body (GET request via postman http://localhost:5005/webhooks/rest/webhook ) is:

{
  "sender": "5db1ad69-b004-4aa4-a4bf-037abd7ba9af",
  "message": "List all my courses",
  "metadata": {
      "token": "some extra information"
  }
}

And in the action.py I just do print(tracker.latest_message):

from typing import Text, Dict, Any, List
from rasa_sdk import Action, Tracker
from rasa_sdk.events import SlotSet
from rasa_sdk.executor import CollectingDispatcher

class ActionCheckRestaurants(Action):
	def name(self) -> Text:
		return "action_get_courses"

	def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
		print(tracker.latest_message)
		dispatcher.utter_message(text = "Hello")
		return []

with the following result:

{'intent': {'id': -3970330514659824069, 'name': 'get_courses', 'confidence': 0.9978423714637756}, 'entities': [], 'text': 'List all my courses', 'message_id': 'ded8a95b1c0f4230932d2f8a35279f26', 'metadata': {}, 'intent_ranking': [{'id': -3970330514659824069, 'name': 'get_courses', 'confidence': 0.9978423714637756}, {'id': 9073406446022162066, 'name': 'out_of_scope', 'confidence': 0.0020098222885280848}, {'id': -5089103512759352920, 'name': 'thank', 'confidence': 8.310468547279015e-05}, {'id': 2222171025580606878, 'name': 'affirm', 'confidence': 3.207153713447042e-05}, {'id': 1515188917182966015, 'name': 'faq', 'confidence': 1.7392963854945265e-05}, {'id': 5517892651944656367, 'name': 'goodbye', 'confidence': 1.4894237210683059e-05}, {'id': 3016223801878893438, 'name': 'greet', 'confidence': 2.8274325813981704e-07}, {'id': 1952904714508125642, 'name': 'deny', 'confidence': 7.317380124050032e-08}], 'response_selector': {'all_retrieval_intents': ....

So metadata seems to be an empty object. Am I missing something?

No, I also tried it and it didn’t work for me. I think the code example I sent you to is no longer working in 2.x.

Instead of using the earlier link I provided, you should base your code on the latest source for action_session_start.

Thanks for pointing me there. As I am quite new to Rasa, does that mean that I need to implement action_session_start in my action.py as well?

Looks like this issue has already been reported here. Please follow progress for a fix there.

So I updated processor.py in core as you have shown in the other issue. However, I again couldn’t find metadata anywhere. I thought to find them in the slots or in the latest_message. But the slots do not have anything stored and metadata in latest_message is still an empty object. Where should it be stored? How can I access it in my custom action?

Hello! Did you manage to resolve this? I am struggling with a similar issue myself. Thanks!