Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Dialogflow WebhookRequest参数列表在C#.NET中为空_C#_.net_Dialogflow Es - Fatal编程技术网

Dialogflow WebhookRequest参数列表在C#.NET中为空

Dialogflow WebhookRequest参数列表在C#.NET中为空,c#,.net,dialogflow-es,C#,.net,Dialogflow Es,我使用@sys.geo-city作为参数,但请求没有获取它: { "responseId": "bd9ad2dd-9a8b-4c66-a1c1-4731dc5a66d2-d5ae01f3", "queryResult": { "queryText": "weather", "parameters": { }, "allRequiredParamsPresent": true, "fulfillmentText": "Let's check the we

我使用@sys.geo-city作为参数,但请求没有获取它:

{ 
"responseId": "bd9ad2dd-9a8b-4c66-a1c1-4731dc5a66d2-d5ae01f3", 
"queryResult": 
{ 
    "queryText": "weather", 
    "parameters": { }, 
    "allRequiredParamsPresent": true,
    "fulfillmentText": "Let's check the weather.", 
    "intent": 
    { 
         "name": "projects/dtc-agent-1-uhoquf/agent/intents/8dde7daa-fd8e-4bd1-8b12-44cb72290d6c",
         "displayName": "Weather" 
    }, 
    "intentDetectionConfidence": 1, "languageCode": "en" 
},
"originalDetectIntentRequest": { "payload": { } }, 
"session": "projects/dtc-agent-1-uhoquf/agent/sessions/cf762b76-13aa-1fd8- fb92-6ee480ec2c5e" }
似乎“参数”应该包含我在Dialogflow控制台中输入的用于天气目的的参数

在我的C#.NET Web API控制器中,我有:

[HttpPost]
public WebhookResponse Post([FromBody] WebhookRequest webhookRequest)
{
   WebhookResponse webhookResponse = new WebhookResponse();     
   webhookResponse.FulfillmentText = webhookRequest.ToString(); 
   return webhookResponse;
}

你是对的,应该这样

您的代码有一个明显错误,那就是解析
WebhookRequest
的方式。使用
[FromBody]
标记注入它将使用系统默认的JSON解析器,这是不正确的。您需要从
Google.Protobuf
名称空间显式使用Protobuf解析器(应包含在
Google.Cloud.Dialogflow.V2
包中):

[HttpPost]
公共WebhookResponse帖子([FromBody]字符串requestString)
{
var requestParser=new Google.Protobuf.JsonParser(
Google.Protobuf.JsonParser.Settings.Default.WithIgnoreUnknownFields(true));
WebhookRequest WebhookRequest=requestParser.Parse(requestString);
// ...
}
请注意,忽略未知字段的设置可能并不总是必要的,但可以方便地避免在将来扩展请求格式时引发异常