[英]Google Dialogflow V2 webhook not working - InvalidType and Null Exception
我正在按照谷歌示例使用 Google Dailog Flow cersion 2 api 为对话流创建 .net 核心 3.0 webhook。 这是代码
public class DialogflowController : ControllerBase
{
private static readonly JsonParser jsonParser =
new JsonParser(JsonParser.Settings.Default.WithIgnoreUnknownFields(true));
public ContentResult DialogAction()
{
WebhookRequest request;
using (var reader = new StreamReader(Request.Body))
{
request = jsonParser.Parse<WebhookRequest>(reader);
}
// Note: you should authenticate the request here.
// Populate the response
WebhookResponse response = new WebhookResponse
{
// ...
};
string responseJson = response.ToString();
return Content(responseJson, "application/json");
}
}
我正在使用 SoapUI 创建 rest 服务,并使用从 dialogflow 本身复制的发布请求测试代码。 运行时我收到以下错误:
---> System.TypeInitializationException: The type initializer for 'Google.Cloud.Dialogflow.V2.ContextReflection' threw an exception.
---> System.ArgumentNullException: Value cannot be null. (Parameter 'extension')
任何想法为什么或我在这里缺少什么?
谢谢
我的项目目前在 .NET Core 3.1 上,我必须更改代码以从 StreamReader 异步读取。 我不得不改变这个:
using (var reader = new StreamReader(Request.Body))
{
request = jsonParser.Parse<WebhookRequest>(reader);
}
有了这个:
using (var reader = new StreamReader(Request.Body))
{
request = jsonParser.Parse<WebhookRequest>(await reader.ReadToEndAsync());
}
我还必须使用 async 关键字更新方法签名并将 ContentResult 放入任务中。
公共异步任务 DialogAction()
希望这有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.