public async Task <NotificationResultEN> PushTopupRequest(string pPersonEmail, string pRequester, string pAmount) { NotificationResultEN operationResult = new NotificationResultEN(); operationResult.Platform = "ANDROID"; operationResult.Result = false; operationResult.ServiceName = "Engagement"; try { var credentials = await ApplicationTokenProvider.LoginSilentAsync(Constants.TENANT_ID, Constants.CLIENT_ID, Constants.CLIENT_SECRET); engagementClient = new EngagementManagementClient(credentials) { SubscriptionId = Constants.SUBSCRIPTION_ID }; engagementClient.ResourceGroupName = Constants.RESOURCE_GROUP; engagementClient.AppCollection = Constants.APP_COLLECTION_NAME; engagementClient.AppName = Constants.APP_RESOURCE_NAME_ANDROID; Device userDevice = await engagementClient.Devices.GetByUserIdAsync(pPersonEmail); Campaign campaign = new Campaign(); campaign.Type = "only_notif"; campaign.DeliveryTime = "any"; campaign.PushMode = "manual"; campaign.NotificationType = "system"; campaign.NotificationCloseable = true; campaign.NotificationTitle = "¡Nueva solicitud de recarga!"; campaign.NotificationMessage = "Hola ${userFirstName}, el número: " + pRequester + " te ha pedido una recarga de " + pAmount + ". Revisa el listado de solicitudes de recarga."; List <string> devices = new List <string>(); devices.Add(userDevice.DeviceId); CampaignPushParameters parameters = new CampaignPushParameters(devices, campaign); CampaignPushResult pushResult = await engagementClient.Campaigns.PushAsync(CampaignKinds.Announcements, Constants.TopupRequestCampaign, parameters); if (pushResult.InvalidDeviceIds.Count <= 0) { //Success operationResult.CodeResult = "Success"; operationResult.Result = true; } } catch (ApiErrorException apiEx) { if (String.Equals(apiEx.Body.Error.Code, "Conflict")) { operationResult.CodeResult = "conflict"; } } catch (Exception ex) { Console.WriteLine(ex.InnerException); } return(operationResult); }
public async Task <NotificationResultEN> PushDepositNotification(CampaignEN pCampaign, string pUserEmail, string pFirstName, string pContent) { NotificationResultEN operationResult = new NotificationResultEN(); operationResult.Platform = "ANDROID"; operationResult.Result = false; operationResult.ServiceName = "Engagement"; int campaignID = Constants.DepositConfCampaign; try { var credentials = await ApplicationTokenProvider.LoginSilentAsync(Constants.TENANT_ID, Constants.CLIENT_ID, Constants.CLIENT_SECRET); engagementClient = new EngagementManagementClient(credentials) { SubscriptionId = Constants.SUBSCRIPTION_ID }; engagementClient.ResourceGroupName = Constants.RESOURCE_GROUP; engagementClient.AppCollection = Constants.APP_COLLECTION_NAME; engagementClient.AppName = Constants.APP_RESOURCE_NAME_ANDROID; string userIdentifier = (!YVRSingleTestModeActive()) ? pUserEmail : ConfigurationManager.AppSettings["Engagement_SingleUserTest"].ToString(); Device userDevice = await engagementClient.Devices.GetByUserIdAsync(userIdentifier); Campaign campaign = new Campaign(); campaign.Type = "text/plain"; campaign.DeliveryTime = "any"; campaign.PushMode = "manual"; campaign.NotificationType = "system"; campaign.NotificationCloseable = true; campaign.NotificationTitle = pCampaign.NotificationTitle; campaign.NotificationMessage = String.Format("Hola {0}, tu deposito fue validado de forma exitosa, haz click aquí para más detalles.", pFirstName); campaign.Title = pCampaign.Title; campaign.Body = pContent; campaign.ActionButtonText = "ACEPTAR"; List <string> devices = new List <string>(); devices.Add(userDevice.DeviceId); CampaignPushParameters parameters = new CampaignPushParameters(devices, campaign); CampaignPushResult pushResult = await engagementClient.Campaigns.PushAsync(CampaignKinds.Announcements, campaignID, parameters); if (pushResult.InvalidDeviceIds.Count <= 0) { //Success operationResult.Result = true; } } catch (ApiErrorException apiEx) { if (String.Equals(apiEx.Body.Error.Code, "Conflict")) { operationResult.CodeResult = "conflict"; } } catch (Exception ex) { Console.WriteLine(ex.InnerException); } return(operationResult); }