Is it possible to pass more data in response?

Hi, it’s possible to add more data in request: How to pass metadata in POST request and then extract it?

But is it possibie to do the same thing with response?

Example:

After sending POST request with body:

{
   "sender": "323",
   "message": "hey"
}

I want to pass slot values into response (but not as a text)

[
    {
        "recipient_id": "323",
        "text": "Hey"
    },
    {
        "recipient_id": "323",
        "metadata": 
        {
            "email":"email@from.slot"
        }
    }
]

Is something like this achievable?

looks like you want to check out Custom Output Payloads

Thanks for an answer, but I’m still having trouble with passing slot to response.

if I create template like this:

  utter_test_metadata:
    - custom:
        - first_name: "{first_name}"

The respone looks like this (its not extracting slot):

{
        "recipient_id": "323",
        "custom": [
            {
                "first_name": "{first_name}"
            }
        ]
    },

And if I create template like this:

  utter_test_metadata:
    - custom:
        - first_name: {first_name}

The response:

{
        "recipient_id": "323",
        "custom": [
            {
                "first_name": {
                    "first_name": null
                }
            }
        ]
    },

What is the proper way of passing slot here?

Solution :

In custom action create template for custom output, then fill this template with slot values

def run(self, dispatcher, tracker, domain):
    first_name = tracker.get_slot("first_name")
    last_name = tracker.get_slot("last_name")
    template = {
        "custom": {
            "first_name": "{first_name}",
            "last_name": "{last_name}"
        }
    }
    t = TemplatedNaturalLanguageGenerator(templates=dict())
    result = t._fill_template(template=template, filled_slots={"first_name": first_name, "last_name": last_name})

    dispatcher.utter_custom_json(result)

Now, the slot values can be found in response:

{
    "recipient_id": "3221223",
    "custom": {
        "custom": {
            "first_name": "aaaa",
            "last_name": "bbbb"
        }
    }
},

More details here:

https://github.com/RasaHQ/rasa/pull/4079/files