示例#1
0
        /// <summary>
        /// Send messages to users.
        /// </summary>
        /// <param name="userId">User identification</param>
        /// <param name="message">Message object</param>
        /// <param name="notificationType">Push notification type: REGULAR, SILENT_PUSH, NO_PUSH</param>
        /// <returns></returns>
        public async Task <MessageResult> SendMessageAsync(string userId, MessageSent message, NotificationType notificationType = NotificationType.Regular)
        {
            var result = new MessageResult();

            try
            {
                var returnValue = (JObject) await PostTaskAsync("me/messages", new
                {
                    recipient = new
                    {
                        id = userId
                    },
                    notification_type = notificationType.GetJsonPropertyName(),
                    message           = message
                });

                result.Error = CreateResultError(returnValue);
                if (result.Error == null)
                {
                    result.RecipientId = returnValue.Value <string>("recipient_id");
                    result.MessageId   = returnValue.Value <string>("message_id");
                    result.Success     = true;
                }
            }
            catch (Exception ex)
            {
                HandleException(ex, result);
            }

            return(result);
        }
示例#2
0
        /// <summary>
        /// Gets the json rendered asynchronous.
        /// </summary>
        /// <param name="userId">The user identifier.</param>
        /// <param name="message">The message.</param>
        /// <param name="notificationType">Type of the notification.</param>
        /// <param name="messageType">Type of the message.</param>
        /// <param name="messageTag">The message tag.</param>
        /// <returns></returns>
        public Task <string> GetJSONRenderedAsync(string userId, MessageSent message,
                                                  NotificationType notificationType = NotificationType.Regular,
                                                  MessageType?messageType           = null,
                                                  MessageTag?messageTag             = null)
        {
            var package = new
            {
                recipient = new
                {
                    id = userId
                },
                tag               = messageTag?.GetJsonPropertyName(),
                messaging_type    = messageType?.GetJsonPropertyName(),
                notification_type = notificationType.GetJsonPropertyName(),
                message
            };

            var result = JsonConvert.SerializeObject(package, Formatting.Indented);

            return(Task.FromResult(result));
        }