Ejemplo n.º 1
0
        public async Task FunctionHandler(object input, ILambdaContext context)
        {
            if (await GetSecrets())
            {
                Boolean liveInstance = false;
                JObject inputJson    = JObject.Parse(input.ToString());
                caseReference = (String)inputJson.SelectToken("CaseReference");
                if (caseReference.ToLower().Contains("emn"))
                {
                    sqsRegion = RegionEndpoint.EUWest2;
                }
                taskToken = (String)inputJson.SelectToken("TaskToken");
                try
                {
                    if (context.InvokedFunctionArn.ToLower().Contains("prod"))
                    {
                        liveInstance = true;
                    }
                }
                catch (Exception)
                {
                }

                if (liveInstance)
                {
                    cxmEndPoint        = secrets.cxmEndPointLive;
                    cxmAPIKey          = secrets.cxmAPIKeyLive;
                    templateBucketName = secrets.TemplateBucketLive;
                }
                else
                {
                    cxmEndPoint        = secrets.cxmEndPointTest;
                    cxmAPIKey          = secrets.cxmAPIKeyTest;
                    templateBucketName = secrets.TemplateBucketTest;
                }
                caseDetails = await GetCustomerContactAsync();

                String emailContents = await FormatEmailAsync();

                if (await SendMessageAsync(emailContents, caseDetails.emailTo, secrets.norbertSendFrom))
                {
                    await TransitionCaseAsync("close-case");
                    await SendSuccessAsync();
                }
            }
        }
Ejemplo n.º 2
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);
                    try
                    {
                        caseDetails.CustomerHasUpdated = (Boolean)caseSearch.SelectToken("values.customer_has_updated");
                    }
                    catch (Exception) { }

                    caseDetails.FullEmail      = GetStringValueFromJSON(caseSearch, "values.original_email");
                    caseDetails.emailTo        = (String)caseSearch.SelectToken("values.forward_email_to");
                    caseDetails.emailFrom      = (String)caseSearch.SelectToken("values.email");
                    caseDetails.enquiryDetails = (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);
        }