internal SkillResponse HelpWhilePlaying(AudioSessionAttributes attributes) { return(Speech.GetAskResponse( "You are listening to Dopey Podcast. " + "You can say, Next or Previous to navigate through the episodes." + "At any time, you can say Pause to pause the audio and Resume to resume.")); }
internal SkillResponse LaunchRequest(AudioSessionAttributes attributes) { attributes.Index = 0; attributes.VisitCount++; attributes.OffsetInMilliseconds = 0; attributes.Loop = true; attributes.Shuffle = false; attributes.PlaybackIndexChanged = true; attributes.EnqueuedToken = -1; attributes.State = Constants.States.StartMode; var response = Speech.GetAskResponse( "Welcome to the Dopey Podcast. You can say, play the audio, to begin the podcast.", "You can say, play the audio, to begin."); response.Response.Card = new StandardCard { Title = "Dopy Podcast", Content = "The dark comedy of drug addiction.", Image = new CardImage { LargeImageUrl = "https://deow9bq0xqvbj.cloudfront.net/image-logo/949223/dopeyreal.jpg", SmallImageUrl = "https://deow9bq0xqvbj.cloudfront.net/image-logo/949223/dopeyreal.jpg" } }; return(response); }
internal SkillResponse Unhandled(AudioSessionAttributes attributes) => Speech.GetAskResponse("Sorry, I could not understand. Please say, play the audio, to begin the audio.");
internal SkillResponse Help(AudioSessionAttributes attributes) => Speech.GetAskResponse("Welcome"); // TODO: extract message constants, same as launch string
internal SkillResponse UnhandledWhilePlaying(AudioSessionAttributes attributes) { return(Speech.GetAskResponse( "Sorry, I could not understand. You can say, Next or Previous to navigate through the episodes.")); }
public SkillResponse HandleStateEvent(string state, string @event, AudioSessionAttributes attributes, ILambdaContext context, Request request) { switch (state) { case Constants.States.StartMode: { switch (@event) { case Constants.Events.LaunchRequest: return(LaunchRequest(attributes)); case Constants.Events.PlayAudio: return(PlayAudio(attributes, true)); case Constants.Events.Amazon.HelpIntent: return(Help(attributes)); case Constants.Events.Amazon.StopIntent: return(StopCancel(attributes)); case Constants.Events.Amazon.CancelIntent: return(StopCancel(attributes)); case Constants.Events.SessionEndedRequest: return(SessionEnded(attributes)); case Constants.Events.Unhandled: return(Unhandled(attributes)); default: throw new InvalidOperationException($"Can't handle state {state} event {@event}"); } } case Constants.States.PlayMode: { switch (@event) { case Constants.Events.LaunchRequest: return(LaunchRequest(attributes)); case Constants.Events.PlayAudio: return(PlayAudio(attributes, false)); case Constants.Events.Amazon.NextIntent: return(NextAudio(attributes)); case Constants.Events.Amazon.PreviousIntent: return(PreviousAudio(attributes)); case Constants.Events.Amazon.PauseIntent: return(StopAudio(attributes)); case Constants.Events.Amazon.StopIntent: return(StopAudio(attributes)); case Constants.Events.Amazon.CancelIntent: return(StopAudio(attributes)); case Constants.Events.Amazon.ResumeIntent: return(PlayAudio(attributes, false)); case Constants.Events.Amazon.LoopOnIntent: return(LoopAudio(attributes, true)); case Constants.Events.Amazon.LoopOffIntent: return(LoopAudio(attributes, false)); case Constants.Events.Amazon.ShuffleOnIntent: return(ShuffleAudio(attributes, true)); case Constants.Events.Amazon.ShuffleOffInten: return(ShuffleAudio(attributes, false)); case Constants.Events.Amazon.StartOverIntent: return(StartOverAudio(attributes)); case Constants.Events.Amazon.HelpIntent: return(HelpWhilePlaying(attributes)); case Constants.Events.SessionEndedRequest: return(SessionEnded(attributes)); case Constants.Events.Unhandled: return(UnhandledWhilePlaying(attributes)); // Remote controller handlers case Constants.Events.PlayCommandIssued: return(PlayAudio(attributes, false)); case Constants.Events.PauseCommandIssued: return(StopAudio(attributes)); case Constants.Events.NextCommandIssued: return(NextAudio(attributes)); case Constants.Events.PreviousCommandIssued: return(PreviousAudio(attributes)); // Audio events case Constants.Events.Audio.PlaybackStarted: { attributes.PlaybackFinished = false; attributes.Index = GetIndexFromToken(attributes, ((AudioPlayerRequest)request).Token); return(Speech.GetContinueResponse()); } case Constants.Events.Audio.PlaybackFinished: { attributes.PlaybackFinished = true; attributes.EnqueuedToken = -1; return(Speech.GetContinueResponse()); } case Constants.Events.Audio.PlaybackStopped: { attributes.Index = GetIndexFromToken(attributes, ((AudioPlayerRequest)request).Token); attributes.OffsetInMilliseconds = ((AudioPlayerRequest)request).OffsetInMilliseconds; return(Speech.GetContinueResponse()); } case Constants.Events.Audio.PlaybackNearlyFinished: return(PlaybackNearlyFinishedAudio(attributes)); case Constants.Events.Audio.PlaybackFailed: { _logger.LogLine($"Playback failed: {((AudioPlayerRequest)request).Error}"); return(Speech.GetContinueResponse()); } default: throw new InvalidOperationException($"Can't handle state {state} event {@event}"); } } case Constants.States.ResumeDecisionMode: { switch (@event) { case Constants.Events.LaunchRequest: case Constants.Events.Amazon.HelpIntent: return(Speech.GetAskResponse( $"You were listening to episode {attributes.Index + 1}. Would you like to resume?", "You can say yes to resume or no to play from the top.")); case Constants.Events.Amazon.YesIntent: return(PlayAudio(attributes, false)); case Constants.Events.Amazon.NoIntent: return(StartOverAudio(attributes)); case Constants.Events.Amazon.StopIntent: case Constants.Events.Amazon.CancelIntent: return(StopAudio(attributes)); case Constants.Events.SessionEndedRequest: return(SessionEnded(attributes)); case Constants.Events.Unhandled: return(UnhandledWhilePlaying(attributes)); default: throw new InvalidOperationException($"Can't handle state {state} event {@event}"); } } } throw new InvalidOperationException($"Can't handle state {state} event {@event}"); }