maxime
maxime

Reputation: 2315

Use fulfillment outputContext parameters into a text response

I use DialogFlow with a fulfillment on an intent.

The fulfillment has this response:

{
    "outputContexts": [
        {
            "name": "search-results",
            "lifespanCount": 9999,
            "parameters": {
                "foo": "bar",
            }
        }
    ]
  }

On the same intent (that does not have search-results as an input context), I'd like to use the parameters returned on the outputContext from my fulfillment on the responses like that

Parameters Responses

Unfortunately, when I run this setup, it does not work. Nothing in the parameters, and the response is "Not available". Even if my output context is set.

Response Parameters values

How can I use the output context parameters immediately in my response ? A possible workarround would be to return directly the fulfillmentMessages with the value - but I find it harder to maintain and overkill for a single variable !

Upvotes: 0

Views: 2338

Answers (1)

Akshay Pratap Singh
Akshay Pratap Singh

Reputation: 3327

You cannot do so by same intent, which do slot filling of parameter, run webhook fulfillment and use output context with same intent.

But, what you want to do is achievable by creating a separate intent (for example intent_show_search_results) for showing search results, this intent will take search-results in input context. And, in text response you can use that context's parameter for preparing user message, use context parameter in message using # pattern to access context parameters, like so

Foo has the value #search-results.foo

Webhook response of fulfillment for v1 api :-

{
  "contextOut": [
    {
      "name": "search-results",
      "lifespan": 9999,
      "parameters": {
        "foo": "bar"
      }
    }
  ],
  "followupEvent": {
    "name": "intent_show_search_results"
  }
}

Webhook response of fulfillment for v2 api :-

{
    "outputContexts": [
        {
            "name": "projects/${PROJECT_ID}/agent/sessions/${SESSION_ID}/contexts/search-results",
            "lifespanCount": 9999,
            "parameters": {
                "foo": "bar"
            }
        }
    ],
    "followupEventInput": {
        "name": "intent_show_search_results",
        "languageCode": "en-US"
    }
}

Upvotes: 2

Related Questions