public async Task SendPushNotification(List <NotificationOrderDto> orderDetails) { var expoSDKClient = new PushApiClient(); var tickets = orderDetails.Select(x => new PushTicketRequest { PushTitle = x.Title, PushTo = new List <string> { x.Token }, PushBody = $"{ x.OrderDetail.Qty} - {(x.OrderDetail.Combo != null ? x.OrderDetail.Combo.Name : x.OrderDetail.Dish.Name) }", PushPriority = "high" }).ToList(); var errors = new List <PushTicketResponse>(); tickets.ForEach(async x => { var result = await expoSDKClient.PushSendAsync(x); errors.Add(result); }); errors.ForEach(x => { if (x?.PushTicketErrors?.Count() > 0) { foreach (var error in x.PushTicketErrors) { Console.WriteLine($"Error: {error.ErrorCode} - {error.ErrorMessage}"); } } }); }
public void TestPushReceiptRequest() { var expoSDKClient = new PushApiClient(); var pushReceiptReq = new PushReceiptRequest() { PushTicketIds = new List <string>() { "..." } }; var result = expoSDKClient.PushGetReceiptsAsync(pushReceiptReq).GetAwaiter().GetResult(); if (result?.ErrorInformations?.Count() > 0) { foreach (var error in result.ErrorInformations) { Console.WriteLine($"Error: {error.ErrorCode} - {error.ErrorMessage}"); } } foreach (var pushReceipt in result.PushTicketReceipts) { Console.WriteLine($"TicketId & Delivery Status: {pushReceipt.Key} {pushReceipt.Value.DeliveryStatus} {pushReceipt.Value.DeliveryMessage}"); } Assert.Pass(); }
public virtual async Task <IActionResult> SendNotification(PushNotificationModel model) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageCustomers)) { return(AccessDeniedView()); } IPagedList <Customer> notificationCustomers = await _customerService.GetAllPushNotificationCustomersAsync(sendToAll : true); foreach (var customer in notificationCustomers) { if (!string.IsNullOrEmpty(customer.PushToken)) { var expoSDKClient = new PushApiClient(); var pushTicketReq = new PushTicketRequest() { PushTo = new List <string>() { customer.PushToken }, PushTitle = model.MessageTitle, PushBody = model.MessageBody }; var result = await expoSDKClient.PushSendAsync(pushTicketReq); } } //prepare model model = new PushNotificationModel(); //if we got this far, something failed, redisplay form return(View(model)); }
public async Task <IActionResult> CancelOrder(int id) { var order = await _orderService.GetOrderByIdAsync(id); if (order == null) { return(Ok(new { success = false, message = await _localizationService.GetResourceAsync("Order.Cancelled.Failed") })); } //try to get an customer with the order id var customer = await _customerService.GetCustomerByIdAsync(order.CustomerId); if (customer == null) { return(Ok(new { success = false, message = await _localizationService.GetResourceAsync("customer.NotFound") })); } await _orderProcessingService.CancelOrderAsync(order, true); await LogEditOrderAsync(order.Id); if (customer.OrderStatusNotification) { var expoSDKClient = new PushApiClient(); var pushTicketReq = new PushTicketRequest() { PushTo = new List <string>() { customer.PushToken }, PushTitle = await _localizationService.GetResourceAsync("PushNotification.OrderCancelTitle"), PushBody = await _localizationService.GetResourceAsync("PushNotification.OrderCancelBody") }; var result = await expoSDKClient.PushSendAsync(pushTicketReq); } return(Ok(new { success = true, message = await _localizationService.GetResourceAsync("Order.Cancelled.Successfully") })); }
private static void SendPush(string expoPushToken, string innerText) { var expoSDKClient = new PushApiClient(); var pushTicketReq = new PushTicketRequest() { PushTo = new List <string>() { expoPushToken }, //PushBadgeCount = 7, PushTitle = "Playable map detected", PushBody = "cs_italy: " + innerText }; var result = expoSDKClient.PushSendAsync(pushTicketReq).GetAwaiter().GetResult(); if (result?.PushTicketErrors?.Count() > 0) { foreach (var error in result.PushTicketErrors) { Console.WriteLine($"Error: {error.ErrorCode} - {error.ErrorMessage}"); } } }
static void Main(string[] args) { //instanciamos la clase que contiene los metodos para enviar la notificación var expoSDKClient = new PushApiClient(); //instanciamos el modelo que contendra la información var pushTicketReq = new PushTicketRequest() { PushTo = new List <string> { "{YOU_EXPO_TOKEN}" }, PushBadgeCount = 7, PushBody = "HI I AM A GREAT DEVELOPER!", }; /* * -creamos una variable con el resultado para luego verificar si ocurrió algún error * -llamamos al metodo PushSendAsync le pasamos el modelo PushTicketRequest el cual devuelve * un taskAwaiter por eso el metodo .GetAwaited() y luego llamamos getResult() * (ESTO ES UN METODO ASYNCRONO) * */ var result = expoSDKClient.PushSendAsync(pushTicketReq).GetAwaiter().GetResult(); //verificamos si hay errores if (result?.PushTicketErrors?.Count > 0) { foreach (var error in result.PushTicketErrors) { Console.WriteLine($"Error: {error.ErrorCode} - {error.ErrorMessage}"); } } Console.WriteLine("Hello World!"); Console.ReadKey(); }