Ejemplo n.º 1
0
        public async Task <AlexaDemoResponse> Main(AlexaDemoRequest alexaRequest)
        {
            AlexaDemoResponse response = new AlexaDemoResponse();

            try
            {
                //check timestamp
                var totalSeconds = (DateTime.UtcNow - alexaRequest.Request.Timestamp).TotalSeconds;
                if (totalSeconds >= TimeStampTolerance)
                {
                    throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest));
                }

                if (alexaRequest.Session.Application.ApplicationId != null)
                {
                    if (alexaRequest.Session.Application.ApplicationId != AppSettings.AmazonAppId)
                    {
                        throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest));
                    }
                }
                else
                {
                    if (alexaRequest.Context.System.Application.ApplicationId != AppSettings.AmazonAppId)
                    {
                        throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest));
                    }
                }
                response.SessionAttributes = alexaRequest.Session.Attributes;

                //===============================================================================================
                //Option 1
                AlexaNet.RegisterHandlers(new List <object>()
                {
                    this
                });
                response = AlexaNet.HandleIntent(alexaRequest, response);

                //===============================================================================================

                //Option 2 --- ATTRIBUTED MODEL
                //need to unremark code in global.cs to make this work
                //response = AlexaNet.HandleIntent(alexaRequest, response);


                //Option 3 ????????? DO WE NEED AN OPTION 3????

                //=====>>>>This appears to be a variation on # 1 above<<==============================

                //option 1 - uncomment the following to test option 1, comment out to test option 2
                // var interactionHandler1 = new Interactions(request);
                // interactionHandler1.Messages.StopMessage = "This is where you can override the default stop message.";
                // response = interactionHandler1.Process(this);

                //=====>>>>I am not sure where this fits now.<<==============================

                //option 2 - uncomment the following to test option 2, comment out to test option 1
                //var interactionHandler2 = new Interactions(request);
                //interactionHandler2.IntentsList.Add("LaunchRequest", (req) => LaunchRequest(req));
                //interactionHandler2.IntentsList.Add("WelcomeIntent", (req) => WelcomeIntent(req));
                //interactionHandler2.IntentsList.Add("AMAZON.HelpIntent", (req) => HelpIntent());
                //interactionHandler2.IntentsList.Add("AMAZON.StopIntent", (req) => new { message = "This is the overriden built-in stop message." });
                //response = interactionHandler2.Process();

                //=====>>>>This appears to be a variation on # 1 above<<==============================

                //This is created as Option #1 in the Alexa.Demo.Web Project it V2 AlexaController..instead
                //of creating a intenthandler and calling them dirrectly as below, just pass a list of your
                //intent handlerst to the SDK.
                // response = BuidOutWithCard(IntentsHandler.Process(request, response)) as AlexaResponse;



                response.SessionAttributes.OutputSpeech = response.Response.OutputSpeech;
                //BuildOutTextOutPut();
                //BuildOutTextOutPutWithCard()
                //BuildOutTextOutPutWithCardImages();
            }
            catch (Exception ex)
            {
                return(await ThrowSafeException(ex, response));
            }

            return(response);
        }
Ejemplo n.º 2
0
        public async Task <AlexaDemoResponse> Main(AlexaDemoRequest alexaRequest)
        {
            AlexaDemoResponse response = new AlexaDemoResponse();

            try
            {
                //check timestamp
                var totalSeconds = (DateTime.UtcNow - alexaRequest.Request.Timestamp).TotalSeconds;
                if (totalSeconds >= TimeStampTolerance)
                {
                    throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest));
                }

                if (alexaRequest.Session.Application.ApplicationId != null)
                {
                    if (alexaRequest.Session.Application.ApplicationId != AppSettings.AmazonAppId)
                    {
                        throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest));
                    }
                }
                else
                {
                    if (alexaRequest.Context.System.Application.ApplicationId != AppSettings.AmazonAppId)
                    {
                        throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest));
                    }
                }
                response.SessionAttributes = alexaRequest.Session.Attributes;


                //===============================================================================================

                //var handler1 = new ListReminderHandler("ListReminder");
                //var handler2 = new CreateReminderHandler("CreateReminder");
                //this.State = "Main";

                //var sdk = new AlexaNetSDK();
                //sdk.RegisterHandlers(new List<IIntentHandler>() {this, handler1 , handler2});

                //alexaRequest =  SetRequestTypeState(alexaRequest);

                //response = sdk.HandleIntent(alexaRequest, response);

                response = AlexaNet.HandleIntent(alexaRequest, response);

                //===============================================================================================


                response.SessionAttributes.OutputSpeech = response.Response.OutputSpeech;

                //BuildOutTextOutPut();
                //BuildOutTextOutPutWithCard()
                //BuildOutTextOutPutWithCardImages();
            }
            catch (Exception ex)
            {
                return(await ThrowSafeException(ex, response));
            }

            return(response);
        }