Пример #1
0
        /// <summary>
        /// Register a notifier to
        /// </summary>
        /// <param name="accountSid"></param>
        /// <param name="authToken"></param>
        /// <param name="receivingNumber"></param>
        /// <param name="notifierId"></param>
        public virtual void RegisterUrlForIncomingSms(string accountSid, string authToken, string receivingNumber, long notifierId)
        {
            var uri = _receiver.GetIncommingUrl(notifierId);

            var phoneOptions = new PhoneNumberOptions
            {
                SmsUrl    = uri,
                SmsMethod = "GET"
            };

            HandleUrlForIncomingSms(accountSid, authToken, receivingNumber, phoneOptions);
        }
Пример #2
0
        /// <summary>
        /// Send a message syncronously
        /// </summary>
        /// <returns>The messages</returns>
        public IEnumerable <SendResponse> SendMessageSync(long notifierId, string sendingNumber, string message, IEnumerable <string> numbers)
        {
            var cleanFailNumber = PhoneNumberHelper.CleanNumber(FailNumber);
            var statusUrl       = _receiver.GetStatusUpdateUrl(notifierId);
            var incommingUrl    = _receiver.GetIncommingUrl(_notifier.Id);

            var reply = $"Reply:{message}";

            var result = new List <SendResponse>();

            foreach (var number in numbers)
            {
                //TODO: Emulate status updating

                bool isFailNumber = number == cleanFailNumber;

                var messageSid = Guid.NewGuid().ToString();

                if (!isFailNumber)
                {
                    var twilioSms = new TwilioSms
                    {
                        MessageSid = messageSid,
                        AccountSid = _notifier.TpAccountSid,
                        From       = PhoneNumberHelper.CleanNumber(number),
                        To         = PhoneNumberHelper.CleanNumber(sendingNumber),
                        Body       = $"TestMode:Reply:{ResponseFromNumber(number)}"
                    };

                    _replies.Add(twilioSms);
                }

                var sendResponse = new SendResponse
                {
                    Number     = number,
                    MessageSid = messageSid,
                    Success    = !isFailNumber,
                    Message    = isFailNumber ? FailMessage : null
                };

                result.Add(sendResponse);
            }

            return(result);
        }