Mohamed Halat
Mohamed Halat

Reputation: 43

manipulating a specific context using output context response

I'm currently trying to change a specific value of one of my context using webhook response and from what I found, the following should work:

       {
            "fulfillmentText": ${textToSpeech},
            "fulfillmentMessages": [{ "text": { "text": [${text}] } }],
            "payload": {
                "google": {
                    "expectUserResponse": true,
                    "richResponse": {
                        "items": [
                            {
                                "simpleResponse": {
                                    "textToSpeech": ${textToSpeech},
                                    "displayText": ${text}
                                }
                            }
                        ],
                        "suggestions": ${suggestions},
                        "linkOutSuggestion": {
                            "destinationName": "Feedback",
                            "url": ${feedbackURL}
                        }
                    }
                }
            },
            "outputContexts": [
                {
                  "name": "projects/${projectID}/agent/sessions/${conversationID}/contexts/${context}",
                  "lifespanCount": 15,
                  "parameters": { 
                    "param":"value"
                   }
                }]
        }

However, this does nothing to change any parameters specified within that context. Am I doing something incorrectly or is there a better method of changing parameters for an output context using webhook responses?

Upvotes: 0

Views: 451

Answers (2)

Mohamed Halat
Mohamed Halat

Reputation: 43

Just managed to solve the issue. Instead of trying to create my own output context i just manipulated the values in req.body.queryResult.outputContexts.

For example: req.body.queryResult.outputContexts[0].parameters.param="value"

and then sent the response with the original outputContext

{
            "fulfillmentText": ${textToSpeech},
            "fulfillmentMessages": [{ "text": { "text": [${text}] } }],
            "payload": {
                "google": {
                    "expectUserResponse": true,
                    "richResponse": {
                        "items": [
                            {
                                "simpleResponse": {
                                    "textToSpeech": ${textToSpeech},
                                    "displayText": ${text}
                                }
                            }
                        ],
                        "suggestions": ${suggestions},
                        "linkOutSuggestion": {
                            "destinationName": "Feedback",
                            "url": ${feedbackURL}
                        }
                    }
                }
            },
            "outputContexts": ${req.body.queryResult.outputContexts}
        }

Upvotes: 0

Prisoner
Prisoner

Reputation: 50741

You may want to check how your Incoming Contexts are named.

Names can have either of the following formats:

  • projects/<Project ID>/agent/sessions/<Session ID>/contexts/<Context ID>
  • projects/<Project ID>/agent/environments/<Environment ID>/users/<User ID>/sessions/<Session ID>/contexts/<Context ID>

If the contexts are coming in using the second format (which includes environment and user IDs), then you'll need to create contexts with similar names.

Specifically, you the part before /contexts/<Context ID> should match the full session string provided in the WebhookRequest which, you guessed it, matches one of the following two patterns:

  • projects/<Project ID>/agent/sessions/<Session ID>
  • projects/<Project ID>/agent/environments/<Environment ID>/users/<User ID>/sessions/<Session ID>

Upvotes: 1

Related Questions