Exemple #1
0
        public ContentResult CheckNutrient()
        {
            var webhookRequest = _googleJsonHelper.GetWebhook(Request);

            WebhookResponse response = new WebhookResponse();

            if (webhookRequest.QueryResult.Parameters.Fields.ContainsKey("Nutrient"))
            {
                var nutrient = webhookRequest.QueryResult.Parameters.Fields.GetValueOrDefault("Nutrient").StringValue;

                // TODO Check if the nutrient is ok
                var nutrientCheckResult = _mongoDBConnector.CheckNutrient(nutrient);

                SimpleResponses simpleResponses = new SimpleResponses();
                SimpleResponse  simpleResponse;

                if (nutrientCheckResult.IsEvilForYou)
                {
                    simpleResponse = new SimpleResponse()
                    {
                        DisplayText =
                            $"Sorry, the {nutrient} seems to be evil for you, because {nutrientCheckResult.Message}. I suggest you this alternative: {nutrientCheckResult.AlternativeNutrient}",
                        TextToSpeech =
                            $"Sorry, the {nutrient} seems to be evil for you, because {nutrientCheckResult.Message}. I suggest you this alternative: {nutrientCheckResult.AlternativeNutrient}"
                    };
                }
                else
                {
                    simpleResponse = new SimpleResponse()
                    {
                        DisplayText  = $"OK {nutrient} seems ok! Would you like to eat it at home, or outside?",
                        TextToSpeech = $"OK {nutrient} seems ok! Would you like to eat it at home, or outside?"
                    };
                }

                simpleResponses.SimpleResponses_.Add(simpleResponse);

                response.FulfillmentMessages.Add(new Message()
                {
                    Platform        = Platform.ActionsOnGoogle,
                    SimpleResponses = simpleResponses
                });
            }


            string responseJson = response.ToString();

            return(Content(responseJson, "application/json"));
        }
Exemple #2
0
        private WebhookResponse ExtractHeadlines(NewsExtract extracts, WebhookResponse returnValue)
        {
            returnValue = new WebhookResponse();
            var headlines = ExtractHeadlines(extracts);

            headlines += Utilities.EndOfCurrentRequest();
            headlines  = Utilities.ConvertAllToASCII(headlines);
            var textMsg = new Text();

            textMsg.Text_.Add(headlines);
            var simpleResponses = new SimpleResponses();
            var simpleResponse  = Utilities.BuildTextToSpeech(headlines);

            simpleResponses.SimpleResponses_.Add(simpleResponse);
            returnValue.FulfillmentMessages.Add(new Intent.Types.Message {
                SimpleResponses = simpleResponses, Platform = Platform.ActionsOnGoogle
            });
            returnValue.FulfillmentMessages.Add(new Intent.Types.Message {
                Text = textMsg
            });
            return(returnValue);
        }