/// <summary> /// add current responder to incident meeting as participant. /// </summary> private void TransferToIncidentMeeting() { Task.Run(async() => { try { var incidentMeetingCallId = statusData?.BotMeetingCallId; var responderStatusData = statusData?.GetResponder(responderId); if (incidentMeetingCallId != null && responderStatusData != null) { var addParticipantRequestData = new AddParticipantRequestData() { ObjectId = responderStatusData.ObjectId, ReplacesCallId = responderStatusData.NotificationCallId, }; await Bot.AddParticipantAsync(incidentMeetingCallId, addParticipantRequestData).ConfigureAwait(false); GraphLogger.Info("Finished to transfer to incident meeting. "); } else { GraphLogger.Warn( $"Tried to transfer to incident meeting but needed info are not valid. Meeting call-id: {incidentMeetingCallId}; status data: {responderStatusData}"); } } catch (Exception ex) { GraphLogger.Error(ex, "Failed to transfer to incident meeting."); throw; } }); }
/// <summary> /// Try to delete a call. /// </summary> /// <param name="callId">The call which will be deleted.</param> private void TryDeleteCall(string callId) { Task.Run(async() => { await Bot.TryDeleteCallAsync(callId).ConfigureAwait(false); GraphLogger.Info($"Try to delete call {callId}."); }); }
/// <summary> /// Subscribe to tone. /// </summary> private void SubscribeToTone() { Task.Run(async() => { try { await Call.SubscribeToToneAsync().ConfigureAwait(false); GraphLogger.Info("Started subscribing to tone."); } catch (Exception ex) { GraphLogger.Error(ex, "Failed to subscribe to tone. "); throw; } }); }
/// <summary> /// Play the notification prompt. /// </summary> private void PlayNotificationPrompt() { Task.Run(async() => { try { await Call.PlayPromptAsync(new List <MediaPrompt> { Bot.MediaMap[Bot.NotificationPromptName] }).ConfigureAwait(false); GraphLogger.Info("Started playing notification prompt"); } catch (Exception ex) { GraphLogger.Error(ex, "Failed to play notification prompt."); throw; } }); }
/// <summary> /// Play the notification prompt. /// </summary> private void PlayNotificationPrompt() { Task.Run(async() => { try { var mediaName = endpointId == null ? Bot.BotIncomingPromptName : Bot.BotEndpointIncomingPromptName; await Call.PlayPromptAsync(new List <MediaPrompt> { Bot.MediaMap[mediaName] }).ConfigureAwait(false); GraphLogger.Info("Started playing notification prompt"); } catch (Exception ex) { GraphLogger.Error(ex, "Failed to play notification prompt."); throw; } }); }
/// <inheritdoc/> protected override void CallOnUpdated(ICall sender, ResourceEventArgs <Call> args) { statusData?.UpdateResponderNotificationStatus(responderId, sender.Resource.State); if (sender.Resource.State == CallState.Established) { var currentPromptTimes = Interlocked.Increment(ref promptTimes); if (currentPromptTimes == 1) { SubscribeToTone(); PlayNotificationPrompt(); } if (sender.Resource.ToneInfo?.Tone != null) { Tone tone = sender.Resource.ToneInfo.Tone.Value; GraphLogger.Info($"Tone {tone} received."); // handle different tones from responder switch (tone) { case Tone.Tone1: PlayTransferringPrompt(); TransferToIncidentMeeting(); break; default: PlayNotificationPrompt(); break; } sender.Resource.ToneInfo.Tone = null; } } }
/// <summary> /// Event fired when the call has been updated. /// </summary> /// <param name="sender">The call.</param> /// <param name="e">The event args containing call changes.</param> private async void CallOnUpdated(ICall sender, ResourceEventArgs <Call> e) { GraphLogger.Info($"Call status updated to {e.NewResource.State} - {e.NewResource.ResultInfo?.Message}"); // Event - Recording update e.g established/updated/start/ended _eventPublisher.Publish($"Call{e.NewResource.State}", $"Call.ID {Call.Id} Sender.Id {sender.Id} status updated to {e.NewResource.State} - {e.NewResource.ResultInfo?.Message}"); if (e.OldResource.State != e.NewResource.State && e.NewResource.State == CallState.Established) { if (!_isDisposed) { // Call is established. We should start receiving Audio, we can inform clients that we have started recording. OnRecordingStatusFlip(sender, null); } } if ((e.OldResource.State == CallState.Established) && (e.NewResource.State == CallState.Terminated)) { if (BotMediaStream != null) { var aQoE = BotMediaStream.GetAudioQualityOfExperienceData(); if (aQoE != null) { if (_settings.CaptureEvents) { await _capture?.Append(aQoE); } } await BotMediaStream.StopMedia(); } if (_settings.CaptureEvents) { await _capture?.Finalise(); } } }