Exemplo n.º 1
0
        private async Task <Boolean> UpdateCaseDetailsAsync(Sentiment sentiment)
        {
            HttpClient cxmClient = new HttpClient();

            cxmClient.BaseAddress = new Uri(cxmEndPoint);
            String uri = "/api/service-api/norbert/case/" + caseReference + "/edit?key=" + cxmAPIKey;
            Dictionary <string, string> cxmPayload = new Dictionary <string, string>
            {
                { "sentiment", sentiment.sentimentRating },
                { "sentiment-score-mixed", sentiment.sentimentMixed },
                { "sentiment-score-negative", sentiment.sentimentNegative },
                { "sentiment-score-neutral", sentiment.sentimentNeutral },
                { "sentiment-score-positive", sentiment.sentimentPositive }
            };
            String        json    = JsonConvert.SerializeObject(cxmPayload, Formatting.Indented);
            StringContent content = new StringContent(json);

            HttpResponseMessage response = await cxmClient.PatchAsync(uri, content);

            try
            {
                response.EnsureSuccessStatusCode();
                return(await StoreSentimentToDynamoAsync(caseReference, sentiment.sentimentRating));
            }
            catch (Exception error)
            {
                await SendFailureAsync(error.Message, "UpdateCaseDetailsAsync");

                Console.WriteLine("ERROR : UpdateCaseDetailsAsync :  " + error.Message);
                return(false);
            }
        }
Exemplo n.º 2
0
        private async Task <Sentiment> GetSentimentFromAWSAsync(String customerContact)
        {
            Sentiment caseSentiment = new Sentiment();

            try
            {
                AmazonComprehendClient comprehendClient = new AmazonComprehendClient(RegionEndpoint.EUWest2);

                Console.WriteLine("Calling DetectSentiment");
                DetectSentimentRequest detectSentimentRequest = new DetectSentimentRequest()
                {
                    Text         = customerContact,
                    LanguageCode = "en"
                };
                DetectSentimentResponse detectSentimentResponse = await comprehendClient.DetectSentimentAsync(detectSentimentRequest);

                caseSentiment.success           = true;
                caseSentiment.sentimentRating   = detectSentimentResponse.Sentiment.ToString().ToLower();
                caseSentiment.sentimentMixed    = ((int)(detectSentimentResponse.SentimentScore.Mixed * 100)).ToString();
                caseSentiment.sentimentNegative = ((int)(detectSentimentResponse.SentimentScore.Negative * 100)).ToString();
                caseSentiment.sentimentNeutral  = ((int)(detectSentimentResponse.SentimentScore.Neutral * 100)).ToString();
                caseSentiment.sentimentPositive = ((int)(detectSentimentResponse.SentimentScore.Positive * 100)).ToString();
                return(caseSentiment);
            }
            catch (Exception error)
            {
                caseSentiment.success = false;
                await SendFailureAsync("Getting Sentiment", error.Message);

                Console.WriteLine("ERROR : GetSentimentFromAWSAsync : " + error.StackTrace);
                return(caseSentiment);
            }
        }
Exemplo n.º 3
0
        public async Task FunctionHandler(object input, ILambdaContext context)
        {
            if (await GetSecrets())
            {
                JObject o = JObject.Parse(input.ToString());
                caseReference = (string)o.SelectToken("CaseReference");
                taskToken     = (string)o.SelectToken("TaskToken");
                Boolean liveInstance = false;
                try
                {
                    if (context.InvokedFunctionArn.ToLower().Contains("prod"))
                    {
                        Console.WriteLine("Prod version");
                        liveInstance = true;
                        tableName    = "MailBotCasesLive";
                    }
                }
                catch (Exception)
                {
                }

                if (liveInstance)
                {
                    cxmEndPoint = secrets.cxmEndPointLive;
                    cxmAPIKey   = secrets.cxmAPIKeyLive;
                    caseDetails = await GetCustomerContactAsync();

                    Sentiment sentimentLive = await GetSentimentFromAWSAsync(caseDetails.customerContact);

                    if (await UpdateCaseDetailsAsync(sentimentLive))
                    {
                        await SendSuccessAsync();
                    }
                }
                else
                {
                    cxmEndPoint = secrets.cxmEndPointTest;
                    cxmAPIKey   = secrets.cxmAPIKeyTest;
                    caseDetails = await GetCustomerContactAsync();

                    Sentiment sentimentTest = await GetSentimentFromAWSAsync(caseDetails.customerContact);

                    if (await UpdateCaseDetailsAsync(sentimentTest))
                    {
                        await SendSuccessAsync();
                    }
                }
            }
        }