使用输出上下文响应来操纵特定上下文 [英] manipulating a specific context using output context response

查看:108
本文介绍了使用输出上下文响应来操纵特定上下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试使用webhook响应以及我从找到,以下方法应该起作用:

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"
                   }
                }]
        }

但是,这不会更改在该上下文中指定的任何参数.我是做错了什么,还是有更好的方法使用webhook响应来更改输出上下文的参数?

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?

推荐答案

只是设法解决了这个问题. 我没有尝试创建自己的输出上下文,而是操作了req.body.queryResult.outputContexts中的值.

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.

例如: req.body.queryResult.outputContexts[0].parameters.param="value"

,然后发送带有原始outputContext的响应

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}
        }

这篇关于使用输出上下文响应来操纵特定上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆