private async Task AriClient_OnPlaybackFinishedAsyncEvent(ISipApiClient sipApiClient, PromptPlaybackFinishedEvent e) { _call.Logger.Information("Playback finished {PlaybackId} {@Call}", e.PlaybackId, _call.CallState); AddPlaybackIdToLogData(e.PlaybackId); if (e.PlaybackId != _currentPlaybackId) { return; } if (_call.GetCurrentState() == State.InCall) { return; } await Task.Delay(TimeSpan.FromSeconds(5)); if (_call.CallState.Bridge.Id != _holdingBridge.Id) { return; } try { _currentPlaybackId = await _call.SipBridgingApi.PlayPromptToBridgeAsync(_call.CallState.Bridge.Id, _call.CallState.HoldPrompt, _call.CallState.LanguageCode); } catch (Exception exception) { _call.Logger.Warning(exception, "Think the call has probably hungup"); RemoveEventSubscriptions(); } _call.Logger.Information("Playback started {currentPlaybackId}, of prompt {HoldPrompt}, to bridge {BridgeName} {@Call}", _currentPlaybackId, _call.CallState.HoldPrompt, _call.CallState.Bridge.Name, _call.CallState); }
private void DTMF_ReceivedEvent(ISipApiClient sipApiClient, DtmfReceivedEvent e) { if (!LogData.ContainsKey(e.LineId)) { LogData.Add(e.LineId, _call.CallState.GetIncomingLineId()); } if (_call.CallState != null && e.LineId != _call.CallState.GetIncomingLineId()) { return; } try { if (_call.GetCurrentState() != State.LanguageInput && _call.GetCurrentState() != State.LanguagePrompts) { return; } if (_call.GetCurrentState() == State.LanguagePrompts) { _call.FireStateChange(Trigger.GetLanguageInput); } GetLanguageChoiceForDigit(e.Digit); _inputTimeout.Stop(); _call.Logger.Info("DTMF Event", LogData); GoToNextStep(); } catch (Exception ex) { _call.Logger.Error(ex, "DTMF Received event ", LogData); } }
public AsteriskLanguageSelectionPromptPlayer(ICall asteriskCall, ISipPromptApi sipPromptApi, ISipApiClient sipApiClient) { _asteriskCall = asteriskCall; _promptQueue = new Queue <IPrompt>(); _sipPromptApi = sipPromptApi; _sipApiClient = sipApiClient; _sipApiClient.OnPromptPlaybackFinishedEvent += HandlePromptFinishedEvent; }
public ArkeCallFlowService(ILogger logger, IAriClient ariClient, ISipApiClient sipApi) { _logger = logger; _logger.Information("ArkeCallFlowService Created"); ConnectedLines = new Dictionary <string, ICall>(); _ariClient = ariClient; _sipApi = sipApi; }
public async Task AriClient_OnPlaybackFinishedEvent(ISipApiClient sipApiClient, PromptPlaybackFinishedEvent e) { if (e.PlaybackId != _currentPlaybackId) { return; } if (_arkeCall.GetCurrentState() == State.StoppingPlayback) { return; } await _arkeCall.CallStateMachine.FireAsync( _promptQueue.Count == 0?Trigger.FinishedPrompt : Trigger.PlayNextPrompt); }
private async Task SipApiClientOnOnLineHangupEvent(ISipApiClient sender, LineHangupEvent e) { if (e.LineId != transferChannel.Id.ToString() && e.LineId != outboundLineId) { return; } if (e.LineId != transferChannel.Id.ToString()) { await _call.SipLineApi.HangupLineAsync(transferChannel.Id.ToString()); } _call.CallState.CallCanBeAbandoned = true; GoToNextStep(_call, _step); await _call.FireStateChange(Trigger.NextCallFlowStep); }
public ArkeCall(ISipApiClient sipApiClient, ISipLineApi sipLineApi, ISipBridgingApi sipBridgeApi, ISipPromptApi sipPromptApi, IRecordingManager recordingmanager) { _sipApiClient = sipApiClient; _sipLineApi = sipLineApi; _sipBridgeApi = sipBridgeApi; _logFields = new Dictionary <string, string>(); _promptPlayer = new ArkePromptPlayer(this, sipPromptApi); _asteriskPhoneInputHandler = new AsteriskPhoneInputHandler(this, _promptPlayer); _asteriskRecordingManager = recordingmanager; _dslProcessor = new DslProcessor(this); _arkeBridgeFactory = new ArkeBridgeFactory(_sipBridgeApi); _callStateMachine = new CallStateMachine(this, _promptPlayer); _callStateMachine.SetupFiniteStateMachine(); LanguageSelectionPromptPlayer = new AsteriskLanguageSelectionPromptPlayer(this, sipPromptApi, sipApiClient); }
private async Task AriClient_OnPlaybackFinishedEvent(ISipApiClient sipApiClient, PromptPlaybackFinishedEvent e) { LogData.Add("PlaybackId", e.PlaybackId); if (e.PlaybackId != _currentPlaybackId) { return; } await Task.Delay(TimeSpan.FromSeconds(5)); if (_call.GetCurrentState() != State.OnHold) { return; } _currentPlaybackId = await _call.SipBridgingApi.PlayPromptToBridge(_call.CallState.GetBridgeId(), HoldPrompt, "en"); _call.Logger.Info("Playback finished", LogData); }
private async Task SipApiClientOnOnLineHangupEvent(ISipApiClient sender, LineHangupEvent e) { if (e.LineId != _call.CallState.GetOutgoingLineId()) { return; } if (!_call.CallState.TalkTimeStart.HasValue) { _call.CallState.CallCanBeAbandoned = true; await _call.FireStateChange(Trigger.FinishCall); } else { // we're not on hold anymore, so we can just remove our events and continue _call.SipApiClient.OnPromptPlaybackFinishedAsyncEvent -= AriClient_OnPlaybackFinishedAsyncEvent; _call.OnWorkflowStep -= OnWorkflowStep; _call.SipApiClient.OnLineHangupAsyncEvent -= SipApiClientOnOnLineHangupEvent; } }
public async Task HandlePromptFinishedEvent(ISipApiClient sipApiClient, PromptPlaybackFinishedEvent e) { if (e.PlaybackId != _currentPlaybackId) { return; } if (_asteriskCall.GetCurrentState() == State.StoppingPlayback) { return; } if (_promptQueue.Count == 0) { if (_asteriskCall.GetCurrentState() != State.LanguageInput) { _asteriskCall.FireStateChange(Trigger.GetLanguageInput); } _stepProcessor.StartTimeoutTimer(); } else { await PlayNextPromptInQueue(); } }
public void AriClient_OnChannelDtmfReceivedEvent(ISipApiClient sipApiClient, DtmfReceivedEvent dtmfReceivedEvent) { DigitTimeoutTimer.Stop(); _call.Logger.Debug($"OnChannel Dtmf Received Event {dtmfReceivedEvent.LineId}"); if (_call.GetCurrentState() == State.LanguagePrompts) { return; } if (dtmfReceivedEvent.LineId != _call.CallState.GetIncomingLineId()) { return; } LogDtmfValue(dtmfReceivedEvent); CaptureDigitIfInValidState(dtmfReceivedEvent); if (_call.GetCurrentState() == State.PlayingInterruptiblePrompt) { _promptPlayer.StopPrompt(); } ProcessDigitsReceived(); }
public async void AriClient_OnChannelDtmfReceivedEvent(ISipApiClient sipApiClient, DtmfReceivedEvent dtmfReceivedEvent) { DigitTimeoutTimer.Stop(); if (_call.GetCurrentState() == State.LanguagePrompts) { return; } if (!ShouldProcessDigit(dtmfReceivedEvent)) { return; } _call.Logger.Debug($"OnChannel Dtmf Received Event {dtmfReceivedEvent.LineId}"); LogDtmfValue(dtmfReceivedEvent); CaptureDigitIfInValidState(dtmfReceivedEvent); if (_call.GetCurrentState() == State.PlayingInterruptiblePrompt) { await _promptPlayer.StopPromptAsync(); } await ProcessDigitsReceived(); }
public async Task AriClient_OnRecordingFinishedEvent(ISipApiClient sender, RecordingFinishedEventHandlerArgs args) { await _call.FireStateChange(Trigger.NextCallFlowStep); }