Example #1
0
        public SpeechletResponse DialogConfirmSlot(Slot slotToElicit, OutputSpeech outputSpeech)
        {
            var intentRequest = (RequestEnvelope.Request as IntentRequest);

            if (intentRequest == null)
            {
                throw new SpeechletException("IntentRequest required");
            }

            if (slotToElicit == null)
            {
                throw new ArgumentNullException(nameof(slotToElicit));
            }
            if (outputSpeech == null)
            {
                throw new ArgumentNullException(nameof(outputSpeech));
            }

            var response = new SpeechletResponse()
            {
                OutputSpeech = outputSpeech,
                Directives   = new List <Directive>()
                {
                    new DialogConfirmSlotDirective()
                    {
                        SlotToConfirm = slotToElicit.Name,
                        UpdatedIntent = intentRequest.Intent
                    }
                },
                ShouldEndSession = false
            };

            return(response);
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="requestEnvelope"></param>
        /// <returns></returns>
        public async Task <string> DoProcessRequestAsync(SpeechletRequestEnvelope requestEnvelope)
        {
            Session           session  = requestEnvelope.Session;
            Context           context  = requestEnvelope.Context;
            SpeechletResponse response = null;

            switch (requestEnvelope.Request)
            {
            case LaunchRequest request:
            {
                if (requestEnvelope.Session.IsNew)
                {
                    await OnSessionStartedAsync(requestEnvelope);
                }
                response = await OnLaunchAsync(request, session, context);
            }
            break;

            case AudioPlayerRequest request:
            {
                response = await OnAudioIntentAsync(request, session, context);
            }
            break;

            // process intent request
            case IntentRequest request:
            {
                // Do session management prior to calling OnSessionStarted and OnIntentAsync
                // to allow dev to change session values if behavior is not desired
                DoSessionManagement(request, session);

                if (requestEnvelope.Session.IsNew)
                {
                    await OnSessionStartedAsync(requestEnvelope);
                }
                response = await OnIntentAsync(request, session, context);
            }
            break;

            // process session ended request
            case SessionEndedRequest request:
            {
                await OnSessionEndedAsync(request, session, context);
            }
            break;
            }

            if (response == null)
            {
                return new SpeechletResponseEnvelope
                       {
                           Version  = requestEnvelope.Version,
                           Response = new SpeechletResponse()
                           {
                               ShouldEndSession = null
                           }
                       }
            }
Example #3
0
        /// <summary>
        /// Create a SpeechletResponse to Stop the current audio playback.
        /// </summary>
        /// <returns>The SpeechletResponse</returns>
        public SpeechletResponse AudioPlayer_Stop()
        {
            var response = new SpeechletResponse()
            {
                Directives = new List <Directive>()
                {
                    new AudioPlayerStopDirective()
                }
                ,
                ShouldEndSession = true
            };

            return(response);
        }
Example #4
0
        /// <summary>
        /// Create a SpeechletResponse to Clear the audio playback queue.
        /// You can set this directive to clear the queue without stopping the currently playing stream,
        /// or clear the queue and stop any currently playing stream.
        /// </summary>
        /// <param name="clearBehavior">Describes the clear queue behavior</param>
        /// <returns>The SpeechletResponse</returns>
        public SpeechletResponse AudioPlayer_ClearQueue(ClearBehaviorEnum clearBehavior = ClearBehaviorEnum.CLEAR_ALL)
        {
            var response = new SpeechletResponse()
            {
                Directives = new List <Directive>()
                {
                    new AudioPlayerClearQueueDirective()
                    {
                        ClearBehavior = clearBehavior
                    }
                },
                ShouldEndSession = true,
            };

            return(response);
        }
Example #5
0
        public SpeechletResponse VideoApp_Launch(VideoItem videoItem)
        {
            var response = new SpeechletResponse()
            {
                Directives = new List <Directive>()
                {
                    new VideoAppLaunchDirective()
                    {
                        VideoItem = videoItem
                    }
                },
                //The shouldEndSession parameter must not be included in the response
                ShouldEndSession = null,
            };

            return(response);
        }
Example #6
0
        /// <summary>
        /// Create a SpeechletResponse to send Alexa a command to stream the audio file identified by the specified audioItem.
        /// Use the playBehavior parameter to determine whether the stream begins playing immediately,
        /// or is added to the queue.
        /// </summary>
        /// <param name="stream">Representing the audio stream to play</param>
        /// <param name="playbehavior">Describes playback behavior.</param>
        /// <returns>The SpeechletResponse</returns>
        public SpeechletResponse AudioPlayer_Play(AudioStream stream, PlayBehaviorEnum playbehavior = PlayBehaviorEnum.REPLACE_ALL)
        {
            var response = new SpeechletResponse()
            {
                Directives = new List <Directive>()
                {
                    new AudioPlayerPlayDirective()
                    {
                        PlayBehavior = playbehavior,
                        AudioItem    = new AudioItem()
                        {
                            Stream = stream
                        }
                    }
                },
                ShouldEndSession = true
            };

            return(response);
        }
Example #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sourceUrl">Dentifies the location of video content at a remote HTTPS location.</param>
        /// <param name="metadata">[OPTIONAL] Information that can be displayed on VideoApp</param>
        /// <returns>The SpeechletResponse</returns>
        public SpeechletResponse VideoApp_Launch(string sourceUrl, VideoItemMetadata metadata = null)
        {
            var response = new SpeechletResponse()
            {
                Directives = new List <Directive>()
                {
                    new VideoAppLaunchDirective()
                    {
                        VideoItem = new VideoItem()
                        {
                            Source   = sourceUrl,
                            Metadata = metadata
                        }
                    }
                },
                //The shouldEndSession parameter must not be included in the response
                ShouldEndSession = null,
            };

            return(response);
        }
Example #8
0
        public SpeechletResponse DialogDelegate()
        {
            var intentRequest = (RequestEnvelope.Request as IntentRequest);

            if (intentRequest == null)
            {
                throw new SpeechletException("IntentRequest required");
            }

            var response = new SpeechletResponse()
            {
                Directives = new List <Directive>()
                {
                    new DialogDelegateDirective()
                    {
                        UpdatedIntent = intentRequest.Intent
                    }
                },
                ShouldEndSession = false
            };

            return(response);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="requestEnvelope"></param>
        /// <returns></returns>
        private string DoProcessRequest(SpeechletRequestEnvelope requestEnvelope)
        {
            Session           session  = requestEnvelope.Session;
            Context           context  = requestEnvelope.Context;
            SpeechletResponse response = null;

            switch (requestEnvelope.Request)
            {
            case LaunchRequest request:
            {
                if (requestEnvelope.Session.IsNew)
                {
                    OnSessionStarted(requestEnvelope);
                }
                response = OnLaunch(request, session, context);
            }
            break;

            case AudioPlayerRequest request:
            {
                response = OnAudioIntent(request, session, context);
            }
            break;

            // process intent request
            case IntentRequest request:
            {
                // Do session management prior to calling OnSessionStarted and OnIntentAsync
                // to allow dev to change session values if behavior is not desired
                DoSessionManagement(request, session);

                if (requestEnvelope.Session.IsNew)
                {
                    OnSessionStarted(requestEnvelope);
                }
                response = OnIntent(request, session, context);
            }
            break;

            // process session ended request
            case SessionEndedRequest request:
            {
                OnSessionEnded(request, session, context);
            }
            break;
            }

            if (response == null)
            {
                return(new SpeechletResponseEnvelope
                {
                    Version = requestEnvelope.Version,
                    Response = new SpeechletResponse()
                    {
                        ShouldEndSession = null
                    }
                }.ToJson());
            }


            var responseEnvelope = new SpeechletResponseEnvelope
            {
                Version           = requestEnvelope.Version,
                Response          = response,
                SessionAttributes = requestEnvelope.Session?.Attributes ?? new Dictionary <string, string>()
            };

            return(responseEnvelope.ToJson());
        }