Ejemplo n.º 1
0
        /// <summary>
        /// This API endpoint is used to send a message from one valid phone number to another valid phone number.
        /// All to and from phone numbers must use an E.164 format, which is an 11-digit 1NPANXXXXXX-formatted number in North America.
        /// While you can send an SMS to any valid North American Numbering Plan Administration (NANPA) phone number; Flowroute cannot
        /// guarantee delivery to any phone number not enabled for SMS. Additionally, you are only allowed to send an SMS from an
        /// SMS-enabled phone number set up on the Direct Inward Dialing (DIDS > Manage) page.You cannot send an SMS from a phone
        /// number not on your Flowroute account.
        ///
        /// For more information: https://developer.flowroute.com/docs/messaging
        /// </summary>
        /// <param name="request">An SMS request object.</param>
        public async Task <FlowrouteSendMessageResponse> SendMessageAsync(SmsRequest request)
        {
            using (HttpClient httpClient = new HttpClient())
            {
                SetAuthorization(httpClient);

                var json = JsonConvert.SerializeObject(request);

                HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Post, UrlEndpoint);
                message.Content = new StringContent(json, Encoding.UTF8, "application/json");

                FlowrouteSendMessageResponse responseInternal;
                using (var response = await httpClient.SendAsync(message))
                {
                    var responseString = await response.Content.ReadAsStringAsync();

                    responseInternal = JsonConvert.DeserializeObject <FlowrouteSendMessageResponse>(responseString);

                    responseInternal.Raw     = response;
                    responseInternal.Success = response.IsSuccessStatusCode;

                    if (!response.IsSuccessStatusCode)
                    {
                        responseInternal.Errors = responseInternal.Errors;
                    }
                }

                return(responseInternal);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This API endpoint is used to send a message from one valid phone number to another valid phone number.
        /// All to and from phone numbers must use an E.164 format, which is an 11-digit 1NPANXXXXXX-formatted number in North America.
        /// While you can send an SMS to any valid North American Numbering Plan Administration (NANPA) phone number; Flowroute cannot
        /// guarantee delivery to any phone number not enabled for SMS. Additionally, you are only allowed to send an SMS from an
        /// SMS-enabled phone number set up on the Direct Inward Dialing (DIDS > Manage) page.You cannot send an SMS from a phone
        /// number not on your Flowroute account.
        ///
        /// For more information: https://developer.flowroute.com/docs/messaging
        /// </summary>
        /// <param name="toPhoneNumber">Phone number of the message recipient, using an E.164 format, This must be in an E.164 format,
        /// which is a North American, 11-digit 1NPANXXXXXX-formatted number.</param>
        /// <param name="fromPhoneNumber">Flowroute phone number to send the message from, using an E.164 format. On the receiver's phone,
        /// this is typically referred to as the Caller ID.</param>
        /// <param name="body">The content of the message to deliver. If a message is greater than 160 characters, and the carrier sends
        /// header information with the message, the message with be reassembled on the receiver's phone as one message. If header
        /// information is not sent by the carrier, the message will be received in multiple parts.</param>
        public async Task <FlowrouteSendMessageResponse> SendMessageAsync(string toPhoneNumber, string fromPhoneNumber, string body)
        {
            if (string.IsNullOrWhiteSpace(toPhoneNumber))
            {
                throw new ArgumentOutOfRangeException(nameof(toPhoneNumber), "To phone number cannot be empty.");
            }
            if (string.IsNullOrWhiteSpace(fromPhoneNumber))
            {
                throw new ArgumentOutOfRangeException(nameof(fromPhoneNumber), "From phone number cannot be empty.");
            }
            if (string.IsNullOrWhiteSpace(body))
            {
                throw new ArgumentOutOfRangeException(nameof(body), "Body cannot be empty.");
            }

            var smsRequest = new SmsRequest()
            {
                ToPhoneNumber   = toPhoneNumber,
                FromPhoneNumber = fromPhoneNumber,
                Body            = body
            };

            return(await SendMessageAsync(smsRequest));
        }