public AlexaResponse ProcessAlexaRequest(AlexaRequestPayload alexaRequestPayload)
        {
            // validate request time stamp and app id
            // note that there is custom validation in the AlexaRequestValidationHandler
            SpeechletRequestValidationResult validationResult = _alexaRequestValidationService.ValidateAlexaRequest(alexaRequestPayload);

            if (validationResult == SpeechletRequestValidationResult.OK)
            {
                try
                {
                    // transform request
                    AlexaRequest alexaRequest = _alexaRequestMapper.MapAlexaRequest(alexaRequestPayload);

                    // persist request and member
                    _alexaRequestPersistenceService.PersistAlexaRequestAndMember(alexaRequest);

                    // create a request handler strategy from the alexarequest
                    IAlexaRequestHandlerStrategy alexaRequestHandlerStrategy = _alexaRequestHandlerStrategyFactory.CreateAlexaRequestHandlerStrategy(alexaRequestPayload);

                    // use the handlerstrategy to process the request and generate a response
                    AlexaResponse alexaResponse = alexaRequestHandlerStrategy.HandleAlexaRequest(alexaRequestPayload);

                    // return response
                    return(alexaResponse);
                }
                catch (Exception exception)
                {
                    // todo: log the error
                    return(new AlexaResponse("There was an error " + exception.Message));
                    //return new AlexaWordErrorResponse().GenerateCustomError();
                }
            }

            return(null);
        }
Beispiel #2
0
        public IAlexaRequestHandlerStrategy CreateAlexaRequestHandlerStrategy(AlexaRequestPayload alexaRequest)
        {
            switch (alexaRequest.Request.Type)
            {
            case "LaunchRequest":
            case "SessionEndedRequest":
                IAlexaRequestHandlerStrategy strategy = _availableStrategies
                                                        .FirstOrDefault(s => s.SupportedRequestType == alexaRequest.Request.Type);
                return(strategy);

            case "IntentRequest":
                IAlexaRequestHandlerStrategy intentStrategy = _availableStrategies
                                                              .FirstOrDefault(s => s.SupportedRequestIntentName == alexaRequest.Request.Intent.Name);
                return(intentStrategy);

            default:
                throw new NotImplementedException();
            }
        }