public async Task <dynamic> Get(string companyName)
        {
            if (CheckClientSecret())
            {
                try
                {
                    using (HttpClient client = new HttpClient())
                        using (Entities db = new Entities())
                        {
                            CompanyRoot.Company company = await CompanySearch.GetCompany(client, companyName, db);

                            EngagementsRoot engagementsRoot = await EngagementsSearch.GetEngagements(client, companyName, db, company.Results.FirstOrDefault().Id);

                            List <EngagementsDTO> allEngagementsDTO = new List <EngagementsDTO>();

                            for (int i = 0; i < engagementsRoot.Results.Count; i++)
                            {
                                allEngagementsDTO.Add(new EngagementsDTO(engagementsRoot.Results[i]));
                            }

                            return(allEngagementsDTO);
                        }
                }
                catch (Exception ex)
                {
                    return(ex);
                }
            }
            else
            {
                return(new HttpResponseMessage(HttpStatusCode.Forbidden));
            }
        }
예제 #2
0
        public EngagementsDTO(Result engagement)
        {
            EngagementType = engagement.Engagement.Type;
            CreatedAt      = DateTimeOffset.FromUnixTimeMilliseconds(engagement.Engagement.CreatedAt);
            LastUpdatedAt  = DateTimeOffset.FromUnixTimeMilliseconds(engagement.Engagement.LastUpdated);

            if (string.Equals(engagement.Engagement.Type, "EMAIL") || string.Equals(engagement.Engagement.Type, "INCOMING_EMAIL"))
            {
                //Identify outbound emails by checking the 'From' address for the company name (CUSTOM_FIELD)

                if (engagement.Metadata.From.Email.Contains("COMPANY_NAME"))
                {
                    Direction = "Outbound";
                }
                else
                {
                    Direction = "Inbound";
                }

                Sender              = new EngagementsContact($"{engagement.Metadata.From.FirstName} {engagement.Metadata.From.LastName}", engagement.Metadata.From.Email);
                Recipients          = EngagementsSearch.CreateContactList(engagement.Metadata.To);
                CC                  = EngagementsSearch.CreateContactList(engagement.Metadata.Cc);
                BCC                 = EngagementsSearch.CreateContactList(engagement.Metadata.Bcc);
                Subject             = engagement.Metadata.Subject;
                Body                = engagement.Engagement.BodyPreview;
                FromNumber          = null;
                ToNumber            = null;
                CallDurationSeconds = null;
            }
            else if (string.Equals(engagement.Engagement.Type, "CALL"))
            {
                if (engagement.Engagement.BodyPreview.Contains("Inbound answered"))
                {
                    Direction = "Inbound";
                }
                else
                {
                    Direction = "Outbound";
                }

                Sender              = null;
                Recipients          = null;
                CC                  = null;
                BCC                 = null;
                Subject             = null;
                Body                = null;
                FromNumber          = engagement.Metadata.FromNumber;
                ToNumber            = engagement.Metadata.ToNumber;
                CallDurationSeconds = engagement.Metadata.DurationMilliseconds / 1000;
            }
            else if (string.Equals(engagement.Engagement.Type, "TASK"))
            {
                Direction           = null;
                Sender              = null;
                Recipients          = null;
                CC                  = null;
                BCC                 = null;
                Subject             = engagement.Metadata.Subject;
                Body                = null;
                FromNumber          = null;
                ToNumber            = null;
                CallDurationSeconds = null;
            }
            else
            {
                Direction           = null;
                Sender              = null;
                Recipients          = null;
                CC                  = null;
                BCC                 = null;
                Subject             = null;
                Body                = null;
                FromNumber          = null;
                ToNumber            = null;
                CallDurationSeconds = null;
            }
        }