internal PlayMediaAndCollectAction(Call call, string controlID, List <CallMedia> media, CallCollect collect) { Call = call; ControlID = controlID; Media = media; Collect = collect; Call.OnCollect += Call_OnCollect; }
public PromptAction PromptAudioAsync(string url, CallCollect collect) { List <CallMedia> play = new List <CallMedia> { new CallMedia { Type = CallMedia.MediaType.audio, Parameters = new CallMedia.AudioParams { URL = url, } } }; return(PromptAsync(play, collect)); }
public PromptAction PromptTTSAsync(string text, CallCollect collect, string gender = null, string language = null) { List <CallMedia> play = new List <CallMedia> { new CallMedia { Type = CallMedia.MediaType.tts, Parameters = new CallMedia.TTSParams { Text = text, Gender = gender, Language = language, } } }; return(PromptAsync(play, collect)); }
public PromptAction PromptAsync(List <CallMedia> play, CallCollect collect) { PromptAction action = new PromptAction { Call = this, ControlID = Guid.NewGuid().ToString(), PlayPayload = play, CollectPayload = collect, }; Task.Run(async() => { PlayStateChangeCallback playStateChangeCallback = (a, c, e, p) => action.State = p.State; OnPlayStateChange += playStateChangeCallback; action.Result = await InternalPromptAsync(action.ControlID, play, collect); action.Completed = true; OnPlayStateChange -= playStateChangeCallback; }); return(action); }
private async Task <PromptResult> InternalPromptAsync(string controlID, List <CallMedia> play, CallCollect collect) { await API.API.SetupAsync(); PromptResult resultPrompt = new PromptResult(); TaskCompletionSource <bool> tcsCompletion = new TaskCompletionSource <bool>(); // Hook callbacks temporarily to catch required events PlayErrorCallback errorCallback = (a, c, e, p) => { resultPrompt.Event = new Event(e.EventType, JObject.FromObject(p)); tcsCompletion.SetResult(false); }; PromptCallback promptCallback = (a, c, e, p) => { resultPrompt.Event = new Event(e.EventType, JObject.FromObject(p)); resultPrompt.Type = p.Result.Type; switch (resultPrompt.Type) { case CallCollectType.digit: { CallingEventParams.CollectParams.ResultParams.DigitParams digitParams = p.Result.ParametersAs <CallingEventParams.CollectParams.ResultParams.DigitParams>(); resultPrompt.Result = digitParams.Digits; resultPrompt.Terminator = digitParams.Terminator; tcsCompletion.SetResult(true); break; } case CallCollectType.speech: { CallingEventParams.CollectParams.ResultParams.SpeechParams speechParams = p.Result.ParametersAs <CallingEventParams.CollectParams.ResultParams.SpeechParams>(); resultPrompt.Result = speechParams.Text; resultPrompt.Confidence = speechParams.Confidence; tcsCompletion.SetResult(true); break; } default: { tcsCompletion.SetResult(false); break; } } }; OnPlayError += errorCallback; OnPrompt += promptCallback; try { Task <LL_PlayAndCollectResult> taskLLPlayAndCollect = mAPI.LL_PlayAndCollectAsync(new LL_PlayAndCollectParams() { NodeID = mNodeID, CallID = mID, ControlID = controlID, Play = play, Collect = collect, }); // The use of await rethrows exceptions from the task LL_PlayAndCollectResult resultLLPlayAndCollect = await taskLLPlayAndCollect; if (resultLLPlayAndCollect.Code == "200") { mLogger.LogDebug("Prompt {0} for call {1} waiting for completion events", controlID, ID); resultPrompt.Successful = await tcsCompletion.Task; mLogger.LogDebug("Prompt {0} for call {1} {2}", controlID, ID, resultPrompt.Successful ? "successful" : "unsuccessful"); } } catch (Exception exc) { mLogger.LogError(exc, "Prompt {0} for call {1} exception", controlID, ID); } // Unhook temporary callbacks OnPlayError -= errorCallback; OnPrompt -= promptCallback; return(resultPrompt); }
public PromptResult Prompt(List <CallMedia> play, CallCollect collect) { return(InternalPromptAsync(Guid.NewGuid().ToString(), play, collect).Result); }
public async Task <PlaySilenceAndCollectAction> PlaySilenceAndCollectAsync(CallMedia.SilenceParams silence, CallCollect collect) { CallMedia media = new CallMedia() { Type = CallMedia.MediaType.silence, Parameters = JObject.FromObject(silence) }; PlayMediaAndCollectAction playMediaAndCollectAction = await PlayMediaAndCollectAsync(new List <CallMedia> { media }, collect); return(new PlaySilenceAndCollectAction(playMediaAndCollectAction)); }
public PlaySilenceAndCollectAction PlaySilenceAndCollect(CallMedia.SilenceParams silence, CallCollect collect) { return(PlaySilenceAndCollectAsync(silence, collect).Result); }
public async Task <PlayTTSAndCollectAction> PlayTTSAndCollectAsync(CallMedia.TTSParams tts, CallCollect collect) { CallMedia media = new CallMedia() { Type = CallMedia.MediaType.tts, Parameters = JObject.FromObject(tts) }; PlayMediaAndCollectAction playMediaAndCollectAction = await PlayMediaAndCollectAsync(new List <CallMedia> { media }, collect); return(new PlayTTSAndCollectAction(playMediaAndCollectAction)); }
public PlayTTSAndCollectAction PlayTTSAndCollect(CallMedia.TTSParams tts, CallCollect collect) { return(PlayTTSAndCollectAsync(tts, collect).Result); }
public async Task <PlayAudioAndCollectAction> PlayAudioAndCollectAsync(CallMedia.AudioParams audio, CallCollect collect) { CallMedia media = new CallMedia() { Type = CallMedia.MediaType.audio, Parameters = JObject.FromObject(audio) }; PlayMediaAndCollectAction playMediaAndCollectAction = await PlayMediaAndCollectAsync(new List <CallMedia> { media }, collect); return(new PlayAudioAndCollectAction(playMediaAndCollectAction)); }
public PlayAudioAndCollectAction PlayAudioAndCollect(CallMedia.AudioParams audio, CallCollect collect) { return(PlayAudioAndCollectAsync(audio, collect).Result); }
public async Task <PlayMediaAndCollectAction> PlayMediaAndCollectAsync(List <CallMedia> media, CallCollect collect) { // Create the action first so it can hook events and not potentially miss anything PlayMediaAndCollectAction action = new PlayMediaAndCollectAction(this, Guid.NewGuid().ToString(), media, collect); Task <CallPlayAndCollectResult> taskCallPlayAndCollectResult = mAPI.LL_CallPlayAndCollectAsync(new CallPlayAndCollectParams() { NodeID = mNodeID, CallID = mCallID, ControlID = action.ControlID, Play = media, Collect = collect, }); // The use of await ensures that exceptions are rethrown, or OperationCancelledException is thrown CallPlayAndCollectResult callPlayAndCollectResult = await taskCallPlayAndCollectResult; // If there was an internal error of any kind then throw an exception mAPI.ThrowIfError(callPlayAndCollectResult.Code, callPlayAndCollectResult.Message); return(action); }
public PlayMediaAndCollectAction PlayMediaAndCollect(List <CallMedia> media, CallCollect collect) { return(PlayMediaAndCollectAsync(media, collect).Result); }