Esempio n. 1
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);
    }
Esempio n. 2
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));
        }
Esempio n. 3
0
        public async Task <IResponse> CallAsync(string from, string to, string msg)
        {
            var pnFrom = new PhoneNumber(from);
            var pnTo   = new PhoneNumber(to);

            var body = WebUtility.UrlEncode(msg);

            var call = await CallResource.CreateAsync(
                pnTo,
                pnFrom,
                url : new Uri($"https://handler.twilio.com/twiml/EH551ae48b51b996d131ebe9a19372ad6f?body={body}"));

            return(new CallResponse(call));
        }
Esempio n. 4
0
        //public void Dial()
        //{
        //    var response = new VoiceResponse();
        //    var dial = new Dial(callerId: "414");
        //    dial.Number("");
        //    response.Append(dial);

        // //   CallAsync(pnFrom, pnTo, msg);

        //    Console.WriteLine(response.ToString());
        //}

        public async Task <IResponse> CallAsync(string from, string to, string msg)
        {
            var pnFrom = new PhoneNumber(from);
            var pnTo   = new PhoneNumber(to);

            var body = WebUtility.UrlEncode(msg);

            var call = await CallResource.CreateAsync(
                pnTo,
                pnFrom,
                url : new Uri($"http://www.rokurocket.com/twilio_call_ext_server/twilio-phone-dialer-servr/voice.php")); //requesturl

            CallResponse Cr = new CallResponse(call);

            return(Cr);
        }
        public async Task <IResponse> CallAsync(string from, string to, string msg)
        {
            var fromPhoneNumber = new PhoneNumber(from);
            var toPhoneNumber   = new PhoneNumber(to);
            var body            = WebUtility.UrlEncode(msg);

            var call = await CallResource.CreateAsync(
                to : toPhoneNumber,
                from : fromPhoneNumber,
                url : new Uri($"https://handler.twilio.com/twiml/EH551ae48b51b996d131ebe9a19372ad6f?body={body}"),
                timeout : 30);

            Thread.Sleep(1000 * 10);
            call = CallResource.Update(status: CallResource.UpdateStatusEnum.Completed, pathSid: call.Sid);

            return(new CallResponse(call));
        }
Esempio n. 6
0
        public async Task <MessageSendResult> SendPhoneCallAsync(string phoneNumber, Uri messageUrl)
        {
            var sendResult = await CallResource.CreateAsync(
                from : _phoneNumber,
                to : new PhoneNumber(phoneNumber),
                url : messageUrl
                );

            return(new MessageSendResult
            {
                IsSuccess = sendResult.Status != MessageResource.StatusEnum.Failed,
                Message = sendResult.Status != MessageResource.StatusEnum.Failed
                    ? "Outbound phone call initiated"
                    : "There was an issue starting the phone call, please check your Twilio logs",
                TrackingIdentifier = sendResult.Sid
            });
        }
Esempio n. 7
0
        public async Task CallAsync(Incident incident, CallSequenceItem stage, string fromNumber, HttpContext ctx)
        {
            var webAddress = $"{ctx.Request.Scheme}://{ctx.Request.Host.Value}";
            var query      = "?incidentId=" + incident.Id;

            await StatusHub.UpdateClientAsync(incident.UserId, "phoneStart", stage.Name + (incident.Attempt > 1 ? $" (attempt {incident.Attempt} of {stage.Attempts})" : string.Empty), ctx);

            await CallResource.CreateAsync(
                to : new PhoneNumber(stage.Number),
                from : new PhoneNumber(fromNumber),
                url : new Uri(webAddress + "/twilio" + query),
                statusCallback : new Uri(webAddress + "/twilio/status" + query),
                statusCallbackEvent : new List <string> {
                "completed"
            },
                machineDetection : stage.RequireKeyPress? "Enable" : null
                );
        }
        /// <summary>
        /// Places a call which is recorded.
        /// </summary>
        /// <param name="twiMLUrl">The TwiML URL to use when making the call.</param>
        /// <param name="numberToCall">The number to call.</param>
        /// <param name="twilioLocalNumber">The local number to use to make the call.</param>
        /// <param name="log">Trace logging instance.</param>
        /// <returns>A Task returning the SID of the call resource.</returns>
        public async Task <string> PlaceAndRecordCallAsync(
            Uri twiMLUrl,
            string numberToCall,
            string twilioLocalNumber,
            ILogger log)
        {
            log.LogInformation($"Received the following TwiML URL: {twiMLUrl.AbsoluteUri}");

            log.LogInformation($"Attempting to place outbound call with Twilio from {twilioLocalNumber} to {numberToCall}...");
            CallResource call = await CallResource.CreateAsync(
                to : new PhoneNumber(numberToCall),
                from : new PhoneNumber(twilioLocalNumber),
                url : twiMLUrl,
                record : true,
                client : _twilioClient);

            return(call.Sid);
        }
Esempio n. 9
0
        public async Task <IActionResult> Index()
        {
            TwilioClient.Init(_settings.AccountSid, _settings.AuthToken);

            try
            {
                var call = await CallResource.CreateAsync(
                    url : new Uri("http://demo.twilio.com/docs/voice.xml"),
                    from : new PhoneNumber("+48799449055"),
                    to : new PhoneNumber(_settings.MyNumber)
                    );

                Debug.WriteLine(call.Sid);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }

            return(Ok());
        }
Esempio n. 10
0
        public async Task Bomb(PhoneNumber target)
        {
            try
            {
                var response = new VoiceResponse();
                response.Say(_bomberConfig.BombContent);
                var sortieIndex = 1;

                while (sortieIndex <= _bomberConfig.TotalSorties)
                {
                    var selectedIndex = new Random().Next(_bomberConfig.OwnedPhoneNumbers.Count);
                    var from          = new PhoneNumber(_bomberConfig.OwnedPhoneNumbers.ToList()[selectedIndex]);
                    var call          = await CallResource.CreateAsync(target, from, twiml : response.ToString());

                    _logger.LogInformation($"{sortieIndex}/{_bomberConfig.TotalSorties} sortie(s): Call has been made: {call.Sid}");
                    sortieIndex++;
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Error occurred when bomb.");
            }
        }
Esempio n. 11
0
        public async Task CallsPagingTest(int numberOfCalls, int pageSize)
        {
            await ClearDatabase();

            var callSids1 = new List <string>();
            var callSids2 = new List <string>();

            for (int i = 0; i < numberOfCalls; i++)
            {
                var call = await CallResource.CreateAsync(TEST_TO_NUMBER, TEST_FROM_NUMBER);

                callSids1.Insert(0, call.Sid);
                callSids2.Insert(0, call.Sid);
                await Task.Delay(1);
            }

            var callsSet1 = await CallResource.ReadAsync(pageSize : pageSize);

            // we now have the first page in memory. add a newer calls to make sure this does not disturb the existing pagination
            for (int i = 0; i < 3; i++)
            {
                var call = await CallResource.CreateAsync(TEST_TO_NUMBER, TEST_FROM_NUMBER);

                callSids2.Insert(0, call.Sid);
                await Task.Delay(1);
            }

            var calls1 = callsSet1.ToList();

            Assert.Collection(calls1, callSids1.Select <string, Action <CallResource> >(sid => { return((CallResource call) => Assert.Equal(sid, call.Sid)); }).ToArray());

            var callsSet2 = await CallResource.ReadAsync(pageSize : pageSize);

            var calls2 = callsSet2.ToList();

            Assert.Collection(calls2, callSids2.Select <string, Action <CallResource> >(sid => { return((CallResource call) => Assert.Equal(sid, call.Sid)); }).ToArray());
        }
Esempio n. 12
0
        public async void SendAsync(string to)
        {
            if (string.IsNullOrEmpty(From))
            {
                throw new Exception("'From' cannot be empty");
            }
            if (string.IsNullOrEmpty(to))
            {
                throw new ArgumentException(nameof(to));
            }
            var code = _verificationCode.Generate(out var result);
            var text = _parser.Parse(code);

            TwilioClient.Init(_configuration.AccountSid, _configuration.AuthToken);
            var message = await CallResource.CreateAsync(
                from : new PhoneNumber(From),
                to : new PhoneNumber(to),
                url : new Uri(
                    $"{Url ?? "http://twimlets.com/message?" + WebUtility.UrlEncode("Message[0]=")}{text}"
                    )
                );

            MessageSentHandler?.Invoke(result, message);
        }
Esempio n. 13
0
 public async Task <CallResource> Call(string to, string from, string url)
 {
     return(await CallResource.CreateAsync(
                new PhoneNumber(to), new PhoneNumber(from), url : new Uri(url), client : _client));
 }
 public async Task CallAgentAsync(string agentId, string callbackUrl)
 {
     var to   = new PhoneNumber($"client:{agentId}");
     var from = new PhoneNumber(Config.TwilioPhoneNumber);
     await CallResource.CreateAsync(to, from, url : new Uri(callbackUrl));
 }
        public static async Task <bool> SendSMSCallMessageTwilio([ActivityTrigger] bool isAlreadySavedToQueue, ILogger log, ExecutionContext executionContext)
        {
            log.LogInformation($"BLOB already saved to queue.");

            //Config settings for Azure Service Bus
            var azureServiceBusConfig = new ConfigurationBuilder()
                                        .SetBasePath(executionContext.FunctionAppDirectory)
                                        .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
                                        .AddEnvironmentVariables()
                                        .Build();

            var twilioAccountId      = azureServiceBusConfig["Twilio_SID"];
            var twilioSecret         = azureServiceBusConfig["Twilio_Secret"];
            var twilioAdminMobile    = azureServiceBusConfig["Admin_Mobile"];
            var twilioVerifiedNumber = azureServiceBusConfig["Twilio_Verified_Number"];

            TwilioClient.Init(twilioAccountId, twilioSecret);

            try
            {
                if (isAlreadySavedToQueue == true)
                {
                    //Send SMS to Azure Service Bus Admin User
                    var smsMessage = await MessageResource.CreateAsync(
                        body : "Hi Admin! A new cloud blob file was uploaded to your Service Bus Queue.",
                        from : new PhoneNumber(twilioVerifiedNumber),
                        to : new PhoneNumber(twilioAdminMobile)
                        );

                    //Backend logging
                    log.LogInformation($"Sms sent to the number {twilioAdminMobile}. \n " +
                                       $"Message Id : {smsMessage.Sid} \n " +
                                       $"Date Sent : {smsMessage.DateSent} \n " +
                                       $"Message : {smsMessage.Body}");

                    //Initiate call reminder to admin
                    var call = CallResource.CreateAsync(
                        twiml: new Twiml("<Response><Say>Hi Jonah! Call reminder. New BLOB added to Service Bus Queue!</Say></Response>"),
                        from: new PhoneNumber(twilioVerifiedNumber),
                        to: new PhoneNumber(twilioAdminMobile)
                        );

                    //Backend logging
                    log.LogInformation($"Called admin on number {twilioAdminMobile}. \n " +
                                       $"Call Id : {call.Id} \n " +
                                       $"Call Status : {call.Status} \n " +
                                       $"Call Completed : {call.IsCompleted} \n ");

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (ApiException e)
            {
                if (e.Code == 21614)
                {
                    Console.WriteLine("Uh oh, looks like this caller can't receive SMS messages.");
                }
                throw;
            }
        }