Ejemplo n.º 1
0
        public async Task <ApiResponse> Refresh(Guid id, string userId)
        {
            ApiResponse res  = new ApiResponse();
            var         site = _dbSet.FirstOrDefault(x => x.Id == id && x.UserId == userId);

            if (site != null)
            {
                switch (site.SiteId)
                {
                case (int)IntegrationType.GetResponse:
                    res = new GetResponseTask(site.ApiKey).Auth();
                    break;

                case (int)IntegrationType.MailChimp:
                    res = new MailChimpTask(site.ApiKey).Auth();
                    break;

                case (int)IntegrationType.Autopilot:
                    res = new AutopilotTask(site.ApiKey).Auth();
                    break;

                case (int)IntegrationType.ActiveCampain:
                    res = new IntegrationServices.ActiveCampain.ActiveCampainTask(site.AccId, site.ApiKey).Auth();
                    break;

                case (int)IntegrationType.InfusionSoft:
                    res = new IntegrationServices.InfusionSoft.InfusionSoftTask(site.ApiKey, site.Password).GetCampaigns();
                    if (res.Code == System.Net.HttpStatusCode.Unauthorized)
                    {
                        var newToken = new IntegrationServices.InfusionSoft.InfusionSoftTask(site.ApiKey, site.Password).Refresh();
                        if (newToken != null && !string.IsNullOrEmpty(newToken.access_token))
                        {
                            site.ApiKey = newToken.access_token;
                            this.Commit();
                            res.Code = System.Net.HttpStatusCode.OK;
                        }
                    }
                    break;

                case (int)IntegrationType.Gmail:
                    res = new EmailServices.GmailPersonalSvc(site.ApiKey, site.TokenJson).Auth();
                    break;

                case (int)IntegrationType.GoogleSheet:
                    res = new EmailServices.GoogleSheetSvc(site.ApiKey, site.TokenJson).Auth();
                    break;

                case (int)IntegrationType.Wordpress:
                    res = new Utils.WordpressUtils(site.AccId, site.ApiKey).Auth();
                    if (res.Code == System.Net.HttpStatusCode.NotFound)
                    {
                        throw new BusinessException("Không kiểm tra được kết nối WP. Cấu hình này được dùng để xuất bản từ phía WP");
                    }
                    break;

                case (int)IntegrationType.Shopify:
                    res = await new ShopifyService.ShopifyService(site.AccId, site.ApiKey).CountPage();
                    break;

                case (int)IntegrationType.Haravan:
                    res = await new HaravanService.HaravanService(site.ApiKey).CountPage();
                    break;

                case (int)IntegrationType.Sapo:
                    res = await new SapoService.SapoService(site.AccId, site.ApiKey).CountPage();
                    break;

                case (int)IntegrationType.Sms:
                    string sim     = string.IsNullOrEmpty(site.AccId) == false ? "sim1" : "sim2";
                    var    profile = uow.UserProfile.Get(userId);
                    var    mobile  = profile == null ? "0968152579" : profile.Mobile;
                    var    r       = new Services.SmsService().Send(site.Phone, site.Password, sim, mobile, $"Chao {profile.FullName}. Punnel sms dang dung tot nhe");
                    if (r == true)
                    {
                        res.Code = System.Net.HttpStatusCode.OK;
                    }
                    else
                    {
                        res.Code    = System.Net.HttpStatusCode.BadRequest;
                        res.Message = "Thiết thị không thể gửi tin nhắn sms. Vui lòng kiểm tra lại thiết bị & ứng dụng SMS đã cài đặt";
                    }
                    break;
                }
                if (res.Code != System.Net.HttpStatusCode.OK)
                {
                    site.IsExpired = true;
                    this.Commit();
                }
                else
                {
                    site.IsExpired = false;
                    this.Commit();
                }
            }
            return(res);
        }
Ejemplo n.º 2
0
        public ApiResponse SendViaApi(LeadToSendIntegrationModel item)
        {
            ApiResponse result = new ApiResponse();

            switch (item.SiteId)
            {
            case (int)Core.Entities.IntegrationType.GetResponse:
                var res = new IntegrationServices.GetResponse.GetResponseTask(item.ApiKey).AddContact(new Entities.Integration.GetResponse.ContactRequest()
                {
                    name     = item.FirstName + " " + item.LastName,
                    email    = item.Email,
                    campaign = new Entities.Integration.GetResponse.Campaign()
                    {
                        campaignId = item.ListId
                    }
                });
                result = res;
                break;

            case (int)Core.Entities.IntegrationType.MailChimp:
                var res1 = new IntegrationServices.MailChimp.MailChimpTask(item.ApiKey).AddContact(new Entities.Integration.MailChimp.ContactRequest()
                {
                    email_address = item.Email,
                    status        = "subscribed",
                    merge_fields  = new Entities.Integration.MailChimp.MergeFields()
                    {
                        FNAME = item.FirstName,
                        LNAME = item.LastName
                    }
                }, item.ListId);
                result = res1;
                break;

            case (int)Core.Entities.IntegrationType.Autopilot:
                var res_al = new IntegrationServices.Autopilot.AutopilotTask(item.ApiKey).AddContact(new Entities.Integration.Autopilot.ContactRequest()
                {
                    contact = new Entities.Integration.Autopilot.ContactModelRequest()
                    {
                        Email     = item.Email,
                        FirstName = item.FirstName,
                        LastName  = item.LastName
                    }
                }, item.ListId);
                result = res_al;
                break;

            case (int)Core.Entities.IntegrationType.ActiveCampain:
                var itg = uow.Integration.GetByApiKey(item.SiteId, item.ApiKey);
                if (itg != null)
                {
                    var res_at = new IntegrationServices.ActiveCampain.ActiveCampainTask(itg.AccId, item.ApiKey).AddContact(new Entities.Integration.ActiveCampain.ContactRequest
                    {
                        contact = new Entities.Integration.ActiveCampain.ContactModelRequest()
                        {
                            email     = item.Email,
                            phone     = item.Phone,
                            firstName = item.FirstName,
                            lastName  = item.LastName
                        }
                    }, item.ListId);
                    result = res_at;
                }
                break;

            case (int)Core.Entities.IntegrationType.InfusionSoft:
                var emailadd = new List <Entities.Integration.InfusionSoft.EmailAddress>();
                emailadd.Add(new Entities.Integration.InfusionSoft.EmailAddress()
                {
                    email = item.Email, field = "EMAIL1"
                });
                var phoneadd = new List <Entities.Integration.InfusionSoft.PhoneNumber>();
                phoneadd.Add(new Entities.Integration.InfusionSoft.PhoneNumber()
                {
                    number = item.Phone, field = "PHONE1"
                });
                var res_in = new IntegrationServices.InfusionSoft.InfusionSoftTask(item.ApiKey).AddContact(new Entities.Integration.InfusionSoft.ContactRequest()
                {
                    email_addresses = emailadd,
                    phone_numbers   = phoneadd,
                    family_name     = item.FirstName + " " + item.LastName
                }, item.ListId);
                result = res_in;
                break;

            case (int)Core.Entities.IntegrationType.GoogleSheet:
                List <Object> d = new List <Object>();
                d.Add(item.FullName);
                d.Add(item.Email);
                d.Add(item.Phone);
                d.Add(item.RegionName);
                d.Add(item.Referer);
                d.Add(item.SubmitDate);
                if (string.IsNullOrEmpty(item.JsonData) == false)
                {
                    var moreInfo = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Entities.RequestModel.FormData> >(item.JsonData);
                    foreach (var i in moreInfo)
                    {
                        d.Add(i.value);
                    }
                }
                var res2 = new EmailServices.GoogleSheetSvc(item.ApiKey, item.TokenJson).AddItemOnSheet(item.ListId, d);
                result = res2;
                break;
            }
            return(result);
        }