public async Task <JsonResult> GoogleAssistant([FromBody] ActionRequest input) { try { var intentName = input.QueryResult.Action; // handle welcome / launch requests if (intentName == Intents.Welcome) { return(Json(DialogBuilder.Ask(Messages.Welcome))); } // handle the animal fact response if (intentName == Intents.AnimalFactIntent) { var animalName = input?.QueryResult?.Parameters["Animal"]; // find the animal fact and return it as voice var animalFact = await _context.AnimalFacts.FirstOrDefaultAsync(af => af.AnimalName.ToLower() == animalName.ToLower()); // if we don't have an animal - reprompt if (animalFact == null) { return(Json(DialogBuilder.Ask("I don't know about that animal. Try a different one!"))); } // return the fact return(Json(DialogBuilder.Tell(animalFact.Fact))); } return(Json(DialogBuilder.Tell("Something went wrong. Please try again later."))); } catch { // return a response if something goes wrong return(Json(DialogBuilder.Tell("Something went wrong. Please try again later."))); } }