コード例 #1
0
ファイル: CallService.cs プロジェクト: seun104/AgbaraVOIP
        public Call AddCallLog(Call call)
        {
            try
            {
                callRepo.Add(call);
            }
            catch (Exception ex)
            {
                call = new Call();
            }

            return call;
        }
コード例 #2
0
ファイル: CallService.cs プロジェクト: seun104/AgbaraVOIP
        public Call UpdateCallLog(Call call)
        {
            using (callRepo.RequestStart())
            {

                try
                {
                    callRepo.Update(call);
                }
                catch (Exception ex)
                {
                    call = new Call();
                }
                return call;
            }
        }
コード例 #3
0
ファイル: CallService.cs プロジェクト: seun104/AgbaraVOIP
        public Call UpdateCallStatus(string CallSId, String Status)
        {
            using (callRepo.RequestStart())
            {
                var call = callRepo.GetSingle(a => a.Sid == CallSId);

                try
                {
                    call.Status = Status;
                    callRepo.Update(call);
                }
                catch (Exception ex)
                {
                    call = new Call();
                }
                return call;
            }
        }
コード例 #4
0
ファイル: ApiServer.cs プロジェクト: seun104/AgbaraVOIP
        private Request PrepareCallRequest( CallRequest request, out Call call)
        {
            call = new Call(){AccountSid=request.AccountSid, CallTo=request.To, AnswerUrl = request.AnswerUrl, Direction="outbound-api", CallerId=request.From, Timeout=request.TimeLimit};
            Queue<DialString> dialStrings = new Queue<DialString>();
            System.Text.StringBuilder args_list = new System.Text.StringBuilder();
            string sched_hangup_id = string.Empty;
            // don't allow "|" and "," in 'to' (destination) to avoid call injection
            request.To = request.To.Split(',', '|')[0];
            //set hangup_on_ring
            int hangup = 0;
            if (!int.TryParse(request.HangupOnRing, out hangup))
                hangup = -1;
            if (hangup == 0)
                args_list.Append("execute_on_ring='hangup ORIGINATOR_CANCEL',");
            else if (hangup > 0)
                args_list.Append(string.Format("execute_on_ring='sched_hangup +{0} ORIGINATOR_CANCEL',", hangup));
            // set send_digits
            if (!string.IsNullOrEmpty(request.SendDigits))
                args_list.Append(string.Format("execute_on_answer='send_dtmf {0}',", request.SendDigits));
            //set time_limit
            int time = 0;
            if (!int.TryParse(request.TimeLimit, out time))
                time = -1;
            if (time > 0)
            {
                //create sched_hangup_id
                sched_hangup_id = System.Guid.NewGuid().ToString();
                args_list.Append(string.Format("api_on_answer='sched_api {0} +{1} hupall ALLOTTED_TIMEOUT agbara_callSid {2}',", sched_hangup_id, request.TimeLimit, call.Sid));
                args_list.Append(string.Format("agbara_sched_hangup_id={0}", sched_hangup_id));
            }

            if (!string.IsNullOrEmpty(request.StatusCallbackUrl))
            {
                args_list.Append(string.Format("agbara_statuscallback_url={0},", request.StatusCallbackUrl));
                args_list.Append(string.Format("agbara_statuscallbackmethod={0},", request.StatusCallbackMethod));
            }

            if (!string.IsNullOrEmpty(request.FallbackUrl))
            {
                args_list.Append(string.Format("agbara_fallbackrul={0},", request.FallbackUrl));
                args_list.Append(string.Format("agbara_fallbackmethod={0},", request.FallbackMethod));
            }

            if (!string.IsNullOrEmpty(request.ApplicationSid))
            {
                args_list.Append(string.Format("agbara_applicationsid={0},", request.ApplicationSid));
            }

            args_list.Append(string.Format("agbara_callsid={0},", call.Sid));
            args_list.Append(string.Format("agbara_accountsid={0},", call.AccountSid));
            args_list.Append(string.Format("agbara_answer_url={0},", request.AnswerUrl));

            args_list.Append(string.Format("origination_caller_id_number={0},", request.From));

            //session_heartbeat
            args_list.Append(string.Format("enable_heartbeat_events={0},", 60));
            //Set Direction
            args_list.Append(string.Format("agbara_call_direction={0}", CallDirection.outboundapi));

            foreach (Gateway gate in _fsService.GetGatewaysForNumber(call.CallTo,FS.Sid))
            {
                for (int i = 1; i < int.Parse(gate.GatewayRetry); i++)
                {
                    DialString dialString = new DialString(call.Sid, request.To, gate.GatewayString, gate.GatewayCodec, gate.GatewayTimeout.ToString(), args_list.ToString());
                    dialStrings.Enqueue(dialString);
                }
            }
            Request call_req = new Request(call.Sid, dialStrings, request.AnswerUrl, request.StatusCallbackUrl, request.StatusCallbackMethod);
            return call_req;
        }
コード例 #5
0
ファイル: Dial.cs プロジェクト: seun104/AgbaraVOIP
        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));
            }
        }
コード例 #6
0
ファイル: FSInbound.cs プロジェクト: seun104/AgbaraVOIP
 public void ON_CHANNEL_BRIDGE(Event ev)
 {
     var disposition = ev.GetHeader("variable_endpoint_disposition");
     if (disposition == "ANSWER")
     {
         var CallSid = ev.GetHeader("variable_agbara_callsid");
         CallElapsedTime[CallSid] = 0;
         Call call = new Call();
         //get call B Sid
         call.Sid = ev.GetHeader("variable_agbara_bleg_callsid");
         CallElapsedTime[call.Sid] = 0;
         call.Direction = CallDirection.outbounddial;
         call.Status = CallStatus.inprogress;
         try
         {
             callSrvc.AddCallLog(call);
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }