public async Task <MessengerResponse> SendAsync(MessengerMessage message, MessengerUser recipient, String accessToken)
        {
            var url     = String.Format(UrlTemplate, accessToken);
            var request = new MessengerSendMessageRequest {
                Recipient = recipient, Message = message
            };

            var content = new StringContent(serializer.Serialize(request));

            content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            try
            {
                var response = await client.PostAsync(url, content);

                var result = new MessengerResponse
                {
                    Succeed     = response.IsSuccessStatusCode,
                    RawResponse = await response.Content.ReadAsStringAsync()
                };

                return(result);
            }
            catch (Exception exc)
            {
                throw new MessengerException(exc);
            }
        }
예제 #2
0
        public async Task <MessengerResponse> SendAsync(MessengerMessage message, MessengerUser recipient, String accessToken)
        {
            var url     = String.Format(UrlTemplate, accessToken);
            var request = new MessengerSendMessageRequest {
                Recipient = recipient, Message = message
            };
            var strings = serializer.Serialize(request);

#if DEBUG
            System.Console.WriteLine(strings);
#endif

            /*if (message.Attachments != null && message.Attachments.Count > 0)
             *  throw new Exception(strings);*/

            var content = new StringContent(strings);

            content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            try
            {
                var response = await client.PostAsync(url, content);

                var result = new MessengerResponse
                {
                    Succeed     = response.IsSuccessStatusCode,
                    RawResponse = await response.Content.ReadAsStringAsync()
                };

                return(result);
            }
            catch (Exception exc)
            {
                throw new MessengerException(exc);
            }
        }
예제 #3
0
        public Task <MessengerResponse> SendAsync(MessengerMessage message, MessengerUser recipient, String accessToken)
        {
            var request = new MessengerSendMessageRequest {
                Recipient = recipient, Message = message
            };

            return(SendMessage(request, accessToken));
        }