首页 > 解决方案 > 在 Dialogflow 中设置输出上下文

问题描述

使用 Dialogflow 的 C# 客户端库,我试图在 webhook 响应中设置输出上下文。但是,输出上下文字段是只读的。这是我的代码:

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

如何设置输出上下文?

标签: google-cloud-platformwebhooksdialogflow-es

解决方案


我知道这是一个老问题,但以防万一有人遇到同样的问题。

您不能将新列表分配给 OutputContexts,您必须将它们添加到列表中:

例如:

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

推荐阅读