示例#1
0
        public async Task <OneSignalNotificationResponse> PushNotification(List <string> playerIds, string message)
        {
            if (!playerIds.Any())
            {
                return(null);
            }
            var id = await _appConfig.Get(ConfigurationTypes.Notification);

            var request = new Request(string.Empty, ApiUrl, HttpMethod.Post);

            var body = new OneSignalNotificationBody
            {
                app_id   = id.Value,
                contents = new Contents
                {
                    en = message
                },
                include_player_ids = playerIds.ToArray()
            };

            request.AddJsonBody(body);

            var result = await _api.Request <OneSignalNotificationResponse>(request);

            return(result);
        }
示例#2
0
        public async Task <OneSignalNotificationResponse> PushNotification(List <string> playerIds, string message, bool isAdminNotification, int requestId, int requestType)
        {
            if (!playerIds.Any())
            {
                return(null);
            }
            var id = await _appConfig.GetAsync(ConfigurationTypes.Notification);

            var request = new Request(string.Empty, ApiUrl, HttpMethod.Post);

            var body = new OneSignalNotificationBody
            {
                app_id   = id.Value,
                contents = new Contents
                {
                    en = message
                },
                include_player_ids = playerIds.ToArray()
            };

            if (isAdminNotification)
            {
                // Add the action buttons
                body.data    = new { requestid = requestId, requestType = requestType };
                body.buttons = new[]
                {
                    new Button {
                        id = "approve", text = "Approve Request"
                    },
                    new Button {
                        id = "deny", text = "Deny Request"
                    },
                };
            }

            request.AddJsonBody(body);

            var result = await _api.Request <OneSignalNotificationResponse>(request);

            return(result);
        }