public IHttpActionResult Post([FromBody] ApiAiRequest request) { int num1 = Convert.ToInt32(request.result.parameters["num1"]); int num2 = Convert.ToInt32(request.result.parameters["num2"]); int sum = num1 + num2; string speech = $"Sum of {num1} and {num2} is {sum}"; ApiAiResponse response = new ApiAiResponse { speech = speech, displayText = speech }; return(Ok(response)); }
//This function creates the response to send back to Dialogflow. public IHttpActionResult Respond(string responsetext, bool links) { if (links) { string[] lines = responsetext.Split(Environment.NewLine.ToCharArray()[0]); KommunicateResponse rs = new KommunicateResponse { message = lines[0], platform = "kommunicate", metadata = new Metadata() { contentType = "300", templateId = "3", payload = new List <Payload>() } }; for (int i = 1; i < lines.Length; i++) { string code = lines[i].Split('-')[0].Remove(0, 1); Payload pl = new Payload { type = "link", url = "http://datareports.lsu.edu/Reports.aspx?yr=" + DateTime.Now.Year + "&rpt=" + code + "&p=ci", name = lines[i].Remove(0, 1) }; rs.metadata.payload.Add(pl); } //return Json(rs); ApiAiResponse response = new ApiAiResponse { fulfillmentText = responsetext, outputContexts = new List <OutputContext>() }; return(Json(response)); } else { ApiAiResponse response = new ApiAiResponse { fulfillmentText = responsetext, outputContexts = new List <OutputContext>() }; return(Json(response)); } }