Vaasir Nisaar S
Vaasir Nisaar S

Reputation: 31

How to create webhook dialogflow API for POST request and response using C# .Net

enter image description here

I have trained dialogflow but i want to create an webhook API for receiving and sending an response. I have created the intent with Enabled the webhook to get response in it. Any help would be appreciated.....

Upvotes: 0

Views: 1739

Answers (1)

Vaasir Nisaar S
Vaasir Nisaar S

Reputation: 31

[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" }; ;
            //return "Connecteds";
        }

Upvotes: 1

Related Questions