Example #1
0
        private void AriClient_OnChannelHangupRequestEvent(IAriClient sender, ChannelHangupRequestEvent e)
        {
            string callerId = e.Channel.Caller.Number;

            numbers.Remove(callerId);

            if (!String.IsNullOrEmpty(e.Channel.Id))
            {
                dtmfs.Remove(e.Channel.Id);
            }
            else
            {
                var keys = dtmfs.Keys;
                foreach (var item in keys)
                {
                    DtmfItem dtmfItem;
                    dtmfs.TryGetValue(item, out dtmfItem);
                    if (dtmfItem != null)
                    {
                        if (dtmfItem.channel.Caller.Number == callerId)
                        {
                            dtmfs.Remove(item);
                        }
                    }
                }
            }
        }
Example #2
0
        private async void AriClientOnStasisStartEvent(IAriClient sender, StasisStartEvent e)
        {
            ICall line;

            if (e.Args.Contains("dialed") || e.Args.Contains("SnoopChannel"))
            {
                return;
            }
            _logger.Info("Line Offhook", new
            {
                ChannelId      = e.Channel.Id,
                CallerIdName   = e.Channel.Caller.Number,
                CallerIdNumber = e.Channel.Caller.Name
            });
            line = ArkeCallFactory.CreateArkeCall(e.Channel);
            ConnectedLines.Add(e.Channel.Id, line);
            _logger.Info("Starting Call Script", new
            {
                ChannelId = e.Channel.Id
            });

            // call answered and started
            await line.RunCallScript();

            _logger.Info("Call Script Complete", new { ChannelId = e.Channel.Id });
        }
Example #3
0
        private void Pbx_OnPeerStatusChangeEvent(IAriClient sender, AsterNET.ARI.Models.PeerStatusChangeEvent e)
        {
            lock (_locker)
            {
                Device device      = deviceCache.GetDeviceById(e.Endpoint.Technology + "/" + e.Endpoint.Resource);
                string destination = "SIP/";
                if (device != null)
                {
                    if (!String.IsNullOrEmpty(e.Peer.Address))
                    {
                        destination += e.Peer.Address + "/" + e.Endpoint.Resource;
                        //Solo actualizo si cambió el contact
                        if (device.Contact != destination)
                        {
                            device.Contact = destination;
                            //solo envio mensaje al calldistributor si el device posee un agente
                            if (!String.IsNullOrEmpty(device.MemberId))
                            {
                                this.actorStateProxy.Send(new MessageDeviceStateChanged()
                                {
                                    From = source, DeviceId = device.Id, MemberId = device.MemberId, IsInUse = device.IsInUse, IsOffline = device.IsOffline, Contact = device.Contact
                                });
                            }
                        }
                    }

                    device.EndpointState = e.Peer.Peer_status;
                    Log.Logger.Debug("ESTADO " + device.Id + " PEER:" + device.DeviceState + " Endpoint: " + device.EndpointState);
                }
            }
        }
Example #4
0
 private void AriClient_OnStasisEndEvent(IAriClient sender, AsterNET.ARI.Models.StasisEndEvent e)
 {
     OnLineHangupEvent?.Invoke(this, new LineHangupEvent()
     {
         LineId = e.Channel.Id
     });
 }
Example #5
0
        private async void AriClientOnStasisStartEvent(IAriClient sender, StasisStartEvent e)
        {
            _logger.Debug($"Line Connecting: {e.Channel.Name}");

            if (e.Args.Contains("dialed") || e.Args.Contains("SnoopChannel"))
            {
                return;
            }
            _logger.Information("Line Offhook", new
            {
                ChannelId      = e.Channel.Id,
                CallerIdName   = e.Channel.Caller.Number,
                CallerIdNumber = e.Channel.Caller.Name
            });
            var line = ArkeCallFactory.CreateArkeCall(e.Channel);

            ConnectedLines.Add(e.Channel.Id, line);
            _logger.Information("Starting Call Script", new
            {
                ChannelId = e.Channel.Id
            });

            // call answered and started
            await line.RunCallScriptAsync(_cancellationToken);

            await Task.Delay(1000, _cancellationToken);

            _logger.Information("Call Script Complete", new { ChannelId = e.Channel.Id });
        }
Example #6
0
        private void Pbx_OnChannelStateChangeEvent(IAriClient sender, ChannelStateChangeEvent e)
        {
            ProtocolMessages.Message msg = null;
            //track channel state changes
            try
            {
                lock (_locker)
                {
                    msg = callHandlerCache.GetByChannelId(e.Channel.Id).ChannelStateChangedEvent(e.Channel.Id, e.Channel.State);
                }
                if (msg != null)
                {
                    actorPbxProxy.Send(msg);
                }
                else
                {
                    Log.Logger.Debug("Channel State Change: " + e.Channel.Id + " el callhandler devolvió msg = null");
                }
            }
            catch (Exception ex)
            {
                Log.Logger.Debug("ERROR!!: Pbx_OnChannelStateChangeEvent chan:" + e.Channel.Id + ", error: " + ex.Message);
            }

            //log to console
            Log.Logger.Debug("El canal: " + e.Channel.Id + " cambio su estado a: " + e.Channel.State.ToString());
        }
        private async void AriClientOnStasisStartEvent(IAriClient sender, StasisStartEvent e)
        {
            var   callScope = Tracer.Instance.StartActive("NewCall");
            ICall line;

            using (var answerScope = Tracer.Instance.StartActive("AnswerCall"))
            {
                if (e.Args.Contains("dialed") || e.Args.Contains("SnoopChannel"))
                {
                    return;
                }
                callScope.Span.SetTag("ChannelId", e.Channel.Id);
                _logger.Info("Line Offhook", new
                {
                    ChannelId      = e.Channel.Id,
                    CallerIdName   = e.Channel.Caller.Number,
                    CallerIdNumber = e.Channel.Caller.Name
                });
                line = ArkeCallFactory.CreateArkeCall(e.Channel, callScope);
                ConnectedLines.Add(e.Channel.Id, line);
                _logger.Info("Starting Call Script", new
                {
                    ChannelId = e.Channel.Id
                });
            }
            // call answered and started
            await line.RunCallScript();

            _logger.Info("Call Script Complete", new { ChannelId = e.Channel.Id });
            callScope.Close();
        }
Example #8
0
 private void AriClient_OnPlaybackFinishedEvent(IAriClient sender, AsterNET.ARI.Models.PlaybackFinishedEvent e)
 {
     OnPromptPlaybackFinishedEvent?.Invoke(this, new PromptPlaybackFinishedEvent()
     {
         PlaybackId = e.Playback.Id
     });
 }
Example #9
0
        private void Pbx_OnChannelDestroyedEvent(IAriClient sender, ChannelDestroyedEvent e)
        {
            ProtocolMessages.Message msg = null;
            try
            {
                lock (_locker)
                {
                    //si aun existe el callhandler manejo el evento
                    if (callHandlerCache.GetByChannelId(e.Channel.Id) != null)
                    {
                        msg = callHandlerCache.GetByChannelId(e.Channel.Id).ChannelDestroyEvent(e.Channel.Id, e.Cause, e.Cause_txt);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Logger.Debug("Error en Pbx_OnChannelDestroyedEvent - " + ex.Message);
            }

            if (msg != null)
            {
                actorPbxProxy.Send(msg);
            }
            else
            {
                Log.Logger.Debug("Channel Destroy: " + e.Channel.Id + " el callhandler devolvió msg = null");
            }
            lock (_locker)
            {
                callHandlerCache.RemoveChannel(e.Channel.Id);
            }
            Log.Logger.Debug("Channel Destroy: " + e.Channel.Id + " remuevo channel del callhandler");
        }
Example #10
0
        private void Pbx_OnChannelUnholdEvent(IAriClient sender, ChannelUnholdEvent e)
        {
            ProtocolMessages.Message msg = null;
            try
            {
                lock (_locker)
                {
                    msg = callHandlerCache.GetByChannelId(e.Channel.Id).ChannelUnHoldEvent(e.Channel.Id);
                }
            }
            catch (Exception ex)
            {
                Log.Logger.Debug("Channel UnHold: ERROR " + ex.Message + "\n" + ex.StackTrace);
            }

            if (msg != null)
            {
                actorPbxProxy.Send(msg);
            }
            else
            {
                Log.Logger.Debug("Channel UnHold: " + e.Channel.Id + " el callhandler devolvió msg = null");
            }
            Log.Logger.Debug("Channel UnHold: " + e.Channel.Id);
        }
Example #11
0
 private void Pbx_OnBridgeAttendedTransferEvent(IAriClient sender, BridgeAttendedTransferEvent e)
 {
     ProtocolMessages.Message msg = null;
     lock (_locker)
     {
         //Este evento trae muchisima info, requiere de mayor estudio/prueba
         //ver como queda el canal del caller, seguro hay un rename por ahi
         CallHandler callHandler = callHandlerCache.GetByChannelId(e.Transferee.Id);
         if (callHandler == null)
         {
             callHandler = callHandlerCache.GetByChannelId(e.Transfer_target.Id);
         }
         if (callHandler != null)
         {
             msg = callHandler.AttendedTransferEvent(e.Transferee, e.Transfer_target);
         }
     }
     //Mando el mensaje
     if (msg != null)
     {
         actorPbxProxy.Send(msg);
     }
     else
     {
         Log.Logger.Debug("AttTransfer devolvió msg = null");
     }
 }
Example #12
0
 private void Pbx_OnBridgeBlindTransferEvent(IAriClient sender, BridgeBlindTransferEvent e)
 {
     ProtocolMessages.Message msg = null;
     lock (_locker)
     {
         CallHandler callHandler = callHandlerCache.GetByChannelId(e.Transferee.Id);
         if (callHandler == null)
         {
             callHandler = callHandlerCache.GetByChannelId(e.Replace_channel.Id);
         }
         if (callHandler != null)
         {
             msg = callHandler.AttendedTransferEvent(e.Transferee, e.Replace_channel);
         }
     }
     //Mando el mensaje
     if (msg != null)
     {
         actorPbxProxy.Send(msg);
     }
     else
     {
         Log.Logger.Debug("UnAttTransfer devolvió msg = null");
     }
 }
Example #13
0
        private static void c_OnStasisStartEvent(IAriClient sender, StasisStartEvent e)
        {
			// Answer the channel
			sender.Channels.Answer(e.Channel.Id);

			// Play an announcement
			sender.Channels.Play(e.Channel.Id, "sound:hello-world");
        }
 /// <summary>
 /// Конструктор для UnitTests
 /// Позволяет передать AriClient
 /// </summary>
 /// <param name="logger"></param>
 /// <param name="commandFactory"></param>
 /// <param name="ariClient"></param>
 public AsteriskAriWebSocketService(
     ILogger logger,
     CommandFactory commandFactory,
     IAriClient ariClient
     ) : this(logger, commandFactory)
 {
     _ariClient = new AsteriskAriClient(logger, ariClient);
 }
Example #15
0
        private static void c_OnStasisStartEvent(IAriClient sender, StasisStartEvent e)
        {
            // Answer the channel
            sender.Channels.Answer(e.Channel.Id);

            // Play an announcement
            sender.Channels.Play(e.Channel.Id, "sound:hello-world");
        }
Example #16
0
 public ArkeCallFlowService(ILogger logger, IAriClient ariClient, ISipApiClient sipApi)
 {
     _logger = logger;
     _logger.Information("ArkeCallFlowService Created");
     ConnectedLines = new Dictionary <string, ICall>();
     _ariClient     = ariClient;
     _sipApi        = sipApi;
 }
Example #17
0
 private void AriClient_OnChannelDtmfReceivedEvent(IAriClient sender, AsterNET.ARI.Models.ChannelDtmfReceivedEvent e)
 {
     OnDtmfReceivedEvent?.Invoke(this, new DtmfReceivedEvent()
     {
         Digit = e.Digit,
         DurationInMilliseconds = e.Duration_ms,
         LineId = e.Channel.Id
     });
 }
Example #18
0
        public ArkeCallFlowService()

        {
            _logger.Info("ArkeCallFlowService Created");
            ConnectedLines           = new Dictionary <string, ICall>();
            _cancellationTokenSource = new CancellationTokenSource();
            _ariClient = ObjectContainer.GetInstance().GetObjectInstance <IAriClient>();
            _sipApi    = ObjectContainer.GetInstance().GetObjectInstance <ArkeSipApiClient>();
        }
 private void ARIClient_internalEvent(IAriClient sender, Event e)
 {
     try
     {
         Task.Run(() =>
         {
             FireEvent(e.Type, e, sender);
         });
     }catch (Exception ex)
     {
         Debug.WriteLine("An Event Listener Threw Unhandled Exception: ", ex.Message);
     }
 }
        private static AsteriskAriApiService GetAsteriskAriApiService(IAriClient ariClient)
        {
            var channelRepositoryMock = new Mock <IChannelRepository>();

            channelRepositoryMock
            .Setup(x => x.GetChannelsByLineId(It.IsAny <Guid>()))
            .ReturnsAsync(new List <DAL.Entities.Channel>
            {
                new DAL.Entities.Channel
                {
                    BridgeId = "someBridgeId"
                }
            });

            channelRepositoryMock
            .Setup(x => x.GetChannelByCallId(It.IsAny <Guid>()))
            .ReturnsAsync(new DAL.Entities.Channel
            {
                BridgeId  = "someBridgeId",
                ChannelId = "0b279ab6-9738-4ea7-a0bc-72d757f7f72b"
            });

            channelRepositoryMock
            .Setup(x => x.GetMainBridgeId(It.IsAny <Guid>()))
            .ReturnsAsync("someBridgeId");

            channelRepositoryMock
            .Setup(x => x.GetChannelForMainUser(It.IsAny <Guid>()))
            .ReturnsAsync(new DAL.Entities.Channel
            {
                BridgeId = "someBridgeId"
            });

            var logger             = new Mock <ILogger>().Object;
            var channelRepository  = channelRepositoryMock.Object;
            var serviceProvider    = new Mock <IServiceProvider>().Object;
            var commandFactoryMock = new Mock <CommandFactory>(serviceProvider);
            var commandFactory     = commandFactoryMock.Object;

            var ariWebsocketService = new AsteriskAriWebSocketService(
                logger,
                commandFactory,
                ariClient
                );

            var ariApiService = new AsteriskAriApiService(logger, channelRepository, ariWebsocketService);

            return(ariApiService);
        }
Example #21
0
        private async void AriClientOnStasisEndEvent(IAriClient sender, StasisEndEvent stasisEndEvent)
        {
            _logger.Info(stasisEndEvent.Channel.Id);
            if (!ConnectedLines.ContainsKey(stasisEndEvent.Channel.Id))
            {
                return;
            }
            ConnectedLines[stasisEndEvent.Channel.Id].Hangup();

            while (!ConnectedLines[stasisEndEvent.Channel.Id].CallState.CallCanBeAbandoned)
            {
                await Task.Delay(1000);
            }
            ConnectedLines.Remove(stasisEndEvent.Channel.Id);
        }
Example #22
0
 private void Pbx_OnStasisEndEvent(IAriClient sender, StasisEndEvent e)
 {
     Log.Logger.Debug("El canal: " + e.Channel.Id + " salió de la app: " + e.Application);
     //uno de los dos cortó o por algun motivo se fue de stasis, transfer?? la cosa es que no estan mas en la app asi que los remuevo
     //aca debería ver el abandono, si sale de la app sin que lo atiendan abandonó?
     //TODO:Verificar el uso de este código, tal vez se pueda quitar
     lock (_locker)
     {
         CallHandler callHandler = callHandlerCache.GetByChannelId(e.Channel.Id);
         if (callHandler != null) //esto es en caso de que existan llamadas en stasis antes de arrancar la app, debería cargar la info de lo preexistente en la pbx
         {
             callHandlerCache.RemoveCallHandler(callHandler.Id);
             Log.Logger.Debug("El canal: " + e.Channel.Id + ", remuevo el callhandler: " + callHandler.Id);
         }
     }
 }
Example #23
0
 private void Pbx_OnDeviceStateChangedEvent(IAriClient sender, AsterNET.ARI.Models.DeviceStateChangedEvent e)
 {
     Log.Logger.Debug("ESTADO el device:" + e.Device_state.Name + " esta en:" + e.Device_state.State);
     lock (_locker)
     {
         Device device = deviceCache.UpdateDeviceState(e.Device_state.Name, e.Device_state.State);
         //solo envio mensaje al calldistributor si el device posee un agente
         if (device != null && !String.IsNullOrEmpty(device.MemberId))
         {
             this.actorStateProxy.Send(new MessageDeviceStateChanged()
             {
                 From = source, DeviceId = device.Id, MemberId = device.MemberId, IsInUse = device.IsInUse, IsOffline = device.IsOffline, Contact = device.Contact
             });
         }
     }
 }
Example #24
0
        private static void ActionClientOnChannelDtmfReceivedEvent(IAriClient sender, ChannelDtmfReceivedEvent e)
        {
            // When DTMF received
            switch (e.Digit)
            {
                case "*":
                    sender.Channels.Play(e.Channel.Id, "sound:asterisk-friend");
                    break;
                case "#":
					sender.Channels.Play(e.Channel.Id, "sound:goodbye");
					sender.Channels.Hangup(e.Channel.Id, "normal");
                    break;
                default:
					sender.Channels.Play(e.Channel.Id, string.Format("sound:digits/{0}", e.Digit));
                    break;
            }
        }
Example #25
0
 private void Client_OnStasisEndEvent(IAriClient sender, StasisEndEvent e)
 {
     if (callerRegistry.ContainsKey(e.Channel.Id))
     {
         Caller c = callerRegistry[e.Channel.Id];
         Logger.Log(c, "Caller hungup.");
         CallerEnd?.Invoke(this, c);
         callerRegistry.Remove(e.Channel.Id);
         return;
     }
     if (DestinationRegistry.ContainsKey(e.Channel.Id))
     {
         DestinationEnd?.Invoke(this, DestinationRegistry[e.Channel.Id]);
         DestinationRegistry.Remove(e.Channel.Id);
         return;
     }
 }
        private void Start(StasisEndpoint endpoint)
        {
            try
            {
                _logger.Information("Starting Asterisk ARI!");

                var ariClient = new AriClient(endpoint, AppName);
                ariClient.OnConnectionStateChanged += AriClientOnConnectionStateChanged;
                ariClient.Connect();
                _ariClient    = ariClient;
                _endpointHost = endpoint.Host;
            }
            catch (HttpRequestException ex)
            {
                _logger.Error($"Ошибка подключения к Asterisk ARI. Host: {endpoint.Host}:{endpoint.Port}, Endpoint: {endpoint.AriEndPoint}", ex);
                throw;
            }
        }
        /// <summary>
        /// Подписка на событие ChannelUserEvent и обработка только SMS
        /// </summary>
        public void OnChannelUserEvent(IAriClient sender, ChannelUsereventEvent e)
        {
            if (!e.Eventname.ToLower().Equals("sms_received"))
            {
                _logger.Debug($"Пришло событие {e.Eventname}");
                return;
            }

            _logger.Debug($"UserEvent: {JsonConvert.SerializeObject(e.Userevent)}");

            ChannelUserEventDto deserializedUserEvent;

            try
            {
                deserializedUserEvent = JsonConvert.DeserializeObject <ChannelUserEventDto>(e.Userevent.ToString());
            }
            catch (Exception ex)
            {
                _logger.Warning($"Не удалось десериализовать {nameof(e.Userevent)} {e.Userevent}", ex);
                return;
            }

            if (string.IsNullOrEmpty(deserializedUserEvent.SenderExtension))
            {
                _logger.Warning("AsteriskAriSmsService. Sms не содежрит отправителя");
                return;
            }

            string messageBody;

            try
            {
                var bytes = Convert.FromBase64String(deserializedUserEvent.Body);
                messageBody = Encoding.UTF8.GetString(bytes, 0, bytes.Length);
                _logger.Debug($"SMS Body: {JsonConvert.SerializeObject(messageBody)}");
            }
            catch (Exception ex)
            {
                _logger.Warning("Ошибка конвертации sms body из base64", ex);
                return;
            }

            ProcessSms(messageBody, deserializedUserEvent.SenderExtension);
        }
Example #28
0
        private void Pbx_OnChannelHangupRequestEvent(IAriClient sender, ChannelHangupRequestEvent e)
        {
            ProtocolMessages.Message msg = null;
            try
            {
                lock (_locker)
                {
                    msg = callHandlerCache.GetByChannelId(e.Channel.Id).ChannelHangupEvent(e.Channel.Id, e.Cause, "");
                }
            }
            catch (Exception ex)
            {
                Log.Logger.Debug("Channel HangUpReques: ERROR " + ex.Message + "\n" + ex.StackTrace);
            }

            if (msg != null)
            {
                actorPbxProxy.Send(msg);
            }
            else
            {
                Log.Logger.Debug("Channel HangUpReques: " + e.Channel.Id + " el callhandler devolvió msg = null");
            }
            //TODO:Revisar este lock, verificar si lo que está adentro lo estoy ejecutando
            lock (_locker)
            {
                //si la llamada finalizó remuevo todo
                CallHandler callHandler = callHandlerCache.GetByChannelId(e.Channel.Id);
                if (callHandler != null && callHandler.IsCallTerminated())
                {
                    Log.Logger.Debug("Channel HangUpRequest: " + e.Channel.Id + ", call TERMINATED remuevo todo el callhandler: " + callHandler);
                    callHandlerCache.RemoveCallHandler(callHandler.Id);

                    Log.Logger.Debug("Channel HangUpRequest: el bridge: " + callHandler.Bridge.Id + " lo marco como free");
                    bridgesList.SetFreeBridge(callHandler.Bridge.Id);
                }
                else // hago lo mismo que el channel destroy
                {
                    callHandlerCache.RemoveChannel(e.Channel.Id);
                    Log.Logger.Debug("Channel HangUpRequest: " + e.Channel.Id + " remuevo channel del callhandler");
                }
            }
        }
Example #29
0
        private void AriClient_OnStasisStartEvent(IAriClient sender, StasisStartEvent e)
        {
            sender.Channels.Answer(e.Channel.Id);
            numbers.Add(e.Channel.Caller.Number, e.Channel.Id);
            ssso.OnValidateNumberBefore?.Invoke(new OnValidateNumberBeforeArgs(e.Channel));
            bool callerIdValidated = ssso.ValidateNumber(sender, e.Channel);

            ssso.OnValidateNumberAfter?.Invoke(new OnValidateNumberAfterArgs(e.Channel, callerIdValidated ? Constants.CallerIdValidated : Constants.CallerIdValidationError));
            if (!callerIdValidated)
            {
                ssso.OnAuthenticationFailed(new OnAuthenticationFailedArgs(e.Channel, Constants.CallerIdValidationError));
                Hangup(e.Channel);
                return;
            }

            DtmfItem dtmfItem = new DtmfItem(e.Channel, ssso.MaxWaitingTime.Value);

            dtmfs.Add(e.Channel.Id, dtmfItem);
        }
Example #30
0
        private static void ActionClientOnChannelDtmfReceivedEvent(IAriClient sender, ChannelDtmfReceivedEvent e)
        {
            // When DTMF received
            switch (e.Digit)
            {
            case "*":
                sender.Channels.Play(e.Channel.Id, "sound:asterisk-friend");
                break;

            case "#":
                sender.Channels.Play(e.Channel.Id, "sound:goodbye");
                sender.Channels.Hangup(e.Channel.Id, "normal");
                break;

            default:
                sender.Channels.Play(e.Channel.Id, string.Format("sound:digits/{0}", e.Digit));
                break;
            }
        }
Example #31
0
        private void Pbx_OnEndpointStateChangeEvent(IAriClient sender, AsterNET.ARI.Models.EndpointStateChangeEvent e)
        {
            Log.Logger.Debug("ESTADO el endpoint: " + e.Endpoint.Technology + "/" + e.Endpoint.Resource + " - tiene el estado: " + e.Endpoint.State + " - canales: " + e.Endpoint.Channel_ids.Count.ToString());
            string endpointId = e.Endpoint.Technology + "/" + e.Endpoint.Resource;

            lock (_locker)
            {
                Device device = deviceCache.UpdateEndpointState(endpointId, e.Endpoint.State);
                //solo envio mensaje al calldistributor si el device posee un agente
                if (!String.IsNullOrEmpty(device.MemberId))
                {
                    //TODO: verificar si enviar este mensaje es totalemente necesario
                    this.actorStateProxy.Send(new MessageDeviceStateChanged()
                    {
                        From = source, DeviceId = device.Id, MemberId = device.MemberId, IsInUse = device.IsInUse, IsOffline = device.IsOffline, Contact = device.Contact
                    });
                }
            }
        }
Example #32
0
        private void AriClient_OnChannelDtmfReceivedEvent(IAriClient sender, ChannelDtmfReceivedEvent e)
        {
            DtmfItem dtmfItem;

            dtmfs.TryGetValue(e.Channel.Id, out dtmfItem);
            if (dtmfItem != null)
            {
                dtmfItem.digits += e.Digit;

                if (dtmfItem.digits.Length == ssso.PinLength)
                {
                    ssso.OnValidatePinBefore?.Invoke(new OnValidatePinBeforeArgs(dtmfItem));
                    var pinValidated = ssso.ValidatePin(dtmfItem);
                    ssso.OnValidatePinAfter?.Invoke(new OnValidatePinAfterArgs(dtmfItem, pinValidated ? Constants.PinValidated : Constants.PinValidationError));
                    if (pinValidated)
                    {
                        ssso.OnAuthenticated(new OnAuthenticatedEventArgs(dtmfItem, Constants.Authenticated));
                        Hangup(dtmfItem.channel);
                        return;
                    }
                    if (dtmfItem.retryCount >= ssso.RetryCount)
                    {
                        ssso.OnAuthenticationFailed(new OnAuthenticationFailedArgs(e.Channel, Constants.AuthenticationFailed));
                        Hangup(e.Channel);
                    }
                    else
                    {
                        ssso.OnAuthenticationFailed(new OnAuthenticationFailedArgs(e.Channel, Constants.PleaseAgainTry));
                        dtmfItem.retryCount++;
                        dtmfItem.digits = "";
                    }
                    return;
                }

                dtmfs.Remove(e.Channel.Id);
                dtmfs.Add(e.Channel.Id, dtmfItem);
            }
        }
Example #33
0
 public Channels(IAriClient ariClient)
 {
     AriClient = ariClient;
 }
Example #34
0
 public Playbacks (IAriClient ariClient)
 {
     AriClient = ariClient;
 }
Example #35
0
 public Bridges(IAriClient ariClient)
 {
     AriClient = ariClient;
 }
Example #36
0
        protected void FireEvent(string eventName, object eventArgs, IAriClient sender)
        {
            switch (eventName)
            {


                case "ChannelCallerId":
                    if (OnChannelCallerIdEvent != null)
                        OnChannelCallerIdEvent(sender, (ChannelCallerIdEvent)eventArgs);
                    else if (OnUnhandledEvent != null) OnUnhandledEvent(sender, (Event)eventArgs);
                    break;


                case "ChannelDtmfReceived":
                    if (OnChannelDtmfReceivedEvent != null)
                        OnChannelDtmfReceivedEvent(sender, (ChannelDtmfReceivedEvent)eventArgs);
                    else if (OnUnhandledEvent != null) OnUnhandledEvent(sender, (Event)eventArgs);
                    break;


                case "BridgeCreated":
                    if (OnBridgeCreatedEvent != null)
                        OnBridgeCreatedEvent(sender, (BridgeCreatedEvent)eventArgs);
                    else if (OnUnhandledEvent != null) OnUnhandledEvent(sender, (Event)eventArgs);
                    break;


                case "ChannelCreated":
                    if (OnChannelCreatedEvent != null)
                        OnChannelCreatedEvent(sender, (ChannelCreatedEvent)eventArgs);
                    else if (OnUnhandledEvent != null) OnUnhandledEvent(sender, (Event)eventArgs);
                    break;


                case "ApplicationReplaced":
                    if (OnApplicationReplacedEvent != null)
                        OnApplicationReplacedEvent(sender, (ApplicationReplacedEvent)eventArgs);
                    else if (OnUnhandledEvent != null) OnUnhandledEvent(sender, (Event)eventArgs);
                    break;


                case "ChannelStateChange":
                    if (OnChannelStateChangeEvent != null)
                        OnChannelStateChangeEvent(sender, (ChannelStateChangeEvent)eventArgs);
                    else if (OnUnhandledEvent != null) OnUnhandledEvent(sender, (Event)eventArgs);
                    break;


                case "PlaybackFinished":
                    if (OnPlaybackFinishedEvent != null)
                        OnPlaybackFinishedEvent(sender, (PlaybackFinishedEvent)eventArgs);
                    else if (OnUnhandledEvent != null) OnUnhandledEvent(sender, (Event)eventArgs);
                    break;


                case "RecordingStarted":
                    if (OnRecordingStartedEvent != null)
                        OnRecordingStartedEvent(sender, (RecordingStartedEvent)eventArgs);
                    else if (OnUnhandledEvent != null) OnUnhandledEvent(sender, (Event)eventArgs);
                    break;


                case "ChannelLeftBridge":
                    if (OnChannelLeftBridgeEvent != null)
                        OnChannelLeftBridgeEvent(sender, (ChannelLeftBridgeEvent)eventArgs);
                    else if (OnUnhandledEvent != null) OnUnhandledEvent(sender, (Event)eventArgs);
                    break;


                case "ChannelDestroyed":
                    if (OnChannelDestroyedEvent != null)
                        OnChannelDestroyedEvent(sender, (ChannelDestroyedEvent)eventArgs);
                    else if (OnUnhandledEvent != null) OnUnhandledEvent(sender, (Event)eventArgs);
                    break;


                case "DeviceStateChanged":
                    if (OnDeviceStateChangedEvent != null)
                        OnDeviceStateChangedEvent(sender, (DeviceStateChangedEvent)eventArgs);
                    else if (OnUnhandledEvent != null) OnUnhandledEvent(sender, (Event)eventArgs);
                    break;


                case "ChannelTalkingFinished":
                    if (OnChannelTalkingFinishedEvent != null)
                        OnChannelTalkingFinishedEvent(sender, (ChannelTalkingFinishedEvent)eventArgs);
                    else if (OnUnhandledEvent != null) OnUnhandledEvent(sender, (Event)eventArgs);
                    break;


                case "PlaybackStarted":
                    if (OnPlaybackStartedEvent != null)
                        OnPlaybackStartedEvent(sender, (PlaybackStartedEvent)eventArgs);
                    else if (OnUnhandledEvent != null) OnUnhandledEvent(sender, (Event)eventArgs);
                    break;


                case "ChannelTalkingStarted":
                    if (OnChannelTalkingStartedEvent != null)
                        OnChannelTalkingStartedEvent(sender, (ChannelTalkingStartedEvent)eventArgs);
                    else if (OnUnhandledEvent != null) OnUnhandledEvent(sender, (Event)eventArgs);
                    break;


                case "RecordingFailed":
                    if (OnRecordingFailedEvent != null)
                        OnRecordingFailedEvent(sender, (RecordingFailedEvent)eventArgs);
                    else if (OnUnhandledEvent != null) OnUnhandledEvent(sender, (Event)eventArgs);
                    break;


                case "BridgeMerged":
                    if (OnBridgeMergedEvent != null)
                        OnBridgeMergedEvent(sender, (BridgeMergedEvent)eventArgs);
                    else if (OnUnhandledEvent != null) OnUnhandledEvent(sender, (Event)eventArgs);
                    break;


                case "RecordingFinished":
                    if (OnRecordingFinishedEvent != null)
                        OnRecordingFinishedEvent(sender, (RecordingFinishedEvent)eventArgs);
                    else if (OnUnhandledEvent != null) OnUnhandledEvent(sender, (Event)eventArgs);
                    break;


                case "BridgeAttendedTransfer":
                    if (OnBridgeAttendedTransferEvent != null)
                        OnBridgeAttendedTransferEvent(sender, (BridgeAttendedTransferEvent)eventArgs);
                    else if (OnUnhandledEvent != null) OnUnhandledEvent(sender, (Event)eventArgs);
                    break;


                case "TextMessageReceived":
                    if (OnTextMessageReceivedEvent != null)
                        OnTextMessageReceivedEvent(sender, (TextMessageReceivedEvent)eventArgs);
                    else if (OnUnhandledEvent != null) OnUnhandledEvent(sender, (Event)eventArgs);
                    break;


                case "ChannelEnteredBridge":
                    if (OnChannelEnteredBridgeEvent != null)
                        OnChannelEnteredBridgeEvent(sender, (ChannelEnteredBridgeEvent)eventArgs);
                    else if (OnUnhandledEvent != null) OnUnhandledEvent(sender, (Event)eventArgs);
                    break;


                case "BridgeDestroyed":
                    if (OnBridgeDestroyedEvent != null)
                        OnBridgeDestroyedEvent(sender, (BridgeDestroyedEvent)eventArgs);
                    else if (OnUnhandledEvent != null) OnUnhandledEvent(sender, (Event)eventArgs);
                    break;


                case "BridgeBlindTransfer":
                    if (OnBridgeBlindTransferEvent != null)
                        OnBridgeBlindTransferEvent(sender, (BridgeBlindTransferEvent)eventArgs);
                    else if (OnUnhandledEvent != null) OnUnhandledEvent(sender, (Event)eventArgs);
                    break;


                case "ChannelUserevent":
                    if (OnChannelUsereventEvent != null)
                        OnChannelUsereventEvent(sender, (ChannelUsereventEvent)eventArgs);
                    else if (OnUnhandledEvent != null) OnUnhandledEvent(sender, (Event)eventArgs);
                    break;


                case "ChannelDialplan":
                    if (OnChannelDialplanEvent != null)
                        OnChannelDialplanEvent(sender, (ChannelDialplanEvent)eventArgs);
                    else if (OnUnhandledEvent != null) OnUnhandledEvent(sender, (Event)eventArgs);
                    break;


                case "ChannelHangupRequest":
                    if (OnChannelHangupRequestEvent != null)
                        OnChannelHangupRequestEvent(sender, (ChannelHangupRequestEvent)eventArgs);
                    else if (OnUnhandledEvent != null) OnUnhandledEvent(sender, (Event)eventArgs);
                    break;


                case "ChannelVarset":
                    if (OnChannelVarsetEvent != null)
                        OnChannelVarsetEvent(sender, (ChannelVarsetEvent)eventArgs);
                    else if (OnUnhandledEvent != null) OnUnhandledEvent(sender, (Event)eventArgs);
                    break;


                case "ChannelHold":
                    if (OnChannelHoldEvent != null)
                        OnChannelHoldEvent(sender, (ChannelHoldEvent)eventArgs);
                    else if (OnUnhandledEvent != null) OnUnhandledEvent(sender, (Event)eventArgs);
                    break;


                case "ChannelConnectedLine":
                    if (OnChannelConnectedLineEvent != null)
                        OnChannelConnectedLineEvent(sender, (ChannelConnectedLineEvent)eventArgs);
                    else if (OnUnhandledEvent != null) OnUnhandledEvent(sender, (Event)eventArgs);
                    break;


                case "ChannelUnhold":
                    if (OnChannelUnholdEvent != null)
                        OnChannelUnholdEvent(sender, (ChannelUnholdEvent)eventArgs);
                    else if (OnUnhandledEvent != null) OnUnhandledEvent(sender, (Event)eventArgs);
                    break;


                case "EndpointStateChange":
                    if (OnEndpointStateChangeEvent != null)
                        OnEndpointStateChangeEvent(sender, (EndpointStateChangeEvent)eventArgs);
                    else if (OnUnhandledEvent != null) OnUnhandledEvent(sender, (Event)eventArgs);
                    break;


                case "Dial":
                    if (OnDialEvent != null)
                        OnDialEvent(sender, (DialEvent)eventArgs);
                    else if (OnUnhandledEvent != null) OnUnhandledEvent(sender, (Event)eventArgs);
                    break;


                case "StasisEnd":
                    if (OnStasisEndEvent != null)
                        OnStasisEndEvent(sender, (StasisEndEvent)eventArgs);
                    else if (OnUnhandledEvent != null) OnUnhandledEvent(sender, (Event)eventArgs);
                    break;


                case "StasisStart":
                    if (OnStasisStartEvent != null)
                        OnStasisStartEvent(sender, (StasisStartEvent)eventArgs);
                    else if (OnUnhandledEvent != null) OnUnhandledEvent(sender, (Event)eventArgs);
                    break;
                default:
                    if (OnUnhandledEvent != null)
                        OnUnhandledEvent(this, (Event)eventArgs);
                    else if (OnUnhandledEvent != null) OnUnhandledEvent(sender, (Event)eventArgs);
                    break;
            }
        }
Example #37
0
 private void ActionClient_OnStasisStartEvent(IAriClient sender, AsterNET.ARI.Models.StasisStartEvent e)
 {
     throw new System.NotImplementedException();
 }