public async Task <NotificationResultEN> PushDepositNotificationAndroid(CampaignEN pCampaign, string pUserEmail, string pFirstName, string pContent) { NotificationResultEN operationResult = new NotificationResultEN(); operationResult.Platform = "ANDROID"; operationResult.Result = false; operationResult.ServiceName = "OneSignal"; try { HttpClient client = new HttpClient(); client.BaseAddress = new Uri(Constants.OneSignalURL); client.DefaultRequestHeaders.Add("authorization", "Basic " + Constants.KEY_ONESIGNAL_YVR_ANDROID); string url = string.Format("/api/v1/notifications"); OneSignalFilter filter = new OneSignalFilter(); filter.field = "tag"; filter.key = "userid"; filter.relation = "="; filter.value = (!SingleTestModeActive()) ? pUserEmail : ConfigurationManager.AppSettings["OneSignal_SingleUserTest_Android"].ToString(); var notificationContent = new { app_id = Constants.APPID_ONESIGNAL_YVR_ANDROID, headings = new { en = pCampaign.NotificationTitle }, contents = new { en = String.Format("Hola {0}. {1}", pFirstName, pContent) }, category = "", collapse_id = "", filters = new object[] { filter } }; var jsonPost = JsonConvert.SerializeObject(notificationContent); StringContent _content = new StringContent(jsonPost, Encoding.UTF8, "application/json"); var response = await client.PostAsync(url, _content); if (response.IsSuccessStatusCode) { var result = response.Content.ReadAsStringAsync().Result; var notificationResult = JsonConvert.DeserializeObject <CreateResultOneSignal>(result); if (notificationResult.errors == null && notificationResult.recipients > 0) { operationResult.CodeResult = "scheduled"; operationResult.Result = true; } } } catch (Exception ex) { Console.WriteLine(ex.InnerException); EventViewerLoggerSVC.LogError("PushDepositNotification: " + ex.Message); } return(operationResult); }
public async Task <NotificationResultEN> CreateMassiveCampaignAndroidRGO(CampaignEN pCampaignContent) { NotificationResultEN operationResult = new NotificationResultEN(); operationResult.Platform = "ANDROID"; operationResult.Result = false; operationResult.ServiceName = "OneSignal"; try { HttpClient client = new HttpClient(); client.BaseAddress = new Uri(Constants.OneSignalURL); client.DefaultRequestHeaders.Add("authorization", "Basic " + Constants.KEY_ONESIGNAL_RGO_ANDROID); //antes era OneSignalKey_Android_Yvr //TODO: REcomendacion: Cambiar nombre a RG! string url = string.Format("/api/v1/notifications"); OneSignalFilter filter = new OneSignalFilter(); if (RecarGOMassiveTestModeActive()) { filter.field = "tag"; filter.key = "userid"; filter.relation = "="; filter.value = ConfigurationManager.AppSettings["OneSignal_SingleUserTest_RGO_Android"].ToString(); } else { filter.field = "country"; filter.value = pCampaignContent.CountryISO2Code; } var notificationContent = new { app_id = Constants.APPID_ONESIGNAL_RGO_ANDROID, headings = new { en = pCampaignContent.NotificationTitle }, contents = new { en = pCampaignContent.NotificationMessage }, big_picture = (pCampaignContent.ImageURL != null) ? pCampaignContent.ImageURL : null, category = "", collapse_id = "", filters = new object[] { filter } }; var jsonPost = JsonConvert.SerializeObject(notificationContent); StringContent _content = new StringContent(jsonPost, Encoding.UTF8, "application/json"); var response = await client.PostAsync(url, _content); if (response.IsSuccessStatusCode) { var result = response.Content.ReadAsStringAsync().Result; var notificationResult = JsonConvert.DeserializeObject <CreateResultOneSignal>(result); if (notificationResult.errors == null) { operationResult.CodeResult = "scheduled"; operationResult.Result = true; } } } catch (Exception ex) { Console.WriteLine(ex.InnerException); EventViewerLoggerSVC.LogError("CreateMassiveCampaign: " + ex.Message); } return(operationResult); }
public async Task <NotificationResultEN> CreateMassiveCampaignIOs(CampaignEN pCampaignContent) { NotificationResultEN operationResult = new NotificationResultEN(); operationResult.Platform = "IOS"; operationResult.Result = false; operationResult.ServiceName = "OneSignal"; try { HttpClient client = new HttpClient(); client.BaseAddress = new Uri(Constants.OneSignalURL); client.DefaultRequestHeaders.Add("authorization", "Basic " + Constants.KEY_ONESIGNAL_YVR_IOS); string url = string.Format("/api/v1/notifications"); #region Target Filter OneSignalFilter filter = new OneSignalFilter(); if (MassiveTestModeActive()) { filter.field = "tag"; filter.key = "userid"; filter.relation = "="; filter.value = ConfigurationManager.AppSettings["OneSignal_SingleUserTest"].ToString(); } else { filter.field = "country"; filter.value = pCampaignContent.CountryISO2Code; } #endregion var attachment = new { id = (pCampaignContent.ImageURL != null) ? pCampaignContent.ImageURL : null }; var notificationContent = new { app_id = Constants.APPID_ONESIGNAL_YVR_IOS, headings = new { en = pCampaignContent.NotificationTitle }, contents = new { en = pCampaignContent.NotificationMessage }, content_available = true, ios_badgeType = "Increase", ios_badgeCount = 1, category = "", collapse_id = "", ios_attachments = (pCampaignContent.ImageURL != null) ? attachment : null, filters = new object[] { filter } }; var jsonPost = JsonConvert.SerializeObject(notificationContent); StringContent _content = new StringContent(jsonPost, Encoding.UTF8, "application/json"); var response = await client.PostAsync(url, _content); if (response.IsSuccessStatusCode) { var result = response.Content.ReadAsStringAsync().Result; var notificationResult = JsonConvert.DeserializeObject <CreateResultOneSignal>(result); if (notificationResult.errors == null) { operationResult.CodeResult = "scheduled"; operationResult.Result = true; } } } catch (Exception ex) { Console.WriteLine(ex.InnerException); EventViewerLoggerSVC.LogError("CreateMassiveCampaign: " + ex.Message); } return(operationResult); }