public HttpResponseMessage Wait(TwilioVoiceRequest request, [FromUri] Guid?callerId = null, [FromUri] int contactId = 0, [FromUri] string redirectTo = null)
        {
            try
            {
                request.AddAdditionalFields(callerId, contactId, redirectTo: redirectTo);
                if (Convert.ToInt32(request.QueueTime) == 0)
                {
                    var history = CallFromTwilioRequest(request);
                    history.ParentID = history.Id;
                    voipEngine.SaveOrUpdateCall(history);

                    var to = request.RedirectTo;
                    if (string.IsNullOrEmpty(to))
                    {
                        request.GetSignalRHelper().Enqueue(request.CallSid, callerId.HasValue ? callerId.Value.ToString() : "");
                    }
                    else
                    {
                        request.GetSignalRHelper().Incoming(request.CallSid, to);
                    }
                }

                return(GetHttpResponse(request.Wait()));
            }
            catch (Exception e)
            {
                Log.Error(e);
                throw;
            }
        }
Example #2
0
        private VoipCall SaveCall(TwilioVoiceRequest request, VoipCallStatus status, DaoFactory daoFactory)
        {
            var call = CallFromTwilioRequest(request);

            call.Status = status;
            return(daoFactory.VoipDao.SaveOrUpdateCall(call));
        }
Example #3
0
        public HttpResponseMessage Dequeue(TwilioVoiceRequest request, [FromUri] Guid?callerId = null, [FromUri] int contactId = 0, [FromUri] string reject = "")
        {
            try
            {
                using (var scope = DIHelper.Resolve())
                {
                    var voipEngine = new VoipEngine(scope.Resolve <DaoFactory>());
                    request.AddAdditionalFields(callerId, contactId, reject);

                    if (Convert.ToBoolean(request.Reject))
                    {
                        MissCall(request, voipEngine);
                        return(GetHttpResponse(request.Leave()));
                    }


                    voipEngine.AnswerCall(CallFromTwilioRequest(request));

                    return(GetHttpResponse(request.Dequeue()));
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
                throw;
            }
        }
        public HttpResponseMessage Dial(TwilioVoiceRequest request, [FromUri] Guid callerId, [FromUri] int contactId = 0, [FromUri] string reject = null)
        {
            try
            {
                request.AddAdditionalFields(callerId, contactId, reject);

                var call = CallFromTwilioRequest(request);
                call = voipEngine.SaveOrUpdateCall(call);

                var parentCall = Global.DaoFactory.GetVoipDao().GetCall(call.ParentID);

                if (!string.IsNullOrEmpty(request.RecordingSid))
                {
                    if (parentCall.VoipRecord == null || string.IsNullOrEmpty(parentCall.VoipRecord.Id))
                    {
                        parentCall.VoipRecord = new VoipRecord {
                            Id = request.RecordingSid
                        };
                    }

                    Global.DaoFactory.GetVoipDao().SaveOrUpdateCall(parentCall);
                }

                voipEngine.SaveAdditionalInfo(parentCall.Id);

                return(GetHttpResponse(request.Dial()));
            }
            catch (Exception e)
            {
                Log.Error(e);
                throw;
            }
        }
        private VoipCall CallFromTwilioRequest(TwilioVoiceRequest request)
        {
            if (!string.IsNullOrEmpty(request.DialCallSid))
            {
                return(new VoipCall
                {
                    Id = request.DialCallSid,
                    ParentID = request.CallSid,
                    From = request.From,
                    To = request.To,
                    AnsweredBy = request.CallerId,
                    EndDialDate = DateTime.UtcNow
                });
            }

            return(new VoipCall
            {
                Id = request.CallSid,
                ParentID = request.ParentCallSid,
                From = request.From,
                To = request.To,
                AnsweredBy = request.CallerId,
                Date = DateTime.UtcNow,
                ContactId = request.ContactId
            });
        }
        private VoipCall SaveCall(TwilioVoiceRequest request, VoipCallStatus status)
        {
            var call = CallFromTwilioRequest(request);

            call.Status = status;
            return(Global.DaoFactory.GetVoipDao().SaveOrUpdateCall(call));
        }
Example #7
0
        private VoiceResponse Inbound(TwilioVoiceRequest request, DaoFactory daoFactory)
        {
            SecurityContext.AuthenticateMe(CoreContext.TenantManager.GetCurrentTenant().OwnerId);
            var call = SaveCall(request, VoipCallStatus.Incoming, daoFactory);

            return(request.Inbound(call, daoFactory));
        }
Example #8
0
        private VoiceResponse Outbound(TwilioVoiceRequest request, DaoFactory daoFactory)
        {
            SaveCall(request, VoipCallStatus.Outcoming, daoFactory);

            var history = CallFromTwilioRequest(request);

            history.ParentID = history.Id;
            new VoipEngine(daoFactory).SaveOrUpdateCall(history);

            return(request.Outbound());
        }
Example #9
0
 public HttpResponseMessage Redirect(TwilioVoiceRequest request, [FromUri] string redirectTo, [FromUri] Guid?callerId = null)
 {
     try
     {
         request.AddAdditionalFields(callerId, redirectTo: redirectTo);
         return(GetHttpResponse(request.Redirect()));
     }
     catch (Exception e)
     {
         Log.Error(e);
         throw;
     }
 }
Example #10
0
 public HttpResponseMessage GatherQueue(TwilioVoiceRequest request, [FromUri] Guid?callerId = null, [FromUri] int contactId = 0)
 {
     try
     {
         request.AddAdditionalFields(callerId, contactId);
         return(GetHttpResponse(request.GatherQueue()));
     }
     catch (Exception e)
     {
         Log.Error(e);
         throw;
     }
 }
        public HttpResponseMessage Client(TwilioVoiceRequest request, [FromUri] Guid callerId)
        {
            try
            {
                request.AddAdditionalFields(callerId);

                voipEngine.SaveOrUpdateCall(CallFromTwilioRequest(request));

                return(GetHttpResponse(new VoiceResponse()));
            }
            catch (Exception e)
            {
                Log.Error(e);
                throw;
            }
        }
 public HttpResponseMessage Index(TwilioVoiceRequest request, [FromUri] Guid?callerId = null, [FromUri] int contactId = 0)
 {
     try
     {
         lock (LockObj)
         {
             request.AddAdditionalFields(callerId, contactId);
             var response = request.IsInbound ? Inbound(request) : Outbound(request);
             return(GetHttpResponse(response));
         }
     }
     catch (Exception e)
     {
         Log.Error(e);
         throw;
     }
 }
        public HttpResponseMessage Enqueue(TwilioVoiceRequest request, [FromUri] Guid?callerId = null, [FromUri] int contactId = 0)
        {
            try
            {
                request.AddAdditionalFields(callerId, contactId);
                if (request.QueueResult != "bridged" && request.QueueResult != "redirected")
                {
                    MissCall(request);
                }

                return(GetHttpResponse(request.Enqueue(request.QueueResult)));
            }
            catch (Exception e)
            {
                Log.Error(e);
                throw;
            }
        }
Example #14
0
        public HttpResponseMessage Client(TwilioVoiceRequest request, [FromUri] Guid callerId)
        {
            try
            {
                using (var scope = DIHelper.Resolve())
                {
                    request.AddAdditionalFields(callerId);

                    new VoipEngine(scope.Resolve <DaoFactory>()).SaveOrUpdateCall(CallFromTwilioRequest(request));

                    return(GetHttpResponse(new VoiceResponse()));
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
                throw;
            }
        }
Example #15
0
        private void MissCall(TwilioVoiceRequest request, VoipEngine voipEngine)
        {
            var voipCall = CallFromTwilioRequest(request);

            voipCall.Status = VoipCallStatus.Missed;

            if (!string.IsNullOrEmpty(request.RecordingSid))
            {
                if (voipCall.VoipRecord == null || string.IsNullOrEmpty(voipCall.VoipRecord.Id))
                {
                    voipCall.VoipRecord = new VoipRecord {
                        Id = request.RecordingSid
                    };
                }
            }

            voipCall = voipEngine.SaveOrUpdateCall(voipCall);
            request.GetSignalRHelper().MissCall(request.CallSid, voipCall.AnsweredBy.ToString());
            voipEngine.SaveAdditionalInfo(voipCall.Id);
        }
Example #16
0
 public HttpResponseMessage Index(TwilioVoiceRequest request, [FromUri] Guid?callerId = null, [FromUri] int contactId = 0)
 {
     try
     {
         lock (LockObj)
         {
             using (var scope = DIHelper.Resolve())
             {
                 var daoFactory = scope.Resolve <DaoFactory>();
                 request.AddAdditionalFields(callerId, contactId);
                 var response = request.IsInbound ? Inbound(request, daoFactory) : Outbound(request, daoFactory);
                 return(GetHttpResponse(response));
             }
         }
     }
     catch (Exception e)
     {
         Log.Error(e);
         throw;
     }
 }
Example #17
0
        public HttpResponseMessage VoiceMail(TwilioVoiceRequest request, [FromUri] Guid?callerId = null, [FromUri] int contactId = 0)
        {
            try
            {
                using (var scope = DIHelper.Resolve())
                {
                    var daoFactory = scope.Resolve <DaoFactory>();
                    var voipEngine = new VoipEngine(daoFactory);
                    request.AddAdditionalFields(callerId, contactId);

                    MissCall(request, voipEngine);

                    return(GetHttpResponse(request.VoiceMail()));
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
                throw;
            }
        }
Example #18
0
        public HttpResponseMessage Enqueue(TwilioVoiceRequest request, [FromUri] Guid?callerId = null, [FromUri] int contactId = 0)
        {
            try
            {
                using (var scope = DIHelper.Resolve())
                {
                    var daoFactory = scope.Resolve <DaoFactory>();
                    var voipEngine = new VoipEngine(daoFactory);

                    request.AddAdditionalFields(callerId, contactId);
                    if (request.QueueResult != "bridged" && request.QueueResult != "redirected")
                    {
                        MissCall(request, voipEngine);
                    }

                    return(GetHttpResponse(request.Enqueue(request.QueueResult)));
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
                throw;
            }
        }