【发布时间】:2019-01-29 10:29:04
【问题描述】:
我正在尝试用 C#(在 Azure 上)为 Dialogflow 创建一个 webhook。每次我看到相同的示例,但我的 DialogFlows 不断收到此响应的错误“
这就是我所做的:
- 创建了一个新的 ASP.Net Web 项目 (WebAPI)
- 已安装 NuGet Google.Cloud.DialogFlow V2 (v1.0.0.beta02)
- 将 System.Net.Http 更新到 4.3.3
创建了一个新的控制器
[System.Web.Http.HttpPost]
public dynamic DialogAction([FromBody] WebhookRequest dialogflowRequest)
{
var intentName = dialogflowRequest.QueryResult.Intent.DisplayName;
var actualQuestion = dialogflowRequest.QueryResult.QueryText;
var testAnswer = $"Dialogflow Request for intent {intentName} and question {actualQuestion}";
var parameters = dialogflowRequest.QueryResult.Parameters;
var dialogflowResponse = new WebhookResponse
{
FulfillmentText = testAnswer,
FulfillmentMessages =
{ new Intent.Types.Message
{ SimpleResponses = new Intent.Types.Message.Types.SimpleResponses
{ SimpleResponses_ =
{ new Intent.Types.Message.Types.SimpleResponse
{
DisplayText = testAnswer,
TextToSpeech = testAnswer,
}
}
}
}
}
};
var jsonResponse = dialogflowResponse.ToString();
return new ContentResult
{
Content = jsonResponse,
ContentType = "application/json"
};
- 已将应用程序发布到 Azure,因此有一个 webhook URL。 现在,当我在 dialogflow 中测试它时,响应是:
“Webhook 调用失败。错误:无法解析 webhook JSON 响应:找不到字段:消息 google.cloud.dialogflow.v2.WebhookResponse 中的内容。”
我不明白......我在这里错过了什么?
【问题讨论】:
-
这里是一个例子 [0]。看起来两者之间唯一有意义的区别是您使用 ContextResult 并且 JSON 字符串被转义而不是像您预期的那样未转义。更改 jsonResponse 以便不再转义 JSON 字符串。 [0]github.com/googleapis/google-cloud-dotnet/blob/master/apis/…
标签: azure dialogflow-es