Example #1
0
        public async Task <IActionResult> PostAsync([FromBody] ChatBotParametrs value)
        {
            var test = value.Utterance;

            using (var client = new HttpClient())
            {
                try
                {
                    var credentials       = GoogleCredential.FromFile(@"../test_project/appsettings.json");
                    var scopedCredentials = credentials.CreateScoped(DialogflowService.Scope.CloudPlatform);
                    var _oAuthToken       = scopedCredentials.UnderlyingCredential.GetAccessTokenForRequestAsync().Result;
                    client.BaseAddress = new Uri("https://dialogflow.googleapis.com");
                    client.DefaultRequestHeaders.Add("Authorization", $"Bearer {_oAuthToken}");
                    var content = new StringContent("{\"queryInput\":{\"text\":{\"text\":\"" + test + "\",\"languageCode\":\"en\"}},\"queryParams\":{\"timeZone\":\"Europe/Kiev\"}}", Encoding.UTF8, "application/json");
                    var result  = await client.PostAsync("/v2/projects/chatbothelper-aqjiii/agent/sessions/5450f4f7-3656-b245-9124-2c1364d11cea:detectIntent", content);

                    string resultContent = await result.Content.ReadAsStringAsync();

                    return(Ok(resultContent));
                }
                catch (Exception ex)
                {
                    return(BadRequest(ex.Message));
                }
            }
        }
        public async Task <IActionResult> Post([FromBody] ChatBotParametrs value)
        {
            if (value.Utterance.ToLower() == "hi" || value.Utterance.ToLower() == "hello")
            {
                return(Ok("{\"prediction\":{ \"topIntent\": \"Hello!\"}}"));
            }
            try
            {
                var result = await CallBotService.MakeRequest(value.Utterance);

                return(Ok(result));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }