【发布时间】:2018-06-14 11:19:18
【问题描述】:
我对 dialogflow 和 WebAPI 非常陌生,并且在使用 C# 编写并托管在 Azure 上的简单 dialogflow 实现 webhook 时遇到了麻烦。我正在使用 dialogflow V2.0 API 版本。
目前我的履行工作并返回一个简单的响应,但不考虑意图和参数。我现在正在尝试解析 JSON 获取意图做一个简单的选择案例并返回接收到的参数的值。这给我带来了很多麻烦。下面给出了 webhook 链接、我的代码和“catch”块中返回的错误消息
public JsonResult Post(string value)
{
try
{
dynamic obj = JsonConvert.DeserializeObject(value);
string Location = string.Empty;
switch (obj.intent.displayName)
{
case "getstock":
Location = obj.outContexts[0].parameters[0].Location;
break;
}
WebhookResponse r = new WebhookResponse();
r.fulfillmentText = string.Format("The stock at {0} is valuing Rs. 31 Lakhs \n And consists of items such as slatwall, grid and new pillar. The detailed list of the same has been email to you", Location);
r.source = "API.AI";
Response.ContentType = "application/json";
return Json(r);
} catch(Exception e)
{
WebhookResponse err = new WebhookResponse();
err.fulfillmentText = e.Message;
return Json(err);
}
}
错误信息:
Value cannot be null.
Parameter name: value
上面的函数是通过POST调用的,你可以使用POSTMAN,你会得到JSON响应。
此外,我正在使用带有控制器的 Visual Studio 2017 的 ASP.Net Web Api
【问题讨论】:
-
这个函数是怎么调用的?看起来它被
value的 null 调用了。我们需要查看更多信息以帮助了解正在发生的事情。 -
它被对话流调用,我无法控制它
-
您能否更新您的问题以提供有关如何将您提供给 dialogflow 的 URL 路由到 Azure 和您正在使用的 C# 框架中的特定函数的信息?
-
post 函数有一个 http post 属性,所以它是用 post 调用的,我也确信 post 正在工作,因为 web 钩子在 catch 块中返回响应
-
如果您有解决方案,可以分享答案吗?
标签: c# webhooks actions-on-google dialogflow-es google-home