Beispiel #1
0
        public override VoipCall RedirectCall(string callId, string to)
        {
            var call = CallResource.Update(callId, url: new System.Uri(Settings.Redirect(to)), method: HttpMethod.Post, client: twilio);

            return(new VoipCall {
                Id = call.Sid, To = to
            });
        }
        //internal static void ApplyContextMessageSettings(CreateCallOptions messageOptions, TwilioSmsContext context)
        //{

        //    if (messageOptions.From == null)
        //    {
        //        messageOptions.From = new PhoneNumber(context.From);
        //    }

        //    //if (messageOptions.Body == null)
        //    //{
        //    //    messageOptions.Body = context.Body;
        //    //}
        //}

        public async Task FlushAsync(CancellationToken cancellationToken = default(CancellationToken))
        {
            while (_messages.TryDequeue(out CreateCallOptions message))
            {
                // this create will initiate the send operation
                await CallResource.CreateAsync(message, client : _context);
            }
        }
        public async Task <object> Call(string to)
        {
            var receiver = new PhoneNumber(to);
            var from     = new PhoneNumber(_configuration["Twilio:Sender"]);

            var call = CallResource.Create(receiver, from, url: new Uri("https://jet-echidna-4440.twil.io/assets/CallVerefication.xml"));

            return(call);
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            TwilioClient.Init("username", "password");
            TwilioClient.SetRestClient(new TwilioEmulatorRestClient(TwilioClient.GetRestClient(), new Uri("http://localhost:5000")));

            var call = CallResource.Create(new PhoneNumber("12345"), new PhoneNumber("34567"));

            Console.WriteLine("Hello World!");
        }
        public static void Main(List <string> names, List <string> nums)
        {
            int    listSize = nums.Count();
            Random rand     = new Random();
            int    randNum  = rand.Next(listSize);

            string        num       = nums[randNum];
            string        name      = names[randNum];
            const string  twilNum   = "+12056240471";
            List <string> word_bank = new List <string>()
            {
                "elephant", "guacamole", "soda", "coin", "hammer"
            };
            List <string> xml_bank = new List <string>()
            {
                "https://handler.twilio.com/twiml/EH7933e9ec81efd66931b477ee8c1b7c6c",
                "https://handler.twilio.com/twiml/EH1c38aeaa6210f3332442c09b398ac5cf",
                "https://handler.twilio.com/twiml/EH7a4c002c14c5741423a6dff504468f65",
                "https://handler.twilio.com/twiml/EH1e9f812891e16cd258bc3dfac04162f2",
                "https://handler.twilio.com/twiml/EHd7621e90eea9b0faf1faef3ec8fa2ddf"
            };

            int    randWordIndex = rand.Next(word_bank.Count());
            string word          = word_bank[randWordIndex];
            string call_url      = xml_bank[randWordIndex];


            const string accountSid = "AC6a821cb13063fc23e74bf10b09e6db00";
            const string authToken  = "21d420efd82e5e087c72cb0c24ddf784";

            TwilioClient.Init(accountSid, authToken);

            var to   = new PhoneNumber("+1" + num);
            var from = new PhoneNumber(twilNum);
            var call = CallResource.Create(to, from, url: new Uri(call_url));

            int randNum2 = rand.Next(listSize);

            while (randNum2 == randNum)
            {
                randNum2 = rand.Next(listSize);
            }

            string num2        = nums[randNum2];
            string name2       = names[randNum2];
            string spy_message = "People at the scene saw you use your " + word + ". Let NOBODY know.";

            var message = MessageResource.Create(
                body: spy_message,
                from: new Twilio.Types.PhoneNumber(twilNum),
                to: new Twilio.Types.PhoneNumber("+1" + num2)
                );

            Console.WriteLine(call.Sid);
            Console.WriteLine(message.Sid);
        }
Beispiel #6
0
 public IActionResult OutboundCall(string to)
 {
     CallResource.Create(
         method: HttpMethod.Get,
         url: new Uri($"{_directlineConfig.Host}/api/voice/receive"),
         to: new Twilio.Types.PhoneNumber(to),
         from: new Twilio.Types.PhoneNumber(_twilioAppConfig.TwilioPhoneNumber)
         );
     return(Ok());
 }
Beispiel #7
0
        public void Call()
        {
            TwilioClient.Init(_acc.AccountSid, _acc.AuthToken);
            var ngrokport  = "";
            var fromNumber = "";
            var toNumber   = new PhoneNumber("");

            CallResource.Create(to: toNumber, from: fromNumber,
                                url: new Uri($"http://{ngrokport}.ngrok.io/voice"));
        }
Beispiel #8
0
    static void Main(string[] args)
    {
        // Find your Account Sid and Token at twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken  = "your_auth_token";

        TwilioClient.Init(accountSid, authToken);

        CallResource.Delete(pathSid: "CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
    }
        public void call()
        {
            string AccountSid = "ACc4455ec9d784ae580638ecac36ad7fea";
            string AuthToken  = "ACc4455ec9d784ae580638ecac36ad7fea";
            var    twilio     = new TwilioRestClient(AccountSid, AuthToken);

            CallResource.Create(
                from: new PhoneNumber("14054000298"),
                to: new PhoneNumber("14059191824"),
                url: new Uri("~/Twilio/TwillioXML/PickUp.xml"));
        }
Beispiel #10
0
        private static async Task <bool> HasChildren(CallResource call, TwilioRestClient client)
        {
            if (!string.IsNullOrEmpty(call.ParentCallSid))
            {
                throw new ArgumentException($"Child call {call.Sid} isn't expected.");
            }

            var children = await CallResource.ReadAsync(new ReadCallOptions { ParentCallSid = call.Sid }, client);

            return(children.Any());
        }
Beispiel #11
0
    static void Main(string[] args)
    {
        // Find your Account Sid and Token at twilio.com/console
        // DANGER! This is insecure. See http://twil.io/secure
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken  = "your_auth_token";

        TwilioClient.Init(accountSid, authToken);

        CallResource.Delete(pathSid: "CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
    }
    static void Main(string[] args)
    {
        // Find your Account Sid and Auth Token at twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken  = "your_auth_token";

        TwilioClient.Init(accountSid, authToken);

        CallResource.Update("CAe1644a7eed5088b159577c5802d8be38",
                            status: CallResource.UpdateStatusEnum.Completed);
    }
Beispiel #13
0
    ///<inheritdoc/>
    public async Task SendVoiceAsync(string number, string callbackUrl)
    {
        _logger.LogInformation("> Voice Sending => {Number}, {CallbackUrl}", number, callbackUrl);

        var to   = new PhoneNumber(number);
        var from = new PhoneNumber(_settings.From);

        var call = await CallResource.CreateAsync(to, from, url : new Uri(callbackUrl), client : _twilio).ConfigureAwait(false);

        _logger.LogInformation(">> Voice Sent => {Number}, {CallbackUrl}, {Sid}", number, callbackUrl, call?.Sid);
    }
Beispiel #14
0
        public IActionResult Call(string to)
        {
            var toPhoneNumber = new PhoneNumber(to);
            var message       = CallResource.Create(
                url: new Uri("http://demo.twilio.com/docs/voice.xml"),
                from: _fromPhoneNumber,
                to: toPhoneNumber
                );

            return(Content("Call inbound!"));
        }
Beispiel #15
0
        /// <summary>
        /// Calls the specified phone number with the starting TwiML message script found at the relative url.
        /// Note that the relative url cannot contain characters that are url-encoded like spaces (Twilio Api throws an invalid url exception, even if the url is valid.
        /// Ideally query parameters in the relativeUrl should be simple, like a record's unique id.
        /// </summary>
        /// <param name="toNumber">phone number to open a phone call to. Standard rates apply.</param>
        /// <param name="relativeUrl">Relative url to the page that generates the TwiML for this message's contents, i.e. "MyController/TwilioCall?param=3".</param>
        public static CallResource SendVoiceMessage(string toNumber, string relativeUrl)
        {
            TwilioClient.Init(TwilioAccountSid, TwilioAuthToken);

            var          phoneResource = GetVoicePhoneResource();
            CallResource call          = CallResource.Create(to: new PhoneNumber(toNumber),
                                                             from: phoneResource.PhoneNumber,
                                                             url: new Uri(ExternalUrl + relativeUrl));

            return(call);
        }
Beispiel #16
0
        public CallResource MakePhoneCallAsync(Call call)
        {
            return(CallResource.Create(
                       statusCallback: new Uri(Auth.UrlPath + "/api/event/"),
                       statusCallbackEvent: new List <string>(new string[] { "initiated", "ringing", "answered", "completed" }),
                       statusCallbackMethod: Twilio.Http.HttpMethod.Post,

                       to: new PhoneNumber(call.ProNumber),
                       from: new PhoneNumber(Auth.Number),
                       url: new Uri(Auth.UrlPath + "/api/dtm/"),
                       client: _client));
        }
        public static string MakeCall([ActivityTrigger] CallInfo callInfo,
                                      [Table("MadeCalls", "AzureWebJobStorage")] out CallDetails calldetails,
                                      ILogger log)
        {
            log.LogWarning($"MakeCall {callInfo.Numbers}");

            var madeCallId = Guid.NewGuid().ToString("N");

            calldetails = new CallDetails
            {
                PartitionKey    = "MadeCalls",
                RowKey          = madeCallId,
                OrchestrationId = callInfo.InstanceId
            };

            string accountSid = Environment.GetEnvironmentVariable("accountSid");
            string authToken  = Environment.GetEnvironmentVariable("authToken");

            TwilioClient.Init(accountSid, authToken);

            // ***********************************************************************************************************
            //TODO figure out how best to call this and loop thru the numbers instead of hardcoding the first number below
            // ***********************************************************************************************************

            var to = new PhoneNumber(callInfo.Numbers[0]);
            //var to = new PhoneNumber(callInfo.NumberCalled);

            var from = new PhoneNumber(Environment.GetEnvironmentVariable("twilioDemoNumber"));

            log.LogWarning($"InstanceId {callInfo.InstanceId}");

            //var statusCallbackUri = new Uri(string.Format(Environment.GetEnvironmentVariable("statusCallBackUrl"), madeCallId));
            var statusCallbackUri = new Uri(string.Format(Environment.GetEnvironmentVariable("statusCallBackUrl"), callInfo.InstanceId));

            log.LogWarning($"statusCallbackUri {statusCallbackUri}");

            var statusCallbackEvent = new List <string> {
                "answered"
            };

            log.LogWarning($"About to make a call to  {to} from {from}.");


            var call = CallResource.Create(
                to,
                from,
                url: new Uri("http://demo.twilio.com/docs/voice.xml"),
                statusCallback: statusCallbackUri,
                statusCallbackMethod: Twilio.Http.HttpMethod.Post,
                statusCallbackEvent: statusCallbackEvent);

            return(madeCallId);
        }
Beispiel #18
0
        public Task <CallResource> CreateCall(string from, string to)
        {
//            to = $"sip:{to}@cust216.auth.bandwidth.com:5012;transport=udp?X-account-id=13264&X-account-token=cfa55a3c3f138b087a640d5b81aa2d978e8f3a1a";
            return(CallResource.CreateAsync(new CreateCallOptions(new PhoneNumber(to), new PhoneNumber(from))
            {
                Method = HttpMethod.Post,
                Record = false,
                Url = new Uri("https://handler.twilio.com/twiml/EHecfe97c89ec5667fd441c57d88a16f25"),
//                SipAuthUsername = "******",
//                SipAuthPassword = "******",
            }, client));
        }
    static void Main(string[] args)
    {
        // Find your Account Sid and Auth Token at twilio.com/console
        // To set up environmental variables, see http://twil.io/secure
        const string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
        const string authToken  = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");

        TwilioClient.Init(accountSid, authToken);

        CallResource.Update("CAe1644a7eed5088b159577c5802d8be38",
                            status: CallResource.UpdateStatusEnum.Completed);
    }
Beispiel #20
0
    static void Main(string[] args)
    {
        // Find your Account Sid and Token at twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken  = "your_auth_token";

        TwilioClient.Init(accountSid, authToken);

        var call = CallResource.Fetch(pathSid: "CA42ed11f93dc08b952027ffbc406d0868");

        Console.WriteLine(call.To);
    }
Beispiel #21
0
        private void button1_Click(object sender, EventArgs e)
        {
            lvLog.Items.Add("Dialing " + tbPhoneNumber.Text);

            var call = CallResource.Create(
                twiml: new Twilio.Types.Twiml("<Response><Dial><Client>+12562578050</Client></Dial></Response>"),
                to: new Twilio.Types.PhoneNumber(tbPhoneNumber.Text),
                from: new Twilio.Types.PhoneNumber("+12562578050")
                );

            lvLog.Items.Add("Call Sid " + call.Sid);
        }
        public void CommunicateCall(string phoneNumber, UserProfile profile, Call call)
        {
            if (profile == null)
            {
                return;
            }

            TwilioClient.Init(Config.NumberProviderConfig.TwilioAccountSid, Config.NumberProviderConfig.TwilioAuthToken);

            if (!profile.VoiceForCall)
            {
                return;
            }

            string number = phoneNumber;

            if (String.IsNullOrWhiteSpace(number) || NumberHelper.IsNexmoNumber(number))
            {
                number = Config.NumberProviderConfig.TwilioResgridNumber;
            }

            if (number.Length == 11 && number[0] != Char.Parse("1"))
            {
                number = "+" + number;
            }

            if (profile.VoiceCallMobile)
            {
                if (!String.IsNullOrWhiteSpace(profile.GetPhoneNumber()))
                {
                    var options = new CreateCallOptions(new PhoneNumber(profile.GetPhoneNumber()), new PhoneNumber(number));
                    options.Url       = new Uri(string.Format(Config.NumberProviderConfig.TwilioVoiceCallApiTurl, profile.UserId, call.CallId));
                    options.Method    = "GET";
                    options.IfMachine = "Continue";

                    var phoneCall = CallResource.Create(options);
                }
            }

            if (profile.VoiceCallHome)
            {
                if (!String.IsNullOrWhiteSpace(profile.GetHomePhoneNumber()))
                {
                    var options = new CreateCallOptions(new PhoneNumber(profile.GetHomePhoneNumber()), new PhoneNumber(number));
                    options.Url       = new Uri(string.Format(Config.NumberProviderConfig.TwilioVoiceCallApiTurl, profile.UserId, call.CallId));
                    options.Method    = "GET";
                    options.IfMachine = "Continue";

                    var phoneCall = CallResource.Create(options);
                }
            }
        }
Beispiel #23
0
        private static string MakeCall(string toPhone)
        {
            string accountSid = configuration["Twillio:AccountSid"];
            string authToken  = configuration["Twillio:AuthToken"];
            string fromPhone  = configuration["Twillio:FromPhone"];

            TwilioClient.Init(accountSid, authToken);

            var to   = new PhoneNumber(toPhone);
            var from = new PhoneNumber(fromPhone);
            var call = CallResource.Create(to, from,
                                           url: new Uri("http://demo.twilio.com/docs/voice.xml"));
        }
Beispiel #24
0
    static void Main(string[] args)
    {
        // Find your Account Sid and Auth Token at twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken  = "your_auth_token";

        TwilioClient.Init(accountSid, authToken);

        CallResource.Update(
            "CAe1644a7eed5088b159577c5802d8be38",
            url: new Uri("http://demo.twilio.com/docs/voice.xml"),
            method: HttpMethod.Post);
    }
    static void Main(string[] args)
    {
        // Find your Account Sid and Auth Token at twilio.com/console
        // To set up environmental variables, see http://twil.io/secure
        const string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
        const string authToken  = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");

        TwilioClient.Init(accountSid, authToken);

        var call = CallResource.Fetch("CA42ed11f93dc08b952027ffbc406d0868");

        Console.WriteLine(call.To);
    }
Beispiel #26
0
        public void Index()
        {
            // Find your Account Sid and Auth Token at twilio.com/console
            string accountSid = "AC143b3bec7037b31ce25589acd8befb8d";
            string authToken  = _configuration.GetValue <string>("TwilioToken");

            TwilioClient.Init(accountSid, authToken);

            var to   = new PhoneNumber(_configuration.GetValue <string>("PhoneNumber:To"));
            var from = new PhoneNumber("+12055574475");
            var call = CallResource.Create(to, from,
                                           url: new Uri("http://demo.twilio.com/docs/voice.xml"));
        }
Beispiel #27
0
            }                                   // queued, ringing, in-progress, canceled, completed, failed, busy, no-answer

            public CallInfo(CallResource CallResource)
            {
                this.SId        = CallResource.Sid;
                this.AccountSId = CallResource.AccountSid;
                this.AnsweredBy = CallResource.AnsweredBy;
                this.CallerName = CallResource.CallerName;
                this.Duration   = CallResource.Duration;
                this.EndTime    = CallResource.EndTime;
                this.StartTime  = CallResource.StartTime;
                this.From       = CallResource.From;
                this.To         = CallResource.To;
                this.Status     = CallResource.Status.ToString();
            }
Beispiel #28
0
        private void Call(string number, string fromNumber)
        {
            // this is NOT done right. Sorry, I've been drinking while coding this.
            if (mc != null)
            {
                if (mc.Status == CallResource.StatusEnum.InProgress)
                {
                    subStatus  = "Call in progess (" + number + ")";
                    callActive = true;
                }
                else if (mc.Status == CallResource.StatusEnum.Ringing)
                {
                    subStatus  = "Call ringing... (" + number + ")";
                    callActive = true;
                }
                else if (mc.Status == CallResource.StatusEnum.Busy)
                {
                    subStatus  = "Number busy (" + number + ")";
                    callActive = false;
                }
                else if (mc.Status == CallResource.StatusEnum.Failed)
                {
                    subStatus  = "Call failed (" + number + ")";
                    callActive = false;
                }
                else if (mc.Status == CallResource.StatusEnum.Completed)
                {
                    callActive = false;
                    mc         = null;
                }
            }
            else
            {
                subStatus = "Calling {" + number + "} from {" + number + "}";
            }
            if (callActive)
            {
                Console.WriteLine("Call still in progress...");
                return;
            }
            Console.WriteLine("Trying to call {" + number + "} from {" + fromNumber + "}");
            Uri _msg = new Uri(String.Format("http://twimlets.com/echo?Twiml=<Response><Say>{0}</Say></Response>", sayMessage.Replace(" ", "+")));

            Console.WriteLine("Call TTS Uri: [" + _msg.ToString() + "]");
            mc = CallResource.Create(
                to: new PhoneNumber(numberToCall),
                from: new PhoneNumber(fromNumber),
                record: recordAudio,
                url: _msg
                );
        }
Beispiel #29
0
        public bool SendNotification(Person to, string message, CommunicationType type)
        {
            var twilioAccountSID  = ConfigurationManager.AppSettings["Twilio_AccountSID"] ?? "AC4e6a4cc549dc577e83ab5ed943b7aa4d";
            var twilioCredentials = ConfigurationManager.AppSettings["Twilio_Credentials"] ?? "c8643b5c95dd80b3e33487ae03d2664e";
            var phoneNumber       = ConfigurationManager.AppSettings["Twilio_PhoneNumber"] ?? "+14388340890";

            try {
                switch (type)
                {
                case CommunicationType.SMS:
                    TwilioClient.Init(twilioAccountSID, twilioCredentials);

                    var messageResource = MessageResource.Create(
                        body: message,
                        from: new Twilio.Types.PhoneNumber(phoneNumber),
                        to: new Twilio.Types.PhoneNumber(to.PhoneNumber)
                        );

                    break;

                case CommunicationType.PhoneCall:
                    TwilioClient.Init(twilioAccountSID, twilioCredentials);

                    var call = CallResource.Create(
                        url: new Uri("http://demo.twilio.com/docs/voice.xml"),
                        to: new Twilio.Types.PhoneNumber(phoneNumber),
                        from: new Twilio.Types.PhoneNumber(to.PhoneNumber)
                        );

                    break;

                case CommunicationType.Email:
                default:
                    var client = new SmtpClient(ConfigurationManager.AppSettings["SmtpIP"] ?? "relais.videotron.ca");

                    var mailMessage = new MailMessage();
                    mailMessage.From = new MailAddress(ConfigurationManager.AppSettings["NotificationFromEmail"] ?? "*****@*****.**");
                    mailMessage.To.Add(to.Email);
                    mailMessage.Body    = message;
                    mailMessage.Subject = "RobotShop Notification";
                    client.Send(mailMessage);

                    break;
                }
            } catch (Exception exc) {
                JanelObserver.EventManager.Dispatch(new ErrorOccurred(exc));
                return(false);
            }

            return(true);
        }
    static void Main(string[] args)
    {
        // Find your Account SID and Auth Token at twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken  = "your_auth_token";

        Twilio.Init(accountSid, authToken);
        var call = CallResource.Create(new PhoneNumber("+14155551212"),
                                       new PhoneNumber("+15017250604"),
                                       url: new Uri("http://demo.twilio.com/docs/voice.xml"),
                                       record: true);

        Console.WriteLine(call.Sid);
    }