Ejemplo n.º 1
0
        public ActionResult CallMute()
        {
            TwilioClient.Init(_accountSid, _authToken);

            string conferenceSid = Request.Params.Get("conference");
            string callSid       = Request.Params.Get("participant");
            bool   muted         = Convert.ToBoolean(Request.Params.Get("muted"));

            ParticipantResource.Update(
                conferenceSid,
                callSid,
                hold: muted
                );


            var response = new VoiceResponse();

            return(Content(response.ToString(), contentType: "text/xml"));
        }
Ejemplo n.º 2
0
    static void Main()
    {
        var response = new VoiceResponse();
        var dial     = new Dial();

        dial.Number("+14155555555", statusCallbackEvent: new [] { Number
                                                                  .EventEnum.Initiated, Number.EventEnum.Ringing, Number.EventEnum
                                                                  .Answered, Number.EventEnum.Completed }.ToList(),
                    statusCallback: new Uri("https://myapp.com/calls/events"),
                    statusCallbackMethod: Twilio.Http.HttpMethod.Post);
        dial.Number("+14153333333", statusCallbackEvent: new [] { Number
                                                                  .EventEnum.Initiated, Number.EventEnum.Ringing, Number.EventEnum
                                                                  .Answered, Number.EventEnum.Completed }.ToList(),
                    statusCallback: new Uri("https://example.com/events"),
                    statusCallbackMethod: Twilio.Http.HttpMethod.Post);
        response.Append(dial);

        Console.WriteLine(response.ToString());
    }
Ejemplo n.º 3
0
        public static IActionResult RunTwilioResult(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "twilio")]
            HttpRequest req, ILogger log)
        {
            string name    = req.Query["code"];
            string culture = req.Query["culture"];

            //var culture = CultureInfo.CurrentUICulture.ChangeCultureBaseOnCountry(result.Country);
            CultureInfo.DefaultThreadCurrentCulture = new CultureInfo(culture);
            var twiml    = new VoiceResponse();
            var sentence = string.Format(ResourceWrapper.GetString("call_text"), string.Join(". ", name.ToCharArray()));

            twiml.Say(sentence, loop: 3, voice: "alice");
            return(new ContentResult()
            {
                Content = twiml.ToString(),
                ContentType = "application/xml"
            });
        }
        public IActionResult ProcessDigits()

        {
            var response = new VoiceResponse();

            Dictionary <string, string> department = new Dictionary <string, string>();

            department.Add("1", "sales");
            department.Add("2", "support");
            department.Add("3", "billing");

            var enqueue = new Enqueue(workflowSid: _workflow_sid);

            enqueue.Task("{'selected_product': '" + department[HttpContext.Request.Query["Digits"]] + @"'}");


            response.Append(enqueue);
            return(Content(response.ToString(), contentType: "text/xml"));
        }
Ejemplo n.º 5
0
        public void TestNestedGatherFinishOnKey()
        {
            var gather = new Gather(finishOnKey: string.Empty);

            gather.Say("Hello world");

            var vr = new VoiceResponse();

            vr.Gather(gather);

            Assert.AreEqual(
                vr.ToString(),
                "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + Environment.NewLine +
                "<Response>" + Environment.NewLine +
                "  <Gather finishOnKey=\"\">" + Environment.NewLine +
                "    <Say>Hello world</Say>" + Environment.NewLine +
                "  </Gather>" + Environment.NewLine +
                "</Response>"
                );
        }
Ejemplo n.º 6
0
    static void Main()
    {
        var response = new VoiceResponse();
        var dial     = new Dial();

        dial.Client("joey",
                    statusCallbackEvent: new List <EventEnum>()
        {
            EventEnum.Initiated,
            EventEnum.Ringing,
            EventEnum.Answered,
            EventEnum.Completed
        },
                    statusCallback: new Uri("https://myapp.com/calls/events"),
                    statusCallbackMethod: HttpMethod.Post);

        response.Append(dial);

        Console.WriteLine(response.ToString());;
    }
Ejemplo n.º 7
0
        public void TestBargeInGather()
        {
            var g = new Gather(input: "speech", action: "/finalresult", bargeIn: false);

            g.Say("Hello");

            var vr = new VoiceResponse();

            vr.Gather(g);

            Assert.AreEqual(
                vr.ToString(),
                "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + Environment.NewLine +
                "<Response>" + Environment.NewLine +
                "  <Gather input=\"speech\" action=\"/finalresult\" bargeIn=\"false\">" + Environment.NewLine +
                "    <Say>Hello</Say>" + Environment.NewLine +
                "  </Gather>" + Environment.NewLine +
                "</Response>"
                );
        }
Ejemplo n.º 8
0
        public void TestHintsGather()
        {
            var g = new Gather(input: "speech", action: "/finalresult", hints: "words, phrases that have many words");

            g.Say("Hello");

            var vr = new VoiceResponse();

            vr.Gather(g);

            Assert.AreEqual(
                vr.ToString(),
                "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + Environment.NewLine +
                "<Response>" + Environment.NewLine +
                "  <Gather input=\"speech\" action=\"/finalresult\" hints=\"words, phrases that have many words\">" + Environment.NewLine +
                "    <Say>Hello</Say>" + Environment.NewLine +
                "  </Gather>" + Environment.NewLine +
                "</Response>"
                );
        }
Ejemplo n.º 9
0
    static void Main()
    {
        var response = new VoiceResponse();
        var say = new Say("Hi", voice: "Polly.Joanna");
        say.SsmlBreak(strength: "x-weak", time: "100ms");
        say.SsmlEmphasis("Words to emphasize", level: "moderate");
        say.SsmlP("Words to speak");
        say.AddText("aaaaaa");
        say.SsmlPhoneme("Words to speak", alphabet: "x-sampa", ph: "pɪˈkɑːn");
        say.AddText("bbbbbbb");
        say.SsmlProsody("Words to speak", pitch: "-10%", rate: "85%",
            volume: "-6dB");
        say.SsmlS("Words to speak");
        say.SsmlSayAs("Words to speak", interpretAs: "spell-out");
        say.SsmlSub("Words to be substituted", alias: "alias");
        say.SsmlW("Words to speak");
        response.Append(say);

        Console.WriteLine(response.ToString());
    }
Ejemplo n.º 10
0
        public void TestPartialResultCallbackMethodGather()
        {
            var g = new Gather(input: "speech", action: "/finalresult", partialResultCallbackMethod: "POST");

            g.Say("Hello");

            var vr = new VoiceResponse();

            vr.Gather(g);

            Assert.AreEqual(
                vr.ToString(),
                "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + Environment.NewLine +
                "<Response>" + Environment.NewLine +
                "  <Gather input=\"speech\" action=\"/finalresult\" partialResultCallbackMethod=\"POST\">" + Environment.NewLine +
                "    <Say>Hello</Say>" + Environment.NewLine +
                "  </Gather>" + Environment.NewLine +
                "</Response>"
                );
        }
Ejemplo n.º 11
0
    static void Main()
    {
        var response = new VoiceResponse();
        var pay      = new Pay();
        var prompt   = new Prompt(attempt: new [] { 1 }.ToList(),
                                  for_: "expiration-date");

        prompt
        .Say("Please enter your expiration date, two digits for the month and two digits for the year.");
        pay.Append(prompt);
        var prompt2 = new Prompt(attempt: new [] { 2, 3 }.ToList(),
                                 for_: "expiration-date");

        prompt2
        .Say("Please enter your expiration date, two digits for the month and two digits for the year. For example, if your expiration date is March 2022, then please enter 0 3 2 2");
        pay.Append(prompt2);
        response.Append(pay);

        Console.WriteLine(response.ToString());
    }
Ejemplo n.º 12
0
        public IActionResult HandShake()
        {
            var response = new VoiceResponse();
            var start    = new Start();
            var stream   = new Stream(url: _projectSettings.TwilioMediaStreamWebhookUri, track: Stream.TrackEnum.BothTracks);

            start.Append(stream);
            response.Append(start);

            var say = new Say("Please record a new message.");

            response.Append(say);
            response.Pause(length: 60);

            // TODO: Dial outgoing number to replace Say above
            //var dial = new Dial(number: "+44");
            //response.Append(dial);

            return(new Twilio.AspNet.Core.TwiMLResult(response.ToString()));
        }
Ejemplo n.º 13
0
        public void TestNestedDial()
        {
            Dial dial = new Dial(hangupOnStar: false, timeLimit: 100);

            dial.Client("client", method: "GET", url: "www.twilio.com");

            var vr = new VoiceResponse();

            vr.Dial(dial);

            Assert.AreEqual(
                vr.ToString(),
                "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + Environment.NewLine +
                "<Response>" + Environment.NewLine +
                "  <Dial hangupOnStar=\"false\" timeLimit=\"100\">" + Environment.NewLine +
                "    <Client method=\"GET\" url=\"www.twilio.com\">client</Client>" + Environment.NewLine +
                "  </Dial>" + Environment.NewLine +
                "</Response>"
                );
        }
Ejemplo n.º 14
0
        public ActionResult ProcessDigits()

        {
            var response = new VoiceResponse();

            Dictionary <string, string> department = new Dictionary <string, string>();

            department.Add("1", "sales");
            department.Add("2", "support");
            department.Add("3", "billing");


            var enqueue = new Enqueue(workflowSid: _workflowSid);

            enqueue.Task("{\"selected_product\": \"" + department[Request.Params.Get("digits")] + "\"}");


            response.Append(enqueue);
            return(Content(response.ToString(), contentType: "text/xml"));
        }
Ejemplo n.º 15
0
        public async Task <ActionResult> VoiceCallAction(string userId, int callId, [FromQuery] TwilioGatherRequest twilioRequest)
        {
            var response = new VoiceResponse();

            if (twilioRequest.Digits == "0")
            {
                response.Redirect(new Uri(string.Format("{0}/Twilio/VoiceCall?userId={1}&callId={2}", Config.SystemBehaviorConfig.ResgridApiBaseUrl, userId, callId)), "GET");
            }
            else if (twilioRequest.Digits == "1")
            {
                var call = await _callsService.GetCallByIdAsync(callId);

                await _actionLogsService.SetUserActionAsync(userId, call.DepartmentId, (int)ActionTypes.RespondingToScene, null, call.CallId);

                response.Say("You have been marked responding to the scene, goodbye.").Hangup();
            }
            else
            {
                var call = await _callsService.GetCallByIdAsync(callId);

                var stations = await _departmentGroupsService.GetAllStationGroupsForDepartmentAsync(call.DepartmentId);

                int index = int.Parse(twilioRequest.Digits) - 2;

                if (index >= 0 && index < 8)
                {
                    var station = stations[index];

                    if (station != null)
                    {
                        await _actionLogsService.SetUserActionAsync(userId, call.DepartmentId, (int)ActionTypes.RespondingToStation, null,
                                                                    station.DepartmentGroupId);

                        response.Say(string.Format("You have been marked responding to {0}, goodbye.", station.Name)).Hangup();
                    }
                }
            }

            //return Request.CreateResponse(HttpStatusCode.OK, response.Element, new XmlMediaTypeFormatter());
            return(Ok(new StringContent(response.ToString(), Encoding.UTF8, "application/xml")));
        }
Ejemplo n.º 16
0
    public static void SendResponse(HttpListenerContext ctx)
    {
        HttpListenerRequest  request  = ctx.Request;
        HttpListenerResponse response = ctx.Response;

        response.StatusCode  = (int)HttpStatusCode.OK;
        response.ContentType = "text/xml";

        // Generate TwiML
        var twiml   = new VoiceResponse();
        var enqueue = new Enqueue(workflowSid: "WW0123456789abcdef0123456789abcdef");

        enqueue.Task("{\"account_number\": \"12345abcdef\"}");
        twiml.Append(enqueue);

        // Write the output and close the stream
        byte[] buffer = Encoding.UTF8.GetBytes(twiml.ToString());
        response.ContentLength64 = buffer.Length;
        response.OutputStream.Write(buffer, 0, buffer.Length);
        response.OutputStream.Close();
    }
Ejemplo n.º 17
0
    static void Main()
    {
        var response = new VoiceResponse();
        var dial     = new Dial();

        dial.Number("+14158675309",
                    statusCallbackEvent: new List <Number.EventEnum> (
                        new Number.EventEnum [] {
            Number.EventEnum.Initiated,
            Number.EventEnum.Ringing,
            Number.EventEnum.Answered,
            Number.EventEnum.Completed
        }),
                    statusCallback: new Uri("https://myapp.com/calls/events"),
                    statusCallbackMethod: HttpMethod.Post
                    );

        response.Append(dial);

        Console.WriteLine(response.ToString());;
    }
    // /Voice/HandleGather
    public ActionResult HandleGather()
    {
        var response = new VoiceResponse();

        switch (Request.Form["Digits"])
        {
        case "1":
            response.Dial("+13105551212");
            response.Say("The call failed or the remote party hung up. Goodbye.");
            break;

        case "2":
            response.Say("Record your message after the tone.");
            response.Record(maxLength: 30, action: "/Voice/HandleRecord");
            break;

        default:
            response.Redirect("/Voice");
            break;
        }
        return(Content(response.ToString(), "text/xml"));
    }
Ejemplo n.º 19
0
    public ActionResult Index(string to)
    {
        var callerId = ConfigurationManager.AppSettings["TwilioCallerId"];

        var response = new VoiceResponse();

        if (!string.IsNullOrEmpty(to))
        {
            var dial = new Dial(callerId: callerId);

            // wrap the phone number or client name in the appropriate TwiML verb
            // by checking if the number given has only digits and format symbols
            if (to.Contains(myPhoneNumber))
            {
                dial.Client("Jose");     // this works!
            }
            else if (Regex.IsMatch(to, "^[\\d\\+\\-\\(\\) ]+$"))
            {
                dial.Number(to);
            }
            else
            {
                dial.Client(to);
            }

            response.Dial(dial);
        }
        else
        {
            var dial = new Dial(callerId: callerId);
            dial.Number("+15555557898");

            response
            .Say("Transferring your call to the Twilio client, Jose.")
            .Dial(dial);
        }

        return(Content(response.ToString(), "text/xml"));
    }
Ejemplo n.º 20
0
        public void TestPlayUrlGather()
        {
            var g = new Gather();

            g.Say("Hello");
            g.Play("hey.mp3");

            var vr = new VoiceResponse();

            vr.Gather(g);

            Assert.AreEqual(
                vr.ToString(),
                "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + Environment.NewLine +
                "<Response>" + Environment.NewLine +
                "  <Gather>" + Environment.NewLine +
                "    <Say>Hello</Say>" + Environment.NewLine +
                "    <Play>hey.mp3</Play>" + Environment.NewLine +
                "  </Gather>" + Environment.NewLine +
                "</Response>"
                );
        }
Ejemplo n.º 21
0
        //public ActionResult Index(string to)
        public ContentResult Index(string to)
        {
            // If there's a caller ID setup, grab it here
            var callerId = ConfigurationManager.AppSettings["TwilioCallerId"];

            // Instantiate a new VoiceResponse
            var response = new VoiceResponse();

            // If 'to' isn't empty or null, this is an outgoing call -- this should always have something
            if (!string.IsNullOrEmpty(to))
            {
                // Build the Dial object for placing the call
                var dial = new Dial(callerId: callerId);

                /* Wrap the phone number or Constituent name in the appropriate TwiML verb
                 * by checking if the number given has only digits and format symbols */
                if (Regex.IsMatch(to, "^[\\d\\+\\-\\(\\) ]+$"))
                {
                    dial.Number(to);
                }
                else
                {
                    dial.Client(to);
                }

                // Append the caller ID
                response.Append(dial);
            }
            // 'to' was empty or null -- this is an incoming call (SHOULD NEVER HAPPEN)
            else
            {
                // Default voice playback when an incoming call is placed -- not going to be used
                response.Say("Thanks for calling!");
            }

            // Send the information to Twilio
            return(Content(response.ToString(), "text/xml"));
        }
Ejemplo n.º 22
0
    public static HttpListenerResponse SendResponse(HttpListenerContext ctx)
    {
        HttpListenerRequest  request  = ctx.Request;
        HttpListenerResponse response = ctx.Response;

        response.StatusCode  = (int)HttpStatusCode.OK;
        response.ContentType = "text/xml";

        var twiml = new VoiceResponse();

        var task = TaskResource.Create("WS0123456789abcdef0123456789abcdef"
                                       workflowSid: "WW0123456789abcdef0123456789abcdef",
                                       attributes: "{\"account_number\":\"12345abcdef\"}", priority: "5",
                                       timeout: "200");

        // alternatively
        twiml.Enqueue(
            "{\"account_number\":\"12345abcdef\"}",
            workflowSid: "WW0123456789abcdef0123456789abcdef");

        response.StatusDescription = twiml.ToString();
        return(response);
    }
Ejemplo n.º 23
0
        public async Task <ActionResult <VoiceResponse> > Incoming(string phoneNumber)
        {
            var response = new VoiceResponse();

            var order = await _unitOfWork.Orders.GetOrderWithPizzasByPhoneNumberAsync(phoneNumber);

            if (order == null)
            {
                response.Say("Pizza Cloudio bonjour!", language: Twilio.TwiML.Voice.Say.LanguageEnum.FrFr);
            }
            else
            {
                response.Say("Pizza Cloudio re-bonjour!", language: Twilio.TwiML.Voice.Say.LanguageEnum.FrFr);
            }

            response.Redirect(new Uri($"{_configuration.GetSection("Twilio:WebhookUrlPath").Value}v1/Accounts/{_configuration.GetSection("Twilio:AccountSid").Value}/flows/{_configuration.GetSection("Twilio:FlowId").Value}?FlowEvent=return"));

            return(new ContentResult {
                ContentType = "text/xml",
                Content = response.ToString(),
                StatusCode = 200
            });
        }
Ejemplo n.º 24
0
        public async Task <IActionResult> KeyPress(string incidentId, string callStatus, string digits)
        {
            if (incidentId == null || !Cache.TryGetValue(incidentId, out Incident incident))
            {
                return(StatusCode(401, "Incident token not recognised."));
            }
            if (digits == "1")
            {
                incident.Index = -1;
                await StatusHub.UpdateClientAsync(incident.UserId, "phoneDone", null, HttpContext);

                var response = new VoiceResponse()
                               .Say($"Thank you for agreeing to support in {incident.Room}.", Say.VoiceEnum.Woman)
                               .Pause(1)
                               .Say("Goodbye.", Say.VoiceEnum.Woman)
                               .Hangup();
                return(Content(response.ToString(), "text/xml"));
            }
            else
            {
                return(Index(incidentId, "human"));
            }
        }
Ejemplo n.º 25
0
    public ActionResult Index(string from)
    {
        var response = new VoiceResponse();
        var dial     = new Dial();

        // If the caller is our MODERATOR, then start the conference when they
        // join and end the conference when they leave
        if (from == Moderator)
        {
            dial.Conference("My conference",
                            startConferenceOnEnter: true,
                            endConferenceOnExit: true);
        }
        else
        {
            // Otherwise have the caller join as a regular participant
            dial.Conference("My conference",
                            startConferenceOnEnter: false);
        }

        response.Dial(dial);

        return(Content(response.ToString(), "text/xml"));
    }
Ejemplo n.º 26
0
    static void Main()
    {
        var response = new VoiceResponse();
        var dial     = new Dial();

        dial.Conference(
            "EventedConf",
            statusCallback: new Uri("https://myapp.com/events"),
            statusCallbackEvent: new List <EventEnum>(
                new EventEnum[] {
            EventEnum.Start,
            EventEnum.End,
            EventEnum.Join,
            EventEnum.Leave,
            EventEnum.Mute,
            EventEnum.Hold
        }
                )
            );

        response.Append(dial);

        Console.WriteLine(response.ToString());
    }
Ejemplo n.º 27
0
    static void Main()
    {
        var response = new VoiceResponse();
        var dial     = new Dial(
            record: "record-from-answer",
            timeout: 10,
            hangupOnStar: true,
            callerId: "bob",
            method: HttpMethod.Post,
            action: new Uri("http://example.com/handle_post_dial")
            );

        var sip = new Sip(
            new Uri("http://example.com?customheader=foo"),
            "kate",
            url: new Uri("http://example.com/handle_screening_on_answer"),
            method: HttpMethod.Post
            );

        response.Append(sip);
        response.Append(dial);

        Console.WriteLine(response.ToString());;
    }
Ejemplo n.º 28
0
    static void Main()
    {
        var response = new VoiceResponse();
        var dial     = new Dial();
        var sip      = new Sip(
            new Uri("http://example.com"),
            "kate",
            statusCallbackEvent: new List <Sip.EventEnum>(
                new EventEnum[] {
            EventEnum.Initiated,
            EventEnum.Ringing,
            EventEnum.Answered,
            EventEnum.Completed
        }
                ),
            statusCallback: new Uri("https://myapp.com/calls/events"),
            statusCallbackMethod: HttpMethod.Post
            );

        dial.Append(sip);
        response.Append(dial);

        Console.WriteLine(response.ToString());;
    }
Ejemplo n.º 29
0
        public void TestElementWithChildren()
        {
            var elem = new VoiceResponse();

            elem.Connect(new Uri("https://example.com"), Twilio.Http.HttpMethod.Get);

            elem.Dial(
                "number",
                new Uri("https://example.com"),
                Twilio.Http.HttpMethod.Get,
                1,
                true,
                1,
                "caller_id",
                Dial.RecordEnum.DoNotRecord,
                Dial.TrimEnum.TrimSilence,
                new Uri("https://example.com"),
                Twilio.Http.HttpMethod.Get,
                Promoter.ListOfOne(Dial.RecordingEventEnum.InProgress),
                true,
                Dial.RingToneEnum.At
                );

            elem.Echo();

            elem.Enqueue(
                "name",
                new Uri("https://example.com"),
                Twilio.Http.HttpMethod.Get,
                new Uri("https://example.com"),
                Twilio.Http.HttpMethod.Get,
                "workflow_sid"
                );

            elem.Gather(
                Promoter.ListOfOne(Gather.InputEnum.Dtmf),
                new Uri("https://example.com"),
                Twilio.Http.HttpMethod.Get,
                1,
                "speech_timeout",
                1,
                true,
                "finish_on_key",
                1,
                new Uri("https://example.com"),
                Twilio.Http.HttpMethod.Get,
                Gather.LanguageEnum.AfZa,
                "hints",
                true,
                true,
                true,
                Gather.SpeechModelEnum.Default,
                true
                );

            elem.Hangup();

            elem.Leave();

            elem.Pause(1);

            elem.Play(new Uri("https://example.com"), 1, "digits");

            elem.Queue(
                "name",
                new Uri("https://example.com"),
                Twilio.Http.HttpMethod.Get,
                "reservation_sid",
                "post_work_activity_sid"
                );

            elem.Record(
                new Uri("https://example.com"),
                Twilio.Http.HttpMethod.Get,
                1,
                "finish_on_key",
                1,
                true,
                Record.TrimEnum.TrimSilence,
                new Uri("https://example.com"),
                Twilio.Http.HttpMethod.Get,
                Promoter.ListOfOne(Record.RecordingEventEnum.InProgress),
                true,
                new Uri("https://example.com")
                );

            elem.Redirect(new Uri("https://example.com"), Twilio.Http.HttpMethod.Get);

            elem.Reject(Reject.ReasonEnum.Rejected);

            elem.Say("message", Say.VoiceEnum.Man, 1, Say.LanguageEnum.Arb);

            elem.Sms(
                "message",
                new Twilio.Types.PhoneNumber("+15558675310"),
                new Twilio.Types.PhoneNumber("+15017122661"),
                new Uri("https://example.com"),
                Twilio.Http.HttpMethod.Get,
                new Uri("https://example.com")
                );

            elem.Pay(
                Pay.InputEnum.Dtmf,
                new Uri("https://example.com"),
                Pay.BankAccountTypeEnum.ConsumerChecking,
                new Uri("https://example.com"),
                Pay.StatusCallbackMethodEnum.Get,
                1,
                1,
                true,
                "postal_code",
                1,
                "payment_connector",
                Pay.PaymentMethodEnum.AchDebit,
                Pay.TokenTypeEnum.OneTime,
                "charge_amount",
                "currency",
                "description",
                Promoter.ListOfOne(Pay.ValidCardTypesEnum.Visa),
                Pay.LanguageEnum.DeDe
                );

            elem.Prompt(
                Prompt.ForEnum.PaymentCardNumber,
                Promoter.ListOfOne(Prompt.ErrorTypeEnum.Timeout),
                Promoter.ListOfOne(Prompt.CardTypeEnum.Visa),
                Promoter.ListOfOne(1)
                );

            elem.Start(new Uri("https://example.com"), Twilio.Http.HttpMethod.Get);

            elem.Stop();

            elem.Refer(new Uri("https://example.com"), Twilio.Http.HttpMethod.Get);

            Assert.AreEqual(
                "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + Environment.NewLine +
                "<Response>" + Environment.NewLine +
                "  <Connect action=\"https://example.com\" method=\"GET\"></Connect>" + Environment.NewLine +
                "  <Dial action=\"https://example.com\" method=\"GET\" timeout=\"1\" hangupOnStar=\"true\" timeLimit=\"1\" callerId=\"caller_id\" record=\"do-not-record\" trim=\"trim-silence\" recordingStatusCallback=\"https://example.com\" recordingStatusCallbackMethod=\"GET\" recordingStatusCallbackEvent=\"in-progress\" answerOnBridge=\"true\" ringTone=\"at\">number</Dial>" + Environment.NewLine +
                "  <Echo></Echo>" + Environment.NewLine +
                "  <Enqueue action=\"https://example.com\" method=\"GET\" waitUrl=\"https://example.com\" waitUrlMethod=\"GET\" workflowSid=\"workflow_sid\">name</Enqueue>" + Environment.NewLine +
                "  <Gather input=\"dtmf\" action=\"https://example.com\" method=\"GET\" timeout=\"1\" speechTimeout=\"speech_timeout\" maxSpeechTime=\"1\" profanityFilter=\"true\" finishOnKey=\"finish_on_key\" numDigits=\"1\" partialResultCallback=\"https://example.com\" partialResultCallbackMethod=\"GET\" language=\"af-ZA\" hints=\"hints\" bargeIn=\"true\" debug=\"true\" actionOnEmptyResult=\"true\" speechModel=\"default\" enhanced=\"true\"></Gather>" + Environment.NewLine +
                "  <Hangup></Hangup>" + Environment.NewLine +
                "  <Leave></Leave>" + Environment.NewLine +
                "  <Pause length=\"1\"></Pause>" + Environment.NewLine +
                "  <Play loop=\"1\" digits=\"digits\">https://example.com</Play>" + Environment.NewLine +
                "  <Queue url=\"https://example.com\" method=\"GET\" reservationSid=\"reservation_sid\" postWorkActivitySid=\"post_work_activity_sid\">name</Queue>" + Environment.NewLine +
                "  <Record action=\"https://example.com\" method=\"GET\" timeout=\"1\" finishOnKey=\"finish_on_key\" maxLength=\"1\" playBeep=\"true\" trim=\"trim-silence\" recordingStatusCallback=\"https://example.com\" recordingStatusCallbackMethod=\"GET\" recordingStatusCallbackEvent=\"in-progress\" transcribe=\"true\" transcribeCallback=\"https://example.com\"></Record>" + Environment.NewLine +
                "  <Redirect method=\"GET\">https://example.com</Redirect>" + Environment.NewLine +
                "  <Reject reason=\"rejected\"></Reject>" + Environment.NewLine +
                "  <Say voice=\"man\" loop=\"1\" language=\"arb\">message</Say>" + Environment.NewLine +
                "  <Sms to=\"+15558675310\" from=\"+15017122661\" action=\"https://example.com\" method=\"GET\" statusCallback=\"https://example.com\">message</Sms>" + Environment.NewLine +
                "  <Pay input=\"dtmf\" action=\"https://example.com\" bankAccountType=\"consumer-checking\" statusCallback=\"https://example.com\" statusCallbackMethod=\"GET\" timeout=\"1\" maxAttempts=\"1\" securityCode=\"true\" postalCode=\"postal_code\" minPostalCodeLength=\"1\" paymentConnector=\"payment_connector\" paymentMethod=\"ach-debit\" tokenType=\"one-time\" chargeAmount=\"charge_amount\" currency=\"currency\" description=\"description\" validCardTypes=\"visa\" language=\"de-DE\"></Pay>" + Environment.NewLine +
                "  <Prompt for=\"payment-card-number\" errorType=\"timeout\" cardType=\"visa\" attempt=\"1\"></Prompt>" + Environment.NewLine +
                "  <Start action=\"https://example.com\" method=\"GET\"></Start>" + Environment.NewLine +
                "  <Stop></Stop>" + Environment.NewLine +
                "  <Refer action=\"https://example.com\" method=\"GET\"></Refer>" + Environment.NewLine +
                "</Response>",
                elem.ToString()
                );
        }
Ejemplo n.º 30
0
        public void TestElementWithChildren()
        {
            var elem = new VoiceResponse();

            elem.Dial(
                "number",
                new Uri("https://example.com"),
                Twilio.Http.HttpMethod.Get,
                1,
                true,
                1,
                "caller_id",
                Dial.RecordEnum.DoNotRecord,
                Dial.TrimEnum.TrimSilence,
                new Uri("https://example.com"),
                Twilio.Http.HttpMethod.Get,
                Promoter.ListOfOne(Dial.RecordingEventEnum.InProgress),
                true,
                Dial.RingToneEnum.At
                );

            elem.Echo();

            elem.Enqueue(
                "name",
                new Uri("https://example.com"),
                Twilio.Http.HttpMethod.Get,
                new Uri("https://example.com"),
                Twilio.Http.HttpMethod.Get,
                "workflow_sid"
                );

            elem.Gather(
                Gather.InputEnum.Dtmf,
                new Uri("https://example.com"),
                Twilio.Http.HttpMethod.Get,
                1,
                "speech_timeout",
                1,
                true,
                "finish_on_key",
                1,
                new Uri("https://example.com"),
                Twilio.Http.HttpMethod.Get,
                Gather.LanguageEnum.AfZa,
                "hints",
                true
                );

            elem.Hangup();

            elem.Leave();

            elem.Pause(1);

            elem.Play(new Uri("https://example.com"), 1, "digits");

            elem.Queue(
                "name",
                new Uri("https://example.com"),
                Twilio.Http.HttpMethod.Get,
                "reservation_sid",
                "post_work_activity_sid"
                );

            elem.Record(
                new Uri("https://example.com"),
                Twilio.Http.HttpMethod.Get,
                1,
                "finish_on_key",
                1,
                true,
                Record.TrimEnum.TrimSilence,
                new Uri("https://example.com"),
                Twilio.Http.HttpMethod.Get,
                true,
                new Uri("https://example.com")
                );

            elem.Redirect(new Uri("https://example.com"), Twilio.Http.HttpMethod.Get);

            elem.Reject(Reject.ReasonEnum.Rejected);

            elem.Say("message", Say.VoiceEnum.Man, 1, Say.LanguageEnum.DaDk);

            elem.Sms(
                "message",
                new Twilio.Types.PhoneNumber("+15558675310"),
                new Twilio.Types.PhoneNumber("+15017122661"),
                new Uri("https://example.com"),
                Twilio.Http.HttpMethod.Get,
                new Uri("https://example.com")
                );

            Assert.AreEqual(
                "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + Environment.NewLine +
                "<Response>" + Environment.NewLine +
                "  <Dial action=\"https://example.com\" method=\"GET\" timeout=\"1\" hangupOnStar=\"true\" timeLimit=\"1\" callerId=\"caller_id\" record=\"do-not-record\" trim=\"trim-silence\" recordingStatusCallback=\"https://example.com\" recordingStatusCallbackMethod=\"GET\" recordingStatusCallbackEvent=\"in-progress\" answerOnBridge=\"true\" ringTone=\"at\">number</Dial>" + Environment.NewLine +
                "  <Echo></Echo>" + Environment.NewLine +
                "  <Enqueue action=\"https://example.com\" method=\"GET\" waitUrl=\"https://example.com\" waitUrlMethod=\"GET\" workflowSid=\"workflow_sid\">name</Enqueue>" + Environment.NewLine +
                "  <Gather input=\"dtmf\" action=\"https://example.com\" method=\"GET\" timeout=\"1\" speechTimeout=\"speech_timeout\" maxSpeechTime=\"1\" profanityFilter=\"true\" finishOnKey=\"finish_on_key\" numDigits=\"1\" partialResultCallback=\"https://example.com\" partialResultCallbackMethod=\"GET\" language=\"af-ZA\" hints=\"hints\" bargeIn=\"true\"></Gather>" + Environment.NewLine +
                "  <Hangup></Hangup>" + Environment.NewLine +
                "  <Leave></Leave>" + Environment.NewLine +
                "  <Pause length=\"1\"></Pause>" + Environment.NewLine +
                "  <Play loop=\"1\" digits=\"digits\">https://example.com</Play>" + Environment.NewLine +
                "  <Queue url=\"https://example.com\" method=\"GET\" reservationSid=\"reservation_sid\" postWorkActivitySid=\"post_work_activity_sid\">name</Queue>" + Environment.NewLine +
                "  <Record action=\"https://example.com\" method=\"GET\" timeout=\"1\" finishOnKey=\"finish_on_key\" maxLength=\"1\" playBeep=\"true\" trim=\"trim-silence\" recordingStatusCallback=\"https://example.com\" recordingStatusCallbackMethod=\"GET\" transcribe=\"true\" transcribeCallback=\"https://example.com\"></Record>" + Environment.NewLine +
                "  <Redirect method=\"GET\">https://example.com</Redirect>" + Environment.NewLine +
                "  <Reject reason=\"rejected\"></Reject>" + Environment.NewLine +
                "  <Say voice=\"man\" loop=\"1\" language=\"da-DK\">message</Say>" + Environment.NewLine +
                "  <Sms to=\"+15558675310\" from=\"+15017122661\" action=\"https://example.com\" method=\"GET\" statusCallback=\"https://example.com\">message</Sms>" + Environment.NewLine +
                "</Response>",
                elem.ToString()
                );
        }