Esempio n. 1
0
 public void OnChannelHangupCompleteEvent(Event evt)
 {
     //   Capture Channel Hangup Complete
     this._hangup_cause = evt.GetHeader("Hangup-Cause");
     this.session_params["HangupCause"] = this._hangup_cause;
     this.session_params["CallStatus"] = CallStatus.completed;
     // Prevent command to be stuck while waiting response
     this._actionEventQueue.Add(new Event());
 }
Esempio n. 2
0
        public void OnCustomEvent(Event evt)
        {
            Console.WriteLine("Subclass {0}",evt.GetHeader("Event-Subclass"));
            Console.WriteLine("Action Performed {0}", evt.GetHeader("Action"));
            Console.WriteLine("Member Id {0}", evt.GetHeader("Member-ID"));
            // case conference event
            if(CurrentElement == "Conference")
            {
            //special case to get Member-ID for Conference
            if (evt.GetHeader("Event-Subclass") == "conference::maintenance" && evt.GetHeader("Action") == "add-member" && evt.GetHeader("Unique-ID") == channel_uuid)
            {
                Console.WriteLine("Subclass {0}", evt.GetHeader("Event-Subclass"));
                Console.WriteLine("Action Performed {0}", evt.GetHeader("Action"));
                Console.WriteLine("Member Id {0}", evt.GetHeader("Member-ID"));
               // this._actionEventQueue.Add(evt);
            }
            // special case for hangupOnStar in Conference
            else if(evt.GetHeader("Event-Subclass") == "conference::maintenance" && evt.GetHeader("Action") == "kick" && evt.GetHeader("Unique-ID") == channel_uuid)
            {
              string  room = evt.GetHeader("Conference-Name");
               string member_id = evt.GetHeader("Member-ID");
                if (!string.IsNullOrEmpty(room)&& !string.IsNullOrEmpty(member_id))
                {
                    BgAPICommand(string.Format("conference {0} kick {1}",room, member_id));
                }
            }
            // special case to send callback for Conference
            else if(evt.GetHeader("Event-Subclass") == "conference::maintenance" && evt.GetHeader("Action") == "digits-match" && evt.GetHeader("Unique-ID") == channel_uuid)
            {

                string digits_action = evt.GetHeader("Callback-Url");
                string digits_method = evt.GetHeader("Callback-Method");
                if (!string.IsNullOrEmpty(digits_action)&& !string.IsNullOrEmpty(digits_method))
                {
                    SortedList param = new SortedList();
                    param["ConferenceMemberID"] = evt.GetHeader("Member-ID");
                    param["ConferenceUUID"] = evt.GetHeader("Conference-Unique-ID");
                    param["ConferenceName"] = evt.GetHeader("Conference-Name");
                    param["ConferenceDigitsMatch"] = evt.GetHeader("Digits-Match");
                    param["ConferenceAction"] = "digits";
                    Task.Factory.StartNew(() => this.SendToUrl(digits_action, param, digits_method));
                }
            }
            }
            // case dial event
            else if(CurrentElement == "Dial")
            {
            if (evt.GetHeader("Event-Subclass") == "agbara::dial" && evt.GetHeader("Action") == "digits-match" && evt.GetHeader("Unique-ID") == channel_uuid)
            {
                string digits_action = evt.GetHeader("Callback-Url");
                string digits_method = evt.GetHeader("Callback-Method");
                if (!string.IsNullOrEmpty(digits_action)&& !string.IsNullOrEmpty(digits_method))
                {
                    SortedList param = new SortedList();
                    param["DialDigitsMatch"] = evt.GetHeader("Digits-Match");
                    param["DialAction"] = "digits";
                    param["DialALegUUID"] = evt.GetHeader("Unique-ID");
                    param["DialBLegUUID"] = evt.GetHeader("variable_bridge_uuid");
                    Task.Factory.StartNew(() => this.SendToUrl(digits_action, param, digits_method));
                }
            }
            }
        }
Esempio n. 3
0
        private void SetHangUpComplete(string CallSid, string call_uuid, string reason, Event ev, string hangup_url)
        {
            long answer_seconds_since_epoch = long.Parse(ev.GetHeader("Caller-Channel-Answered-Time"));
            long hangup_seconds_since_epoch = long.Parse(ev.GetHeader("Caller-Channel-Hangup-Time"));
            string called_num = ev.GetHeader("Caller-Destination-Number");
                string caller_num = ev.GetHeader("Caller-Caller-ID-Number");
            string direction = ev.GetHeader("variable_agbara_call_direction");
            //get call details
            Call call = callSrvc.GetCallDetail(CallSid);
            call.Status = CallStatus.completed;
            call.CallerId = caller_num;
            call.CallTo = called_num;
            call.DateUpdated = DateTime.Now;
            call.StartTime = EpochTimeConverter.ConvertFromEpochTime(answer_seconds_since_epoch);
            call.EndTime = EpochTimeConverter.ConvertFromEpochTime(hangup_seconds_since_epoch);
            call.Duration = EpochTimeConverter.GetEpochTimeDifferent(hangup_seconds_since_epoch, answer_seconds_since_epoch);
            call.Direction = direction;

             try
            {
                CallRequest.Remove(CallSid);
                CallElapsedTime.Remove(CallSid);
            }
            catch (Exception ex)
            {
            }

             try
             {
                 callSrvc.UpdateCallLog(call);
             }
             catch (Exception ex)
             {
             }
        }
Esempio n. 4
0
 //In order to "block" the execution of our service until the
 //command is finished, we use a synchronized queue from gevent
 //and wait for such event to come. The on_channel_execute_complete
 //method will put that event in the queue, then we may continue working.
 //However, other events will still come, like for instance, DTMF.
 public void OnChannelExecuteComplete(Event evt)
 {
     string app = evt.GetHeader("Application");
     if  (WAIT_FOR_ACTIONS.Contains(app))
     // If transfer has begun, put empty event to break current action
     if (evt.GetHeader("variable_agbara_transfer_progress") == "true")
     {
         this._actionEventQueue.Add(new Event());
     }
     else
     {
        this._actionEventQueue.Add(evt);
     }
 }
Esempio n. 5
0
 public void ON_CHANNEL_PROGRESS_MEDIA(Event ev)
 {
     Request call_req;
     string CallSid = ev.GetHeader("variable_agbara_CallSid");
     string direction = ev.GetHeader("Call-Direction");
     //Detect early media state
     if (!string.IsNullOrEmpty(CallSid) && direction == "outbound")
     {
         try
         {
             call_req = CallRequest[CallSid];
         }
         catch (Exception ex)
         {
             return;
         }
         // only send if not already ringing/early state
         if (string.IsNullOrEmpty(call_req.state_flag))
             //# set state flag to true
             call_req.state_flag = "EarlyMedia";
         // clear gateways to avoid retry
         call_req.gateways.Clear();
         string called_num = ev.GetHeader("Caller-Destination-Number");
         string caller_num = ev.GetHeader("Caller-Caller-ID-Number");
         // send ring if ring_url found
         string ring_url = call_req.ring_url;
         if (!string.IsNullOrEmpty(ring_url))
         {
             SortedList param = new SortedList();
             param.Add("RequestUUID", CallSid);
             param.Add("Direction", direction);
             param.Add("To", called_num);
             param.Add("CallStatus", "ringing");
             param.Add("From", caller_num);
             string response = Task<string>.Factory.StartNew(() => SendToUrl(ring_url, param, string.Empty)).Result;
         }
     }
 }
Esempio n. 6
0
        public void ON_SESSION_HEARTBEAT(Event ev)
        {
            //TODO
            //store in db

            long answer_seconds_since_epoch = long.Parse(ev.GetHeader("Caller-Channel-Answered-Time"));
            long heartbeat_seconds_since_epoch = long.Parse(ev.GetHeader("Event-Date-Timestamp"));
            int ElapsedTime = EpochTimeConverter.GetEpochTimeDifferent(heartbeat_seconds_since_epoch, answer_seconds_since_epoch);
            var BCallSid = ev.GetHeader("variable_agbara_bleg_callsid");
            var ACallSid = ev.GetHeader("variable_agbara_callsid");
            if (!string.IsNullOrEmpty(BCallSid))
            {
                int current = CallElapsedTime[BCallSid];
                CallElapsedTime[BCallSid] = current + ElapsedTime;
            }
            else if (!string.IsNullOrEmpty(ACallSid))
            {
                int current = CallElapsedTime[ACallSid];
                CallElapsedTime[ACallSid] = current + ElapsedTime;
            }

            //TODO
            //bill user real time here
        }
Esempio n. 7
0
 public void ON_CHANNEL_HANGUP_COMPLETE(Event ev)
 {
     Request call_req;
     string CallSid = ev.GetHeader("variable_agbara_callsid");
     string direction = ev.GetHeader("Call-Direction");
     if (!string.IsNullOrEmpty(CallSid) && direction != "outbound")
         return;
     string call_uuid = ev.GetHeader("Unique-ID");
     string reason = ev.GetHeader("Hangup-Cause");
     try
     {
         call_req = CallRequest[CallSid];
     }
     catch (Exception ex)
     {
         return;
     }
     // If there are gateways to try again, spawn originate
     if (call_req.gateways.Count > 0)
     {
         Originate(CallSid);
         return;
     }
     else // Else clean call request
     {
         string hangup_url = call_req.hangup_url;
         SetHangUpComplete(CallSid, call_uuid, reason, ev, hangup_url);
     }
 }
Esempio n. 8
0
 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;
         }
     }
 }
Esempio n. 9
0
 public void ON_CHANNEL_ANSWER(Event ev)
 {
     //Set up call elapsed
     var CallSid = ev.GetHeader("variable_agbara_callsid");
     CallElapsedTime[CallSid] = 0;
 }
Esempio n. 10
0
        public void ON_CALL_UPDATE(Event ev)
        {
            //A Leg from API outbound call answered
            var agbaraFlag = ev.GetHeader("variable_agbara_app");
            //TODO
            //agbaraflag

                var disposition = ev.GetHeader("variable_endpoint_disposition");
                if (disposition == "ANSWER")
                {
                    var CallSid = ev.GetHeader("variable_agbara_callsid");
                    CallElapsedTime[CallSid] = 0;
                }
        }
Esempio n. 11
0
        public void ON_BACKGROUND_JOB(Event ev)
        {
            Request call_req = new Request(null, null, null, null, null);

            string status = string.Empty;
            string reason = string.Empty;
            //Capture Job Event
            // Capture background job only for originate and ignore all other jobs
            string job_cmd = ev.GetHeader("Job-Command");
            string job_uuid = ev.GetHeader("Job-UUID");
            if (job_cmd == "originate" && string.IsNullOrEmpty(job_uuid))
            {
                try
                {
                    string data = ev.GetBody();
                    int pos = data.IndexOf(' ');
                    if (pos != -1)
                    {
                        status = data.Substring(0, pos).Trim();
                        reason = data.Substring(pos + 1).Trim();
                    }
                }
                catch (Exception ex)
                {
                    return;
                }
                string CallSid = BackgroundJobs[job_uuid];
                if (string.IsNullOrEmpty(CallSid))
                {
                    return;
                }
                try
                {
                    call_req = CallRequest[CallSid];
                }
                catch (Exception ex)
                {
                    return;
                }
                //Handle failure case of originate
                //This case does not raise a on_channel_hangup event.
                //All other failures will be captured by on_channel_hangup
                if (!status.Contains("OK"))
                    //In case ring/early state done, just warn releasing call request will be done in hangup event
                    if (call_req.state_flag == "Ringing" || call_req.state_flag == "EarlyMedia")
                    {
                        return;
                    }
                    //If no more gateways, release call request
                    else if (call_req.gateways.Count == 0)
                    {
                        //set an empty call_uuid
                        string call_uuid = "";
                        string hangup_url = call_req.hangup_url;
                        SetHangUpComplete(CallSid, call_uuid, reason, ev, hangup_url);
                        return;
                    }
                    //If there are gateways and call request state_flag is not set
                    //try again a call
                    else if (call_req.gateways.Count > 0)
                        Originate(CallSid);

            }
        }