Setting output contexts in Dialogflow

本小妞迷上赌 提交于 2019-12-08 10:52:21

问题


Using the C# client library for Dialogflow, I am trying to set the output context in a webhook response. However, the output context field is read only. This is my code:

WebhookResponse response = new WebhookResponse
   {
       FulfillmentText = "This is a test",
       OutputContexts = ... //Regardless of what I try and set OutputContexts to be, I get the error "property or indexer 'WebhookResponse.OutputContexts' cannot be assigned to -- it is read only"
   };

How do I set the output context?


回答1:


I know this is an old question but just in case someone has the same problem.

You can not assign a new list to OutputContexts, you have to add them to the list:

For example:

response.OutputContexts.Add(new Context
            {
                Name = $"{request.Session}/your_context",
                LifespanCount = 1
            });



回答2:


I think the response json which you are forming is wrong.
Below is the correct json response which you need to send:

{
    "fulfillmentText = "This is a test",
    "outputContexts": [
        {
            "name": "projects/project_id/agent/sessions/session_id/contexts/your_context",
            "lifespanCount": 5,
            "parameters": {
                "foo": "bar",
                "foo1": "bar1"
            }
        }
    ],
    "followupEventInput": {
        "name": "even_name"
    }
}


来源:https://stackoverflow.com/questions/52559839/setting-output-contexts-in-dialogflow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!