Ejemplo n.º 1
0
        private async Task <CaseDetails> GetCustomerContactAsync()
        {
            CaseDetails caseDetails = new CaseDetails();
            HttpClient  cxmClient   = new HttpClient();

            cxmClient.BaseAddress = new Uri(cxmEndPoint);
            String             requestParameters = "key=" + cxmAPIKey;
            HttpRequestMessage request           = new HttpRequestMessage(HttpMethod.Get, "/api/service-api/norbert/case/" + caseReference + "?" + requestParameters);

            try
            {
                HttpResponseMessage response = cxmClient.SendAsync(request).Result;
                if (response.IsSuccessStatusCode)
                {
                    HttpContent responseContent = response.Content;
                    String      responseString  = responseContent.ReadAsStringAsync().Result;
                    JObject     caseSearch      = JObject.Parse(responseString);
                    caseDetails.customerContact = (String)caseSearch.SelectToken("values.enquiry_details");
                }
                else
                {
                    await SendFailureAsync("Getting case details for " + caseReference, response.StatusCode.ToString());

                    Console.WriteLine("ERROR : GetStaffResponseAsync : " + request.ToString());
                    Console.WriteLine("ERROR : GetStaffResponseAsync : " + response.StatusCode.ToString());
                }
            }
            catch (Exception error)
            {
                await SendFailureAsync("Getting case details for " + caseReference, error.Message);

                Console.WriteLine("ERROR : GetStaffResponseAsync : " + error.StackTrace);
            }
            return(caseDetails);
        }
Ejemplo n.º 2
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();
                    }
                }
            }
        }