public IActionResult Index()
        {
            var    parameters = ToDictionary(this.Request.Form);
            var    response   = new VoiceResponse();
            string CallSid    = "";

            parameters.TryGetValue("CallSid", out CallSid);

            if (!String.IsNullOrWhiteSpace(CallSid))
            {
                Call call = null;
                memoryCache.TryGetValue(CallSid, out call);
                // bool isExist = memoryCache.TryGetValue(AccountSid, out call);
                if (call != null)
                {
                    var gather = new Gather(action: new Uri(Auth.UrlPath + "/api/connect/"));
                    gather.Say("Spinga un numero per accettare la chiamata da GIupiter.com", voice: "alice", language: "it-IT");
                    response.Append(gather);
                    response.Say("Grazie Arrivederci!", voice: "alice", language: "it-IT");
                    response.Hangup();
                }
                else
                {
                    response.Say("Mi spiace c'è stato un errore!", voice: "alice", language: "it-IT");
                    response.Hangup();
                }
            }
            else
            {
                response.Say("Mi spiace c'è stato un errore cache!", voice: "alice", language: "it-IT");
                response.Hangup();
            }
            return(Content(response.ToString(), "application/xml"));
        }
        public IActionResult Index()
        {
            var    parameters = ToDictionary(this.Request.Form);
            var    response   = new VoiceResponse();
            string CallSid    = "";

            parameters.TryGetValue("CallSid", out CallSid);
            if (!String.IsNullOrWhiteSpace(CallSid))
            {
                Call call = null;
                memoryCache.TryGetValue(CallSid, out call);
                if (call != null)
                {
                    response.Say("Giupiter.com la sta mettendo in contatto.", voice: "alice", language: "it-IT");
                    response.Dial(call.UserNumber, timeLimit: call.TimeLimit);
                    response.Hangup();
                    HttpTools.UpdateCall(call, "dtm");
                }
                else
                {
                    response.Say("Mi spiace c'è stato un errore!", voice: "alice", language: "it-IT");
                    response.Hangup();
                }
            }
            else
            {
                response.Say("Mi spiace c'è stato un errore cache!", voice: "alice", language: "it-IT");
                response.Hangup();
            }
            return(Content(response.ToString(), "application/xml"));
        }
        public TwiMLResult Call(string agentId, string dialCallStatus)
        {
            if (dialCallStatus == "completed")
            {
                var emptyResponse = new XDocument(new XElement("Root", ""));
                return(new TwiMLResult(emptyResponse));
            }

            var response = new VoiceResponse();

            response.Say(
                body: "It appears that no agent is available. " +
                "Please leave a message after the beep",
                language: "en-GB",
                voice: "alice"
                );

            response.Record(
                maxLength: 20,
                playBeep: true,
                action: Url.Action("Hangup"),
                transcribeCallback: Url.Action("Create", "Recording", new { agentId })
                );

            response.Say(
                body: "No record received. Goodbye",
                language: "en-GB",
                voice: "alice"
                );

            response.Hangup();

            return(TwiML(response));
        }
        public TwiMLResult Index(VoiceRequest request, string addOns)
        {
            var response      = new VoiceResponse();
            var isCallBlocked = false;

            if (!string.IsNullOrWhiteSpace(addOns))
            {
                Trace.WriteLine(addOns);

                var addOnData = JObject.Parse(addOns);
                if (addOnData["status"]?.ToString() == "successful")
                {
                    isCallBlocked = IsBlockedByNomorobo(addOnData["results"]?["nomorobo_spamscore"]) ||
                                    IsBlockedByWhitepages(addOnData["results"]?["whitepages_pro_phone_rep"]) ||
                                    IsBlockedByMarchex(addOnData["results"]?["marchex_cleancall"]);
                }
            }

            if (isCallBlocked)
            {
                response.Reject();
            }
            else
            {
                response.Say("Welcome to the jungle.");
                response.Hangup();
            }
            return(TwiML(response));
        }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            DayOfWeek[] days =
                Configuration.GetValue <string>("Days", "1, 2, 3, 4, 5, 6").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(x => (DayOfWeek)int.Parse(x)).ToArray();
            //new DayOfWeek[] { DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday };

            double startHour = Configuration.GetValue <double>("StartHour", 9);
            double endHour   = Configuration.GetValue <double>("EndHour", 18);

            string[] phoneNumbers = Configuration.GetValue <string>("PhoneNumbers", "").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            app.Run(async(context) =>
            {
                VoiceResponse response      = new VoiceResponse();
                TimeZoneInfo centralZone    = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");
                DateTime currentCentralTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, centralZone);
                if ((days.Contains(currentCentralTime.DayOfWeek)) && (currentCentralTime > currentCentralTime.Date.AddHours(startHour)) && (currentCentralTime < currentCentralTime.Date.AddHours(endHour)))
                {
                    response.Play(null, null, "ww9ww9ww9");
                    response.Hangup();
                }
                else if (phoneNumbers.Any())
                {
                    phoneNumbers.ToList().ForEach(x => { response.Dial(x); });
                }
                else
                {
                    response.Say("Access Denied");
                }
                context.Response.ContentType = "text/xml";
                await context.Response.WriteAsync(response.ToString());
            });
        }
Beispiel #6
0
        private async Task <VoiceResponse> TwiMlHangUp()
        {
            _logger.LogDebug("Hang up the phone");
            await _hubContext.Clients.All.SendAsync("SendShortAction", "Hang up");

            var hangUpVoices = new List <string>();

            foreach (var endingCat in _voiceConfig.Ending)
            {
                if (_voiceConfig.Mapping.ContainsKey(endingCat))
                {
                    hangUpVoices.AddRange(_voiceConfig.Mapping[endingCat]);
                }
            }

            if (hangUpVoices.Count == 0)
            {
                throw new InvalidConfigException("No ending voice configured");
            }

            var idx = new Random().Next(hangUpVoices.Count);

            var response = new VoiceResponse();

            response.Play(GetVoiceUrl(hangUpVoices[idx]));
            response.Hangup();
            return(response);
        }
Beispiel #7
0
        private static VoiceResponse CreateVoiceResponsePolly(BotReponse botResponse)
        {
            var voiceResponse = new VoiceResponse();

            if (botResponse.endCall)
            {
                var text = "https://feedbackbotjp.azurewebsites.net/api/Polly" + "?text=" + System.Web.HttpUtility.UrlEncode(botResponse.ResponseText);
                voiceResponse.Append(new Play(new Uri(text)));
                voiceResponse.Hangup();

                // at this point we could persist our result in a db or put on a queue
            }
            else
            {
                var input = new List <InputEnum> {
                    InputEnum.Speech
                };
                var gather = new Gather(input: input, timeout: 30, numDigits: 1, language: "en-GB", speechTimeout: "1");

                var text = "https://feedbackbotjp.azurewebsites.net/api/Polly" + "?text=" + System.Web.HttpUtility.UrlEncode(botResponse.ResponseText);
                gather.Play(new Uri(text));

                //gather.Say(botResponse.ResponseText, Say.VoiceEnum.Man, language: Say.LanguageEnum.EnGb);
                voiceResponse.Append(gather);
            }

            return(voiceResponse);
        }
        public TwiMLResult ProccessPayment(string ccInfo, string expDate, string code)
        {
            var response = new VoiceResponse();
            var total    = new ReviewRepository().GettotalAmountOwed((int)Session["orderId"]);
            var repo     = new CheckoutRepository(ccInfo, expDate, total, code, (int)Session["orderId"]);
            var record   = repo.SubmitPayment();

            if (record.Result == 0)
            {
                repo.RecordPayment((int)Session["orderId"], record.Amount.Value);
                response.Say("Thank you, your payment was successful. Thank you for placing your order. Goodbye", voice: "alice", language: "en-US");
                response.Hangup();
            }
            else if (record.Result == 1)
            {
                response.Say("The charge dit not go through. the response was, " + record.ResultMessage + ". Please try again.", voice: "alice", language: "en-US");
                response.Redirect("/checkout/EnterCCInfo");
            }
            else if (record.ErrorMessage != null)
            {
                response.Say(record.ErrorMessage + ". Please try again.", voice: "alice", language: "en-US");
                response.Redirect("/checkout/EnterCCInfo");
            }
            return(TwiML(response));
        }
    static void Main()
    {
        var response = new VoiceResponse();

        response.Hangup();

        Console.WriteLine(response.ToString());
    }
        public async Task <TwiMLResult> ConfirmPayment(string id, string digits, string from)
        {
            var response             = new VoiceResponse();
            var mobileNumber         = from;
            var receiverMobileNumber = id.Split('#')[0];
            var amount = id.Split('#')[1];

            if (digits == "1")
            {
                var values = new Dictionary <string, string>
                {
                    { "destinationMobileNumber", "+" + receiverMobileNumber },
                    { "mobileNumber", mobileNumber },
                    { "amount", amount }
                };
                HttpResponseMessage httpResponse = await _webAPIRequest.PostAsAJson("http://localhost:3000/v1/customers/wallet/transfer", values);

                WebAPIResponseModel webAPIResponseModel = Newtonsoft.Json.JsonConvert.DeserializeObject <WebAPIResponseModel>(httpResponse.Content.ReadAsStringAsync().Result);
                if (webAPIResponseModel.ResponseCode == ResponseCode.INSUFFICIENT_FUNDS)
                {
                    response.Say("You do not have insufficient funds. Please try again");
                    return(GetEndUserMobileNo(receiverMobileNumber, from));
                }
                else if (webAPIResponseModel.ResponseCode == ResponseCode.UNREGISTERED_NUMBER)
                {
                    response.Say("Oops! Entered mobile number is not present in our records. Kindly invite them to Grab World.");
                    response.Hangup();
                }
                else
                {
                    response.Say("Successfully Transferred. Thank you for calling Grab Offline Payment Care. Good bye.");
                    response.Hangup();
                }
            }
            else if (digits == "2")
            {
                return(GetEndUserMobileNo(receiverMobileNumber, from));
            }
            else
            {
                response.Hangup();
            }

            return(TwiML(response));
        }
Beispiel #11
0
        public TwiMLResult Exit()
        {
            var response = new VoiceResponse();

            response.Say("Thank you for your time.", language: "en-GB");
            response.Hangup();

            return(this.TwiML(response));
        }
    public ActionResult Index()
    {
        var response = new VoiceResponse();

        response.Say("Hi! I want to know what do you think about coding.");
        response.Record(maxLength: 10, action: new Uri("/recording", UriKind.Relative));
        response.Hangup();

        return(TwiML(response));
    }
        public ActionResult Goodbye()
        {
            var voiceResponse = new VoiceResponse();

            voiceResponse.Say("Thank you for using Call Congress! " +
                              "Your voice makes a difference. Goodbye.");
            voiceResponse.Hangup();

            return(TwiML(voiceResponse));
        }
        public TwiMLResult Hangup()
        {
            var response = new VoiceResponse();

            response.Say(
                body: "Thanks for your message. Goodbye",
                language: "en-GB",
                voice: "alice"
                );
            response.Hangup();

            return(TwiML(response));
        }
        public IActionResult Voice(string from)
        {
            var message = "Thanks for calling! " +
                          $"Your phone number is {from}. " +
                          "I got your call because of Twilio\'s webhook. " +
                          "Goodbye!";

            var response = new VoiceResponse();

            response.Say(string.Format(message, from));
            response.Hangup();

            return(Content(response.ToString()));
        }
Beispiel #16
0
        public void TestHangup()
        {
            var vr = new VoiceResponse();

            vr.Hangup();

            Assert.AreEqual(
                vr.ToString(),
                "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + Environment.NewLine +
                "<Response>" + Environment.NewLine +
                "  <Hangup />" + Environment.NewLine +
                "</Response>"
                );
        }
Beispiel #17
0
    public ActionResult Index()
    {
        var response = new VoiceResponse();

        // Use <Say> to give the caller some instructions
        response.Say("Hello. Please leave a message and I will transcribe it.");

        // Use <Record> to record and transcribe the caller's message
        response.Record(transcribe: true, maxLength: 30);

        // End the call with <Hangup>
        response.Hangup();

        return(Content(response.ToString(), "text/xml"));
    }
Beispiel #18
0
        public HttpResponseMessage PostVoice([FromBody] TwilioVoiceRequest voiceRequest)
        {
            var message =
                "Thanks for calling! " +
                $"Your phone number is {voiceRequest.From}. " +
                "I got your call because of Twilio's webhook. " +
                "Goodbye!";

            var response = new VoiceResponse();

            response.Say(message);
            response.Hangup();

            return(ToResponseMessage(response.ToString()));
        }
Beispiel #19
0
    public ActionResult Index()
    {
        var response = new VoiceResponse();

        // Use <Say> to give the caller some instructions
        response.Say("Hello. Please leave a message after the beep.");

        // Use <Record> to record the caller's message
        response.Record();

        // End the call with <Hangup>
        response.Hangup();

        return Content(response.ToString(), "text/xml")
    }
        public TwiMLResult SaveMessage(string From, string RecordingUrl)
        {
            var             response = new VoiceResponse();
            SalesRepository repo     = new SalesRepository();

            BirovAm.data.Message m = new BirovAm.data.Message
            {
                PhoneNumber = From.Substring(2),
                MessageURL  = RecordingUrl
            };
            repo.AddMessageURL(m);
            response.Say("thank you for your message");
            response.Hangup();
            return(TwiML(response));
        }
        public async Task <TwiMLResult> GetWalletBalance(string from)
        {
            var response = new VoiceResponse();
            var values   = new Dictionary <string, string>
            {
                { "mobileNumber", from }
            };
            var httpResponse = await _webAPIRequest.PostAsAJson("http://localhost:3000/v1/customers/wallet/balance", values);

            var    balanceModel = JToken.Parse(httpResponse.Content.ReadAsStringAsync().Result);
            string balance      = Convert.ToString(balanceModel["balance"]);

            response.Say("You have " + balance + " in the wallet");
            response.Hangup();
            return(TwiML(response));
        }
Beispiel #22
0
        private TwiMLResult ReturnInstructions()
        {
            var response = new VoiceResponse();

            response.Say("To get to your extraction point, get on your bike and go down " +
                         "the street. Then Left down an alley. Avoid the police cars. Turn left " +
                         "into an unfinished housing development. Fly over the roadblock. Go " +
                         "passed the moon. Soon after you will see your mother ship.",
                         voice: "alice", language: "en-GB");

            response.Say("Thank you for calling the ET Phone Home Service - the " +
                         "adventurous alien's first choice in intergalactic travel");

            response.Hangup();

            return(TwiML(response));
        }
Beispiel #23
0
        public void TestVoiceResponse()
        {
            var vr = new VoiceResponse();

            vr.Hangup();
            vr.Leave();
            vr.Sms("twilio sms", to: "+11234567890", from: "+10987654321");

            Assert.AreEqual(
                vr.ToString(),
                "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + Environment.NewLine +
                "<Response>" + Environment.NewLine +
                "  <Hangup />" + Environment.NewLine +
                "  <Leave />" + Environment.NewLine +
                "  <Sms to=\"+11234567890\" from=\"+10987654321\">twilio sms</Sms>" + Environment.NewLine +
                "</Response>"
                );
        }
        public TwiMLResult ScreenCall(string from)
        {
            var response = new VoiceResponse();

            var incomingCallMessage = "You have an incoming call from: " +
                                      SpelledPhoneNumber(from);
            var gather = new Gather(
                numDigits: 1,
                action: Url.Action("ConnectMessage")
                );

            gather.Say(incomingCallMessage)
            .Say("Press any key to accept");
            response.Gather(gather);

            response.Say("Sorry. Did not get your response");
            response.Hangup();

            return(TwiML(response));
        }
Beispiel #25
0
        public TwiMLResult ScreenCall(string from)
        {
            var response = new VoiceResponse();

            var incomingCallMessage = "You have an incoming call from: " +
                                      from;
            var gather = new Gather(
                numDigits: 1,
                action: new Uri("/answer/connectMessage", UriKind.Relative)
                );

            gather.Say(incomingCallMessage)
            .Say("Press any key to accept");
            response.Append(gather);

            response.Say("Sorry. Did not get your response");
            response.Hangup();

            return(TwiML(response));
        }
Beispiel #26
0
        private TwiMLResult ReturnInstructions()
        {
            var bb = Request["From"] != null ? Request["From"] : "7087070312";

            createticket("IVR-Voice", bb);
            var response = new VoiceResponse();

            response.Say("A new support ticket has been created.");

            /* response.Say("To get to your extraction point, get on your bike and go down " +
             *            "the street. Then Left down an alley. Avoid the police cars. Turn left " +
             *            "into an unfinished housing development. Fly over the roadblock. Go " +
             *            "passed the moon. Soon after you will see your mother ship.",
             *            voice: "alice", language: "en-GB");*/

            response.Say("Thank you again for calling the Office of Personnel Management. Good bye.");

            response.Hangup();

            return(TwiML(response));
        }
Beispiel #27
0
        private static VoiceResponse CreateVoiceResponse(BotReponse botResponse)
        {
            var voiceResponse = new VoiceResponse();

            if (botResponse.endCall)
            {
                voiceResponse.Append(new Say(botResponse.ResponseText, Say.VoiceEnum.Man, language: Say.LanguageEnum.EnGb));
                voiceResponse.Hangup();

                // at this point we could persist our result in a db or put on a queue
            }
            else
            {
                var input = new List <InputEnum> {
                    InputEnum.Speech, InputEnum.Dtmf, InputEnum.Dtmf
                };
                var gather = new Gather(input: input, timeout: 30, numDigits: 1, language: "en-GB", speechTimeout: "1");
                gather.Say(botResponse.ResponseText, Say.VoiceEnum.Man, language: Say.LanguageEnum.EnGb);
                voiceResponse.Append(gather);
            }

            return(voiceResponse);
        }
        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()
                );
        }
Beispiel #29
0
        private async System.Threading.Tasks.Task HandleIncomingBotMessagesAsync(IList <Activity> botReplies, string callSid)
        {
            var voiceResponse    = new VoiceResponse();
            var says             = new StringBuilder();
            var forwardingNumber = string.Empty;
            var forward          = false;
            var error            = false;
            var errorMessage     = string.Empty;

            foreach (var activity in botReplies)
            {
                var languagesManager = new LanguagesManager();
                var localeCulture    = languagesManager.CheckAndReturnAppropriateCulture(activity.Locale);
                CultureInfo.CurrentCulture = new CultureInfo(localeCulture);

                //Using TTS to repond to the caller
                var ttsResponse = await System.Threading.Tasks.Task.Run(() =>
                                                                        _textToSpeech.TransformTextToSpeechAsync(activity.Text, CultureInfo.CurrentCulture.Name));

                var wavGuid = Guid.NewGuid();
                var pathToAudioDirectory = _hostingEnvironment.WebRootPath + "/audio";
                var pathCombined         = Path.Combine(pathToAudioDirectory, $"{ wavGuid }.wav");
                var formatConverter      = new FormatConvertor();
                await formatConverter.TurnAudioStreamToFile(ttsResponse, pathCombined);

                voiceResponse.Play(new Uri($"{_directlineConfig.Host}audio/{wavGuid}.wav"));

                if (activity.Entities != null)
                {
                    foreach (var entity in activity.Entities)
                    {
                        forward          = entity.Properties.TryGetValue("forward", out var numberJToken);
                        forwardingNumber = forward ? numberJToken.ToString() : string.Empty;

                        error = entity.Properties.TryGetValue("error", out var errorMessageJToken);
                        if (error)
                        {
                            break;
                        }
                    }
                }
            }

            if (error)
            {
                voiceResponse.Hangup();
            }
            else if (forward)
            {
                voiceResponse.Dial(number: forwardingNumber);
            }
            else
            {
                voiceResponse.Gather(
                    input: new List <Gather.InputEnum> {
                    Gather.InputEnum.Speech
                },
                    language: CultureInfo.CurrentCulture.Name,
                    action: new Uri($"{_directlineConfig.Host}api/voice/send"),
                    method: HttpMethod.Get,
                    speechTimeout: "auto",
                    hints: _hints
                    );
            }

            var xmlFileName        = Guid.NewGuid();
            var pathToXMLDirectory = _hostingEnvironment.WebRootPath + "/xml";

            System.IO.File.WriteAllText($"{pathToXMLDirectory}/{xmlFileName}.xml", voiceResponse.ToString());

            CallResource.Update(
                method: HttpMethod.Get,
                url: new Uri($"{_directlineConfig.Host}xml/{xmlFileName}.xml"),
                pathSid: callSid
                );
        }
Beispiel #30
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()
                );
        }