Esempio n. 1
0
 public override void Execute(FSOutbound outboundClient)
 {
     string play_str = "";
     if (!string.IsNullOrEmpty(SoundFilePath))
     {
         if (LoopTimes == 1)
             play_str = SoundFilePath;
         else
             outboundClient.set("playback_delimiter=!");
         play_str = "file_string://silence_stream://1!";
         List<string> path = new List<string>();
         for (int i = 1; i <= LoopTimes; i++)
         {
             path.Add(SoundFilePath);
         }
         play_str += string.Join("!", path);
         var res = outboundClient.playback(play_str);
         if (res.IsReplyTextSuccess())
         {
             var evnt = outboundClient.ActionReturnedEvent();
             if (evnt.GetHeaders().Count < 1)
             {
                 return;
             }
         }
         else
         {
         }
         return;
     }
 }
Esempio n. 2
0
        public override void Execute(FSOutbound outboundClient)
        {
            foreach (Element child in Children)
            {
                if (child.GetType() == typeof(Play))
                {
                    var play = (Play)child;
                    play.Execute(outboundClient);
                }
                else if (child.GetType() == typeof(Pause))
                {
                    var pause = (Pause)child;
                    pause.Execute(outboundClient);
                }
                else if (child.GetType() == typeof(Say))
                {
                    var say = (Say)child;
                    say.Execute(outboundClient);
                }
            }
            outboundClient.play_and_get_digits(1, num_digits, retries, timeout, finish_on_key, null, "", "pagd_input", valid_digits, "", play_beep);

            var    evnt   = outboundClient.ActionReturnedEvent();
            string digits = evnt.GetHeader("variable_pagd_input");

            if (!string.IsNullOrEmpty(digits) && !string.IsNullOrEmpty(action))
            {
                outboundClient.session_params["Digits"] = digits;
                FetchNextAgbaraRespone(action, outboundClient.session_params, method);
            }
        }
Esempio n. 3
0
        public override void Execute(FSOutbound outboundClient)
        {
            foreach (Element child in Children)
                if (child.GetType() == typeof(Play))
                {
                    var play = (Play)child;
                    play.Execute(outboundClient);
                }
                else if (child.GetType() == typeof(Pause))
                {
                    var pause = (Pause)child;
                    pause.Execute(outboundClient);
                }
                else if (child.GetType() == typeof(Say))
                {
                    var say = (Say)child;
                    say.Execute(outboundClient);
                }
            outboundClient.play_and_get_digits(1, num_digits, retries, timeout, finish_on_key, null, "", "pagd_input", valid_digits, "", play_beep);

            var evnt = outboundClient.ActionReturnedEvent();
            string digits = evnt.GetHeader("variable_pagd_input");
            if (!string.IsNullOrEmpty(digits) && !string.IsNullOrEmpty(action))
            {
                outboundClient.session_params["Digits"] = digits;
                FetchNextAgbaraRespone(action, outboundClient.session_params, method);
            }
        }
Esempio n. 4
0
 public override void Execute(FSOutbound outboundClient)
 {
     outboundClient.preanswer();
     foreach (Element child in Children)
     {
         child.Run(outboundClient);
     }
 }
Esempio n. 5
0
 public override void Execute(FSOutbound outboundClient)
 {
     outboundClient.preanswer();
     foreach (Element child in Children)
     {
         child.Run(outboundClient);
     }
 }
Esempio n. 6
0
        public override void Execute(FSOutbound outboundClient)
        {
            if (!string.IsNullOrEmpty(reason))
                reason = "NORMAL_CLEARING";

            outboundClient.hangup(reason);
            return; //reason;
        }
Esempio n. 7
0
        public override void Execute(FSOutbound outboundClient)
        {
            if (!string.IsNullOrEmpty(reason))
            {
                reason = "NORMAL_CLEARING";
            }

            outboundClient.hangup(reason);
            return; //reason;
        }
Esempio n. 8
0
 public override void Execute(FSOutbound client)
 {
     if (voice == "male")
     {
         voice = "kal";
     }
     else
     {
         voice = "slt";
     }
     string say_args = string.Format("{0}|{1}|{2}", engine, voice, base.Text);
     var res = client.speak(say_args, "", true, loop_times);
     for (int i = 1; i <= loop_times; i++)
     {
         var evnt = client.ActionReturnedEvent();
     }
     return;
 }
Esempio n. 9
0
        public override void Execute(FSOutbound client)
        {
            if (voice == "male")
            {
                voice = "kal";
            }
            else
            {
                voice = "slt";
            }
            string say_args = string.Format("{0}|{1}|{2}", engine, voice, base.Text);
            var    res      = client.speak(say_args, "", true, loop_times);

            for (int i = 1; i <= loop_times; i++)
            {
                var evnt = client.ActionReturnedEvent();
            }
            return;
        }
Esempio n. 10
0
        public override void Execute(FSOutbound outboundClient)
        {
            string play_str = "";

            if (!string.IsNullOrEmpty(SoundFilePath))
            {
                if (LoopTimes == 1)
                {
                    play_str = SoundFilePath;
                }
                else
                {
                    outboundClient.set("playback_delimiter=!");
                }
                play_str = "file_string://silence_stream://1!";
                List <string> path = new List <string>();
                for (int i = 1; i <= LoopTimes; i++)
                {
                    path.Add(SoundFilePath);
                }
                play_str += string.Join("!", path);
                var res = outboundClient.playback(play_str);
                if (res.IsReplyTextSuccess())
                {
                    var evnt = outboundClient.ActionReturnedEvent();
                    if (evnt.GetHeaders().Count < 1)
                    {
                        return;
                    }
                }
                else
                {
                }
                return;
            }
        }
Esempio n. 11
0
        private List<string> _prepare_moh(FSOutbound outboundClient)
        {
            List<string> sound_files = new List<string>(); //[]
            if (!Util.IsUrlExist(moh_sound))
            {
                DirectoryInfo file = new DirectoryInfo(moh_sound);
                if (Util.IsFileExist(moh_sound))
                {
                    moh_sound = string.Format("file_string://{0}", moh_sound);
                    sound_files.Add(moh_sound);
                }
            }
            else
            {

                XElement doc = null;
                if (!string.IsNullOrEmpty(moh_sound))
                {
                    try
                    {
                        string response = outboundClient.SendToUrl(moh_sound, outboundClient.session_params, method);
                        doc = XElement.Parse(response);
                    }
                    catch (Exception ex)
                    {
                    }
                    if (doc.Name != "Response")
                        return sound_files;

                    // build play string from remote restxml
                    foreach (XElement element in doc.Elements())
                    {
                        //Play element
                        if (element.Name == "Play")
                        {
                            Play child = new Play();
                            child.ParseElement(element);
                            string sound_file = child.SoundFilePath;
                            if (!string.IsNullOrEmpty(sound_file))
                            {
                                int loop = child.LoopTimes;
                                if (loop == 0)
                                    loop = MAX_LOOPS;  //Add a high number to Play infinitely
                                //Play the file loop number of times
                                for (int i = 0; i < loop; i++)
                                {
                                    sound_files.Add(sound_file);
                                }
                                // Infinite Loop, so ignore other children
                                if (loop == MAX_LOOPS)
                                    break;
                            }
                        }
                        //Say element
                        else if (element.Name == "Say")
                        {
                            Say child = new Say();
                            child.ParseElement(element);
                           // child.Execute(outboundClient);
                            //sound_files.Add(pause_str);
                        }

                         //Redirect element
                        else if (element.Name == "Redirect")
                        {
                            Redirect child = new Redirect();
                            child.ParseElement(element);
                            child.Execute(outboundClient);
                        }
                    }
                }
            }
            return sound_files;
        }
Esempio n. 12
0
        public override void Execute(FSOutbound outboundClient)
        {
            List<string> numbers = new List<string>();
            string sched_hangup_id = string.Empty;
            string dialNumber = string.Empty;

            if (!string.IsNullOrEmpty(base.Text.Trim()))
            {
                dialNumber = base.Text.Trim();
                Number num = new Number();
                num.number = dialNumber;
                numbers.Add(PrepareNumber(num, outboundClient));
            }
            else
            {
                //Set numbers to dial from Number nouns
                foreach (Element child in Children)
                {
                    string dial_num = "";
                    Number num = null;
                    Conference conf = null;
                    if (child.GetType() == typeof(Number))
                    {
                        num = (Number)child;
                        dial_num = PrepareNumber(num, outboundClient);
                        if (string.IsNullOrEmpty(dial_num))
                            continue;
                        numbers.Add(dial_num);
                    }
                    else if (child.GetType() == typeof(Conference))
                    {
                        //if conference is needed
                        conf = (Conference)child;
                        //set record for conference
                        if (record) { conf.record = true; }
                        //set hangupOnStar for member
                        if (hangupOnStar) { conf.hangup_on_star = true; }
                        //Create Partcipant
                        Participant participant = new Participant();
                        participant.CallSid = outboundClient.CallSid;
                        participant.AccountSid = outboundClient.AccountSid;
                        conf.participant = participant;
                        conf.Execute(outboundClient);
                    }
                }
            }
            if (numbers == null)
            {
                return;
            }
            else
            {
                string duration_ms = string.Empty;
                Call bleg = new Call();
                //Set timeout
                outboundClient.set(string.Format("call_timeout={0}", timeout));
                outboundClient.set(string.Format("answer_timeout={0}", timeout));
                //Set callerid or unset if not provided
                if (!string.IsNullOrEmpty(caller_id))
                    outboundClient.set(string.Format("effective_caller_id_number={0}", caller_id));
                else
                    outboundClient.unset("effective_caller_id_number");
                //Set continue on fail
                outboundClient.set("continue_on_fail=true");
                //Set ring flag if dial will ring.
                //But first set agbara_dial_rang to false to be sure we don't get it from an old Dial
                outboundClient.set("agbara_dial_rang=false");
                outboundClient.set("execute_on_ring=set::agbara_dial_rang=true");

                //Create dialstring
                dial_str = string.Join(":_:", numbers);

                // Don't hangup after bridge !
                outboundClient.set("hangup_after_bridge=false");
                if (hangupOnStar)
                    outboundClient.set("bridge_terminate_key=*");
                else
                    outboundClient.unset("bridge_terminate_key");
                outboundClient.set("bridge_early_media=true");
                outboundClient.unset("instant_ringback");
                outboundClient.unset("ringback");

                //set bleg call sid
                outboundClient.set(string.Format("agbara_bleg_callsid={0}", bleg.Sid));
                //enable session heartbeat
                outboundClient.set("enable_heartbeat_events=60");

                // set call direction
                outboundClient.set(string.Format( "agbara_call_direction={0}", CallDirection.outbounddial));
                string dial_rang = "";
                string hangup_cause = "NORMAL_CLEARING";

                //string recordingPath = "";
                //AppSettingsReader reader = new AppSettingsReader();
                //recordingPath = (string)reader.GetValue("RecordingDirectory", recordingPath.GetType());
                //var CallSid = outboundClient.CallSid;
                //string filename = string.Format("{0}_{1}", DateTime.UtcNow.ToShortDateString(), outboundClient.get_channel_unique_id());
                //string record_file = string.Format("{0}{1}.wav", recordingPath, CallSid);
                //if (record)
                //{
                //    outboundClient.set("RECORD_STEREO=true");
                //    outboundClient.APICommand(string.Format("uuid_record {0} start {1}", outboundClient.get_channel_unique_id(), record_file));
                //}

                try
                {
                    //execute bridge
                    outboundClient.bridge(dial_str, outboundClient.get_channel_unique_id(), true);
                    //waiting event
                    var evnt = outboundClient.ActionReturnedEvent();
                    //parse received events
                    if (evnt.GetHeader("Event-Name") == "CHANNEL_UNBRIDGE")
                    {
                        evnt = outboundClient.ActionReturnedEvent();
                    }
                    string reason = "";
                    string originate_disposition = evnt.GetHeader("variable_originate_disposition");

                    long answer_seconds_since_epoch = long.Parse(evnt.GetHeader("Caller-Channel-Answered-Time"));
                    long end_seconds_since_epoch = long.Parse(evnt.GetHeader("Event-Date-Timestamp"));

                    hangup_cause = originate_disposition;
                    if (hangup_cause == "ORIGINATOR_CANCEL")
                        reason = string.Format("{0} (A leg)", hangup_cause);
                    else
                        reason = string.Format("{0} (B leg)", hangup_cause);
                    if (string.IsNullOrEmpty(hangup_cause) || hangup_cause == "SUCCESS")
                    {
                        hangup_cause = outboundClient.GetHangupCause();
                        reason = string.Format("{0} (A leg)", hangup_cause);
                        if (string.IsNullOrEmpty(hangup_cause))
                        {
                            hangup_cause = outboundClient.GetVar("bridge_hangup_cause", outboundClient.get_channel_unique_id());
                            reason = string.Format("{0} (B leg)", hangup_cause);
                            if (string.IsNullOrEmpty(hangup_cause))
                            {
                                hangup_cause = outboundClient.GetVar("hangup_cause", outboundClient.get_channel_unique_id());
                                reason = string.Format("{0} (A leg)", hangup_cause);
                                if (string.IsNullOrEmpty(hangup_cause))
                                {
                                    hangup_cause = "NORMAL_CLEARING";
                                    reason = string.Format("{0} (A leg)", hangup_cause);
                                }
                            }
                        }
                    }

                    //Get ring status
                    dial_rang = outboundClient.GetVar("agbara_dial_rang", outboundClient.get_channel_unique_id());

                    //get duration
                    duration_ms = EpochTimeConverter.GetEpochTimeDifferent(answer_seconds_since_epoch, end_seconds_since_epoch).ToString();
                }

                catch (Exception e)
                {
                }
                finally
                {
                    outboundClient.session_params.Add("DialCallSid", bleg.Sid);
                    outboundClient.session_params.Add("DialCallDuration", duration_ms);
                    if (dial_rang == "true")
                    {

                        outboundClient.session_params.Add("DialCallStatus", CallStatus.completed);
                    }
                    else
                    {
                        outboundClient.session_params.Add("DialCallStatus", CallStatus.failed);
                    }
                }
            }

            //If record is specified
            if (record) { outboundClient.session_params.Add("RecordingUrl", ""); }

            if (!string.IsNullOrEmpty(action) && Util.IsValidUrl(action) && !string.IsNullOrEmpty(method))
            {
                Task.Factory.StartNew(() => FetchNextAgbaraRespone(action, outboundClient.session_params, method));
            }
        }
Esempio n. 13
0
        private List<string> _prepare_play_string(FSOutbound outboundClient, string remote_url)
        {
            List<string> sound_files = new List<string>();
            if (!string.IsNullOrEmpty(remote_url))
                return sound_files;
            try
            {
                string response = outboundClient.SendToUrl(remote_url, outboundClient.session_params, this.method);
                XElement doc = XElement.Load(response);
                if (doc.Name != "Response")
                    return sound_files;

                // build play string from remote restxml
                foreach (XElement ele in doc.Nodes())
                {
                    //Play element
                    if (ele.Name == "Play")
                    {
                        var child = new Play();
                        child.ParseElement(ele);
                        string sound_file = child.SoundFilePath;
                        if (!string.IsNullOrEmpty(sound_file))
                        {
                            var loop = child.LoopTimes;
                            if (loop == 0)
                                loop = 1000;  // Add a high number to Play infinitely
                            // Play the file loop number of times
                            for (int i = 1; i < loop; i++)
                                sound_files.Add(sound_file);
                            //Infinite Loop, so ignore other children
                            if (loop == 1000)
                                break;
                        }
                    }
                    //Say element
                    else if (ele.Name == "Say")
                    {
                        var child = new Say();
                        child.ParseElement(ele);
                        var text = child.Text;
                        // escape simple quote
                        text = text.Replace("'", "\\'");
                        var loop = child.loop_times;
                        var engine = child.engine;
                        var voice = child.voice;
                        var say_str = string.Format("say:{0}:{1}:'{2}'", engine, voice, text);
                        for (int i = 1; i < loop; i++)
                            sound_files.Add(say_str);
                    }
                    //Pause element
                    else if (ele.Name == "Pause")
                    {
                        var child = new Pause();
                        child.ParseElement(ele);
                        var pause_secs = child.length;
                        string pause_str = string.Format("file_string://silence_stream://{0}", (pause_secs * 1000));
                        sound_files.Add(pause_str);
                    }
                }
            }
            catch (Exception e)
            {
            }
            return sound_files;
        }
Esempio n. 14
0
        private string PrepareNumber(Number Num, FSOutbound outboundClient)
        {
            List<string> num_gw = new List<string>();
            string option_send_digits = string.Empty;
            if (string.IsNullOrEmpty(Num.number))
            {
                return "";
            }

            if (!string.IsNullOrEmpty(Num.SendDigit))
                option_send_digits = string.Format("api_on_answer='uuid_recv_dtmf ${uuid} {0}'", Num.SendDigit);
            else
                option_send_digits = "";
            foreach (Gateway gw in fs.GetGatewaysForNumber(Num.number, ""))
            {
                List<string> num_options = new List<string>();

                if (!string.IsNullOrEmpty(option_send_digits))
                    num_options.Add(option_send_digits);

                num_options.Add(string.Format("absolute_codec_string={0}", gw.GatewayCodec));
                num_options.Add(string.Format("leg_timeout={0}", gw.GatewayTimeout));
                int gw_retries = 1;
                try
                {
                    gw_retries = int.Parse(gw.GatewayRetry);
                    if (gw_retries <= 0)
                        gw_retries = 1;
                }
                catch (Exception e)
                {
                    gw_retries = 1;
                }
                string options = "";
                if (!string.IsNullOrEmpty(num_options.ToString()))
                    options = string.Format("[{0}]", string.Join(",", num_options));
                else
                    options = "";
                string num_str = string.Format("{0}{1}/{2}", options, gw.GatewayString, Num.number);
                string dial_num = "";
                for (int i = 1; i <= gw_retries; i++)
                {
                    dial_num = string.Join("|", num_str);
                }
                num_gw.Add(dial_num);
            }
            string result = string.Join("|", num_gw);
            return result;
        }
Esempio n. 15
0
        private List <string> _prepare_moh(FSOutbound outboundClient)
        {
            List <string> sound_files = new List <string>(); //[]

            if (!Util.IsUrlExist(moh_sound))
            {
                DirectoryInfo file = new DirectoryInfo(moh_sound);
                if (Util.IsFileExist(moh_sound))
                {
                    moh_sound = string.Format("file_string://{0}", moh_sound);
                    sound_files.Add(moh_sound);
                }
            }
            else
            {
                XElement doc = null;
                if (!string.IsNullOrEmpty(moh_sound))
                {
                    try
                    {
                        string response = outboundClient.SendToUrl(moh_sound, outboundClient.session_params, method);
                        doc = XElement.Parse(response);
                    }
                    catch (Exception ex)
                    {
                    }
                    if (doc.Name != "Response")
                    {
                        return(sound_files);
                    }

                    // build play string from remote restxml
                    foreach (XElement element in doc.Elements())
                    {
                        //Play element
                        if (element.Name == "Play")
                        {
                            Play child = new Play();
                            child.ParseElement(element);
                            string sound_file = child.SoundFilePath;
                            if (!string.IsNullOrEmpty(sound_file))
                            {
                                int loop = child.LoopTimes;
                                if (loop == 0)
                                {
                                    loop = MAX_LOOPS;  //Add a high number to Play infinitely
                                }
                                //Play the file loop number of times
                                for (int i = 0; i < loop; i++)
                                {
                                    sound_files.Add(sound_file);
                                }
                                // Infinite Loop, so ignore other children
                                if (loop == MAX_LOOPS)
                                {
                                    break;
                                }
                            }
                        }
                        //Say element
                        else if (element.Name == "Say")
                        {
                            Say child = new Say();
                            child.ParseElement(element);
                            // child.Execute(outboundClient);
                            //sound_files.Add(pause_str);
                        }

                        //Redirect element
                        else if (element.Name == "Redirect")
                        {
                            Redirect child = new Redirect();
                            child.ParseElement(element);
                            child.Execute(outboundClient);
                        }
                    }
                }
            }
            return(sound_files);
        }
Esempio n. 16
0
 public override void Execute(FSOutbound outboundClient)
 {
     outboundClient.hangup("NORMAL_CLEARING");
     return; //reason;
 }
Esempio n. 17
0
 public override void Execute(FSOutbound outboundClient)
 {
     FetchNextAgbaraRespone(url, outboundClient.session_params, method);
 }
Esempio n. 18
0
 public override void Execute(FSOutbound outboundClient)
 {
     FetchNextAgbaraRespone(url, outboundClient.session_params, method);
 }
Esempio n. 19
0
 public override void Execute(FSOutbound outboundClient)
 {
     outboundClient.sleep((length * 1000).ToString(), outboundClient.get_channel_unique_id(), false);
     var evnt = outboundClient.ActionReturnedEvent();
 }
Esempio n. 20
0
 public void Prepare(FSOutbound outboundClient)
 {
     //if not self.sound_file_path:
     //url = normalize_url_space(self.temp_audio_path)
     //self.sound_file_path = get_resource(outbound_socket, url)
 }
Esempio n. 21
0
 public override void Execute(FSOutbound outboundClient)
 {
     outboundClient.hangup("NORMAL_CLEARING");
     return; //reason;
 }
Esempio n. 22
0
        public override void Execute(FSOutbound outboundClient)
        {
            string            recordingPath = "";
            AppSettingsReader reader        = new AppSettingsReader();

            recordingPath = (string)reader.GetValue("RecordingDirectory", recordingPath.GetType());
            Event evnt = null;

            if (play_beep == "true")
            {
                string beep = "tone_stream://%(300,200,700)";
                outboundClient.playback(beep);
                var retEvnt = outboundClient.ActionReturnedEvent();
            }
            string record_file = string.Format("{0}{1}.wav", recordingPath, outboundClient.CallSid);

            outboundClient.start_dtmf();
            outboundClient.record(record_file, max_length.ToString(), silence_threshold.ToString(), timeout.ToString(), finish_on_key);
            evnt = outboundClient.ActionReturnedEvent();
            outboundClient.stop_dtmf();

            //Otherwise, continue to next Element
            if (!string.IsNullOrEmpty(action) && Util.IsValidUrl(action))
            {
                outboundClient.session_params["RecordUrl"] = record_file;

                int record_ms;
                try
                {
                    var duration = evnt.GetHeader("variable_record_ms");
                    if (string.IsNullOrEmpty(duration))
                    {
                        record_ms = 0;
                    }
                    else
                    {
                        record_ms = int.Parse(duration);
                    }
                }
                catch (Exception ex)
                {
                    record_ms = 0;
                }
                outboundClient.session_params["RecordingDuration"] = record_ms;
                string record_digits = evnt.GetHeader("variable_playback_terminator_used");
                if (!string.IsNullOrEmpty(record_digits))
                {
                    outboundClient.session_params["Digits"] = record_digits;
                }
                else
                {
                    outboundClient.session_params["Digits"] = "hangup";
                }

                //save recording
                Recording record = new Recording();
                record.AccountSid = outboundClient.AccountSid;
                record.CallSid    = outboundClient.CallSid;
                record.Duration   = record_ms;
                record.RecordUrl  = record_file;
                try
                {
                    recoSvc.CreateRecording(record);
                }
                catch (Exception ex)
                {
                    //log
                }

                // fetch xml
                FetchNextAgbaraRespone(action, outboundClient.session_params, method);
            }
        }
Esempio n. 23
0
        public override void Execute(FSOutbound outboundClient)
        {
            List<string> flags = new List<string>();
            //settings for conference room
            outboundClient.set("conference_controls=none");
            if (max_members > 0)
                outboundClient.set(string.Format("max-members={0}", max_members));
            else
                outboundClient.unset("max-members");

            //set moh sound
            List<string> mohs = _prepare_moh(outboundClient);
            if (mohs.Count > 0)
            {
                outboundClient.set("playback_delimiter=!");
                string play_str = string.Join("!", mohs);
                play_str = string.Format("file_string://silence_stream://1!{0}", play_str);
                outboundClient.set(string.Format("conference_moh_sound={0}", play_str));
            }
            else
                outboundClient.unset("conference_moh_sound");
            //set member flags
            if (muted)
                flags.Add("muted");
            if (StartOnEnter)
                flags.Add("moderator");
            else
                flags.Add("wait-mod");
            if (EndOnExit)
                flags.Add("endconf");
            string flags_opt = string.Join(",", flags);
            if (!string.IsNullOrEmpty(flags_opt))
                outboundClient.set(string.Format("conference_member_flags={0}", flags_opt));
            else
                outboundClient.unset("conference_member_flags");

            outboundClient.set(string.Format("agabara_confid={0}", 2333333));
            outboundClient.set(string.Format("agabara_memberid={0}", 45555));
            //really enter conference room
            var res = outboundClient.conference(full_room, outboundClient.get_channel_unique_id(), true);
            if (!res.IsReplyTextSuccess())
            {
                //error creating conference
                return;
            }
            //Console.WriteLine(""
            // get next event
            var evnt = outboundClient.ActionReturnedEvent();

            try
            {
                string digit_realm = "";

                //set hangup on star
                if (hangup_on_star)
                {
                    // create event template
                    string raw_event = string.Format("Event-Name=CUSTOM,Event-Subclass=conference::maintenance,Action=kick,Unique-ID={0},Member-ID={1},Conference-Name={2},Conference-Unique-ID={3}", outboundClient.get_channel_unique_id(), member_id, room, conf_id);
                    digit_realm = string.Format("agbara_bda_{0}", outboundClient.get_channel_unique_id());
                    string cmd = string.Format("{0},*,exec:event,'{1}'", digit_realm, raw_event);
                    outboundClient.bind_digit_action(cmd);
                }

                //play beep on enter if enabled
                if (!string.IsNullOrEmpty(member_id) && beep)
                {
                    if (enter_sound == "beep:1")
                        outboundClient.BgAPICommand(string.Format("conference {0} play tone_stream://%%(300,200,700) async", room));
                    else if (enter_sound == "beep:2")
                        outboundClient.BgAPICommand(string.Format("conference {0} play tone_stream://L=2;%%(300,200,700) async", room));
                }

                // wait conference ending for this member
                var ret = outboundClient.ActionReturnedEvent();

                //play beep on exit if enabled
                if (!string.IsNullOrEmpty(member_id))
                {
                    if (exit_sound == "beep:1")
                        outboundClient.APICommand(string.Format("conference {0} play tone_stream://%%(300,200,700) async", room));
                    else if (exit_sound == "beep:2")
                        outboundClient.APICommand(string.Format("conference {0} play tone_stream://L=2;%%(300,200,700) async", room));
                }
                //unset digit realm
                if (!string.IsNullOrEmpty(digit_realm))
                    outboundClient.clear_digit_action(digit_realm);
            }
            catch (Exception ex)
            {
            }

            finally
            {
                //notify channel has left room
               // _notify_exit_conf(outboundClient);
                //If action is set, redirect to this url, Otherwise, continue to next Element
                //if (!string.IsNullOrEmpty(action) && outboundClient.is_valid_url(action))
                //{
                //    Hashtable param = new Hashtable();
                //    param["ConferenceName"] = room;
                //    param["ConferenceUUID"] = conf_id;
                //    param["ConferenceMemberID"] = member_id;
                //    //if (!string.IsNullOrEmpty(record_file))
                //    //{
                //    //    param["RecordFile"] = record_file;
                //    //    FetchNextAgbaraRespone(action, param, method);
                //    //}
                //}
            }
        }
Esempio n. 24
0
        private string PrepareNumber(Number Num, FSOutbound outboundClient)
        {
            List <string> num_gw             = new List <string>();
            string        option_send_digits = string.Empty;

            if (string.IsNullOrEmpty(Num.number))
            {
                return("");
            }

            if (!string.IsNullOrEmpty(Num.SendDigit))
            {
                option_send_digits = string.Format("api_on_answer='uuid_recv_dtmf ${uuid} {0}'", Num.SendDigit);
            }
            else
            {
                option_send_digits = "";
            }
            foreach (Gateway gw in fs.GetGatewaysForNumber(Num.number, ""))
            {
                List <string> num_options = new List <string>();

                if (!string.IsNullOrEmpty(option_send_digits))
                {
                    num_options.Add(option_send_digits);
                }

                num_options.Add(string.Format("absolute_codec_string={0}", gw.GatewayCodec));
                num_options.Add(string.Format("leg_timeout={0}", gw.GatewayTimeout));
                int gw_retries = 1;
                try
                {
                    gw_retries = int.Parse(gw.GatewayRetry);
                    if (gw_retries <= 0)
                    {
                        gw_retries = 1;
                    }
                }
                catch (Exception e)
                {
                    gw_retries = 1;
                }
                string options = "";
                if (!string.IsNullOrEmpty(num_options.ToString()))
                {
                    options = string.Format("[{0}]", string.Join(",", num_options));
                }
                else
                {
                    options = "";
                }
                string num_str  = string.Format("{0}{1}/{2}", options, gw.GatewayString, Num.number);
                string dial_num = "";
                for (int i = 1; i <= gw_retries; i++)
                {
                    dial_num = string.Join("|", num_str);
                }
                num_gw.Add(dial_num);
            }
            string result = string.Join("|", num_gw);

            return(result);
        }
Esempio n. 25
0
 public void Prepare(FSOutbound outboundClient)
 {
     //if not self.sound_file_path:
     //url = normalize_url_space(self.temp_audio_path)
     //self.sound_file_path = get_resource(outbound_socket, url)
 }
Esempio n. 26
0
        public override void Execute(FSOutbound outboundClient)
        {
            List <string> numbers         = new List <string>();
            string        sched_hangup_id = string.Empty;
            string        dialNumber      = string.Empty;

            if (!string.IsNullOrEmpty(base.Text.Trim()))
            {
                dialNumber = base.Text.Trim();
                Number num = new Number();
                num.number = dialNumber;
                numbers.Add(PrepareNumber(num, outboundClient));
            }
            else
            {
                //Set numbers to dial from Number nouns
                foreach (Element child in Children)
                {
                    string     dial_num = "";
                    Number     num      = null;
                    Conference conf     = null;
                    if (child.GetType() == typeof(Number))
                    {
                        num      = (Number)child;
                        dial_num = PrepareNumber(num, outboundClient);
                        if (string.IsNullOrEmpty(dial_num))
                        {
                            continue;
                        }
                        numbers.Add(dial_num);
                    }
                    else if (child.GetType() == typeof(Conference))
                    {
                        //if conference is needed
                        conf = (Conference)child;
                        //set record for conference
                        if (record)
                        {
                            conf.record = true;
                        }
                        //set hangupOnStar for member
                        if (hangupOnStar)
                        {
                            conf.hangup_on_star = true;
                        }
                        //Create Partcipant
                        Participant participant = new Participant();
                        participant.CallSid    = outboundClient.CallSid;
                        participant.AccountSid = outboundClient.AccountSid;
                        conf.participant       = participant;
                        conf.Execute(outboundClient);
                    }
                }
            }
            if (numbers == null)
            {
                return;
            }
            else
            {
                string duration_ms = string.Empty;
                Call   bleg        = new Call();
                //Set timeout
                outboundClient.set(string.Format("call_timeout={0}", timeout));
                outboundClient.set(string.Format("answer_timeout={0}", timeout));
                //Set callerid or unset if not provided
                if (!string.IsNullOrEmpty(caller_id))
                {
                    outboundClient.set(string.Format("effective_caller_id_number={0}", caller_id));
                }
                else
                {
                    outboundClient.unset("effective_caller_id_number");
                }
                //Set continue on fail
                outboundClient.set("continue_on_fail=true");
                //Set ring flag if dial will ring.
                //But first set agbara_dial_rang to false to be sure we don't get it from an old Dial
                outboundClient.set("agbara_dial_rang=false");
                outboundClient.set("execute_on_ring=set::agbara_dial_rang=true");

                //Create dialstring
                dial_str = string.Join(":_:", numbers);

                // Don't hangup after bridge !
                outboundClient.set("hangup_after_bridge=false");
                if (hangupOnStar)
                {
                    outboundClient.set("bridge_terminate_key=*");
                }
                else
                {
                    outboundClient.unset("bridge_terminate_key");
                }
                outboundClient.set("bridge_early_media=true");
                outboundClient.unset("instant_ringback");
                outboundClient.unset("ringback");

                //set bleg call sid
                outboundClient.set(string.Format("agbara_bleg_callsid={0}", bleg.Sid));
                //enable session heartbeat
                outboundClient.set("enable_heartbeat_events=60");

                // set call direction
                outboundClient.set(string.Format("agbara_call_direction={0}", CallDirection.outbounddial));
                string dial_rang    = "";
                string hangup_cause = "NORMAL_CLEARING";

                //string recordingPath = "";
                //AppSettingsReader reader = new AppSettingsReader();
                //recordingPath = (string)reader.GetValue("RecordingDirectory", recordingPath.GetType());
                //var CallSid = outboundClient.CallSid;
                //string filename = string.Format("{0}_{1}", DateTime.UtcNow.ToShortDateString(), outboundClient.get_channel_unique_id());
                //string record_file = string.Format("{0}{1}.wav", recordingPath, CallSid);
                //if (record)
                //{
                //    outboundClient.set("RECORD_STEREO=true");
                //    outboundClient.APICommand(string.Format("uuid_record {0} start {1}", outboundClient.get_channel_unique_id(), record_file));
                //}


                try
                {
                    //execute bridge
                    outboundClient.bridge(dial_str, outboundClient.get_channel_unique_id(), true);
                    //waiting event
                    var evnt = outboundClient.ActionReturnedEvent();
                    //parse received events
                    if (evnt.GetHeader("Event-Name") == "CHANNEL_UNBRIDGE")
                    {
                        evnt = outboundClient.ActionReturnedEvent();
                    }
                    string reason = "";
                    string originate_disposition = evnt.GetHeader("variable_originate_disposition");

                    long answer_seconds_since_epoch = long.Parse(evnt.GetHeader("Caller-Channel-Answered-Time"));
                    long end_seconds_since_epoch    = long.Parse(evnt.GetHeader("Event-Date-Timestamp"));

                    hangup_cause = originate_disposition;
                    if (hangup_cause == "ORIGINATOR_CANCEL")
                    {
                        reason = string.Format("{0} (A leg)", hangup_cause);
                    }
                    else
                    {
                        reason = string.Format("{0} (B leg)", hangup_cause);
                    }
                    if (string.IsNullOrEmpty(hangup_cause) || hangup_cause == "SUCCESS")
                    {
                        hangup_cause = outboundClient.GetHangupCause();
                        reason       = string.Format("{0} (A leg)", hangup_cause);
                        if (string.IsNullOrEmpty(hangup_cause))
                        {
                            hangup_cause = outboundClient.GetVar("bridge_hangup_cause", outboundClient.get_channel_unique_id());
                            reason       = string.Format("{0} (B leg)", hangup_cause);
                            if (string.IsNullOrEmpty(hangup_cause))
                            {
                                hangup_cause = outboundClient.GetVar("hangup_cause", outboundClient.get_channel_unique_id());
                                reason       = string.Format("{0} (A leg)", hangup_cause);
                                if (string.IsNullOrEmpty(hangup_cause))
                                {
                                    hangup_cause = "NORMAL_CLEARING";
                                    reason       = string.Format("{0} (A leg)", hangup_cause);
                                }
                            }
                        }
                    }

                    //Get ring status
                    dial_rang = outboundClient.GetVar("agbara_dial_rang", outboundClient.get_channel_unique_id());

                    //get duration
                    duration_ms = EpochTimeConverter.GetEpochTimeDifferent(answer_seconds_since_epoch, end_seconds_since_epoch).ToString();
                }

                catch (Exception e)
                {
                }
                finally
                {
                    outboundClient.session_params.Add("DialCallSid", bleg.Sid);
                    outboundClient.session_params.Add("DialCallDuration", duration_ms);
                    if (dial_rang == "true")
                    {
                        outboundClient.session_params.Add("DialCallStatus", CallStatus.completed);
                    }
                    else
                    {
                        outboundClient.session_params.Add("DialCallStatus", CallStatus.failed);
                    }
                }
            }

            //If record is specified
            if (record)
            {
                outboundClient.session_params.Add("RecordingUrl", "");
            }

            if (!string.IsNullOrEmpty(action) && Util.IsValidUrl(action) && !string.IsNullOrEmpty(method))
            {
                Task.Factory.StartNew(() => FetchNextAgbaraRespone(action, outboundClient.session_params, method));
            }
        }
Esempio n. 27
0
 public override void Execute(FSOutbound outboundClient)
 {
     outboundClient.sleep((length * 1000).ToString(), outboundClient.get_channel_unique_id(), false);
     var evnt = outboundClient.ActionReturnedEvent();
 }
Esempio n. 28
0
        private List <string> _prepare_play_string(FSOutbound outboundClient, string remote_url)
        {
            List <string> sound_files = new List <string>();

            if (!string.IsNullOrEmpty(remote_url))
            {
                return(sound_files);
            }
            try
            {
                string   response = outboundClient.SendToUrl(remote_url, outboundClient.session_params, this.method);
                XElement doc      = XElement.Load(response);
                if (doc.Name != "Response")
                {
                    return(sound_files);
                }

                // build play string from remote restxml
                foreach (XElement ele in doc.Nodes())
                {
                    //Play element
                    if (ele.Name == "Play")
                    {
                        var child = new Play();
                        child.ParseElement(ele);
                        string sound_file = child.SoundFilePath;
                        if (!string.IsNullOrEmpty(sound_file))
                        {
                            var loop = child.LoopTimes;
                            if (loop == 0)
                            {
                                loop = 1000;  // Add a high number to Play infinitely
                            }
                            // Play the file loop number of times
                            for (int i = 1; i < loop; i++)
                            {
                                sound_files.Add(sound_file);
                            }
                            //Infinite Loop, so ignore other children
                            if (loop == 1000)
                            {
                                break;
                            }
                        }
                    }
                    //Say element
                    else if (ele.Name == "Say")
                    {
                        var child = new Say();
                        child.ParseElement(ele);
                        var text = child.Text;
                        // escape simple quote
                        text = text.Replace("'", "\\'");
                        var loop    = child.loop_times;
                        var engine  = child.engine;
                        var voice   = child.voice;
                        var say_str = string.Format("say:{0}:{1}:'{2}'", engine, voice, text);
                        for (int i = 1; i < loop; i++)
                        {
                            sound_files.Add(say_str);
                        }
                    }
                    //Pause element
                    else if (ele.Name == "Pause")
                    {
                        var child = new Pause();
                        child.ParseElement(ele);
                        var    pause_secs = child.length;
                        string pause_str  = string.Format("file_string://silence_stream://{0}", (pause_secs * 1000));
                        sound_files.Add(pause_str);
                    }
                }
            }
            catch (Exception e)
            {
            }
            return(sound_files);
        }
Esempio n. 29
0
        public override void Execute(FSOutbound outboundClient)
        {
            string recordingPath = "";
            AppSettingsReader reader = new AppSettingsReader();
            recordingPath = (string)reader.GetValue("RecordingDirectory", recordingPath.GetType());
            Event evnt = null;

            if (play_beep == "true")
            {
                string beep = "tone_stream://%(300,200,700)";
                outboundClient.playback(beep);
                var retEvnt = outboundClient.ActionReturnedEvent();
            }
            string record_file = string.Format("{0}{1}.wav", recordingPath, outboundClient.CallSid);
            outboundClient.start_dtmf();
            outboundClient.record(record_file, max_length.ToString(), silence_threshold.ToString(), timeout.ToString(), finish_on_key);
            evnt = outboundClient.ActionReturnedEvent();
            outboundClient.stop_dtmf();

            //Otherwise, continue to next Element
            if (!string.IsNullOrEmpty(action) && Util.IsValidUrl(action))
            {
                outboundClient.session_params["RecordUrl"] = record_file;

                int record_ms;
                try
                {
                    var duration = evnt.GetHeader("variable_record_ms");
                    if (string.IsNullOrEmpty(duration))
                        record_ms = 0;
                    else
                        record_ms = int.Parse(duration);
                }
                catch (Exception ex)
                {
                    record_ms = 0;
                }
                outboundClient.session_params["RecordingDuration"] = record_ms;
                string record_digits = evnt.GetHeader("variable_playback_terminator_used");
                if (!string.IsNullOrEmpty(record_digits))
                    outboundClient.session_params["Digits"] = record_digits;
                else
                    outboundClient.session_params["Digits"] = "hangup";

                //save recording
                Recording record = new Recording();
                record.AccountSid = outboundClient.AccountSid;
                record.CallSid = outboundClient.CallSid;
                record.Duration = record_ms;
                record.RecordUrl = record_file;
                try
                {
                    recoSvc.CreateRecording(record);

                }
                catch (Exception ex)
                {
                    //log
                }

                // fetch xml
                FetchNextAgbaraRespone(action, outboundClient.session_params, method);

            }
        }
Esempio n. 30
0
        public override void Execute(FSOutbound outboundClient)
        {
            List <string> flags = new List <string>();

            //settings for conference room
            outboundClient.set("conference_controls=none");
            if (max_members > 0)
            {
                outboundClient.set(string.Format("max-members={0}", max_members));
            }
            else
            {
                outboundClient.unset("max-members");
            }


            //set moh sound
            List <string> mohs = _prepare_moh(outboundClient);

            if (mohs.Count > 0)
            {
                outboundClient.set("playback_delimiter=!");
                string play_str = string.Join("!", mohs);
                play_str = string.Format("file_string://silence_stream://1!{0}", play_str);
                outboundClient.set(string.Format("conference_moh_sound={0}", play_str));
            }
            else
            {
                outboundClient.unset("conference_moh_sound");
            }
            //set member flags
            if (muted)
            {
                flags.Add("muted");
            }
            if (StartOnEnter)
            {
                flags.Add("moderator");
            }
            else
            {
                flags.Add("wait-mod");
            }
            if (EndOnExit)
            {
                flags.Add("endconf");
            }
            string flags_opt = string.Join(",", flags);

            if (!string.IsNullOrEmpty(flags_opt))
            {
                outboundClient.set(string.Format("conference_member_flags={0}", flags_opt));
            }
            else
            {
                outboundClient.unset("conference_member_flags");
            }

            outboundClient.set(string.Format("agabara_confid={0}", 2333333));
            outboundClient.set(string.Format("agabara_memberid={0}", 45555));
            //really enter conference room
            var res = outboundClient.conference(full_room, outboundClient.get_channel_unique_id(), true);

            if (!res.IsReplyTextSuccess())
            {
                //error creating conference
                return;
            }
            //Console.WriteLine(""
            // get next event
            var evnt = outboundClient.ActionReturnedEvent();

            try
            {
                string digit_realm = "";

                //set hangup on star
                if (hangup_on_star)
                {
                    // create event template
                    string raw_event = string.Format("Event-Name=CUSTOM,Event-Subclass=conference::maintenance,Action=kick,Unique-ID={0},Member-ID={1},Conference-Name={2},Conference-Unique-ID={3}", outboundClient.get_channel_unique_id(), member_id, room, conf_id);
                    digit_realm = string.Format("agbara_bda_{0}", outboundClient.get_channel_unique_id());
                    string cmd = string.Format("{0},*,exec:event,'{1}'", digit_realm, raw_event);
                    outboundClient.bind_digit_action(cmd);
                }


                //play beep on enter if enabled
                if (!string.IsNullOrEmpty(member_id) && beep)
                {
                    if (enter_sound == "beep:1")
                    {
                        outboundClient.BgAPICommand(string.Format("conference {0} play tone_stream://%%(300,200,700) async", room));
                    }
                    else if (enter_sound == "beep:2")
                    {
                        outboundClient.BgAPICommand(string.Format("conference {0} play tone_stream://L=2;%%(300,200,700) async", room));
                    }
                }

                // wait conference ending for this member
                var ret = outboundClient.ActionReturnedEvent();

                //play beep on exit if enabled
                if (!string.IsNullOrEmpty(member_id))
                {
                    if (exit_sound == "beep:1")
                    {
                        outboundClient.APICommand(string.Format("conference {0} play tone_stream://%%(300,200,700) async", room));
                    }
                    else if (exit_sound == "beep:2")
                    {
                        outboundClient.APICommand(string.Format("conference {0} play tone_stream://L=2;%%(300,200,700) async", room));
                    }
                }
                //unset digit realm
                if (!string.IsNullOrEmpty(digit_realm))
                {
                    outboundClient.clear_digit_action(digit_realm);
                }
            }
            catch (Exception ex)
            {
            }

            finally
            {
                //notify channel has left room
                // _notify_exit_conf(outboundClient);
                //If action is set, redirect to this url, Otherwise, continue to next Element
                //if (!string.IsNullOrEmpty(action) && outboundClient.is_valid_url(action))
                //{
                //    Hashtable param = new Hashtable();
                //    param["ConferenceName"] = room;
                //    param["ConferenceUUID"] = conf_id;
                //    param["ConferenceMemberID"] = member_id;
                //    //if (!string.IsNullOrEmpty(record_file))
                //    //{
                //    //    param["RecordFile"] = record_file;
                //    //    FetchNextAgbaraRespone(action, param, method);
                //    //}
                //}
            }
        }