问题
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?
回答1:
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>
回答2:
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}
}
来源:https://stackoverflow.com/questions/62363430/manipulating-a-specific-context-using-output-context-response