Example #1
0
        public override SendMessageResponse SendMessage(SendMessageRequest request)
        {
            try
            {
                //Send Request to Clickatell service with SendMessageURL, phone numbers and message
                var response = SendRequest(Properties.HTTPSettings.Default.SendMessageURL, phoneNumbers: request.PhoneNumbers, message: request.Message);

                //Extract messages objects from string response
                var messages = GetMessagesFromResponse(response, request.PhoneNumbers).ToArray();

                return new SendMessageResponse
                {
                    Success = true,
                    Result = response,
                    Messages = messages
                };
            }
            catch (Exception exception)
            {
                return new SendMessageResponse
                {
                    Result = string.Format("Error occured during Clickatell {0}. Details: {1}", MethodBase.GetCurrentMethod().Name, exception.Message),
                    Success = false
                };
            }
        }
Example #2
0
        public override SendMessageResponse SendMessage(SendMessageRequest request)
        {
            try
            {
                //Gets the WebRequest with the SendMessageURL and POST method
                var webRequest = GetWebRequest(Properties.RESTSettings.Default.SendMessageURL, Properties.RESTSettings.Default.PostMethod);

                //Creates a JSON object with the message,telephone numbers applied and serialize it to be sent to the Clickatell service
                var postData = JsonSerializer<Data.JSON.REST.MessageRequest.Rootobject>(
                    new Data.JSON.REST.MessageRequest.Rootobject
                    {
                        text = request.Message,
                        to = request.PhoneNumbers
                    });

                //Gets the encoding of the JSON post data created (iso-8859-1)
                var bytes = Encoding.GetEncoding(Properties.RESTSettings.Default.EncodingName).GetBytes(postData);
                webRequest.ContentLength = bytes.Length;

                //Get webRequest Requested stream from encoded bytes
                using (var writeStream = webRequest.GetRequestStream())
                {
                    writeStream.Write(bytes, 0, bytes.Length);
                }

                //Get WebResponse from Clickatell service
                var webResponse = GetWebResponse(webRequest);

                //Deserlialize the webResponse in JSON and maps the results for the Messages response
                var jsonMessages = JsonDeserialize<Data.JSON.REST.MessageResponse.Rootobject>(webResponse.Result).data.message.Select(message => new Message
                    {
                        APIMessageID = message.apiMessageId,
                        To = message.to
                    }).ToArray();

                return new SendMessageResponse
                {
                    Result = webResponse.Result,
                    Success = webResponse.Success,
                    Messages = jsonMessages
                };
            }
            catch (Exception exception)
            {
                return new SendMessageResponse
                {
                    Result = string.Format("Error occured during Clickatell {0}. Details: {1}", MethodBase.GetCurrentMethod().Name, exception.Message),
                    Success = false
                };
            }
        }
 /// <summary>
 /// Sends a message to the phonenumber(s) supplied.
 /// </summary>
 /// <param name="SendMessageRequest"></param>
 /// <returns>
 /// SendMessageResponse:
 /// Success = If call was successfully made to Clickatell
 /// Result  = Service response
 /// Messages[] = Message object which will have the APIMessageID(Guid created for message for reference) and To(The phonenumber)
 /// </returns>
 public abstract SendMessageResponse SendMessage(SendMessageRequest request);