/// <summary>
        /// Handler Lambda function for the alexa skill.
        /// </summary>
        /// <param name="alexaRequest">The alexa skill request.</param>
        /// <param name="lambdaContext">The context of the executing lambda.</param>
        /// <returns>The alexa response.</returns>
        public AlexaResponse HandleAlexaSkillRequest(AlexaRequest alexaRequest, ILambdaContext lambdaContext)
        {
            AlexaResponse response;

            switch (alexaRequest.RequestData.RequestType)
            {
            // Handle Launch request.
            case AlexaRequestType.LaunchRequest:
                AlexaLaunchRequest launchRequest = alexaRequest.RequestData as AlexaLaunchRequest;
                if (Logger.IsEnabled(LogLevel.Debug))
                {
                    Logger.LogDebug($"Recieved Alexa Launch Request: ID = {launchRequest.RequestId}");
                }
                response = HandleLaunchRequest(launchRequest, alexaRequest.Context, alexaRequest.Session);
                break;

            // Can not send response to session ended request.
            case AlexaRequestType.SessionEndedRequest:
                AlexaSessionEndedRequest sessionEndedRequest = alexaRequest.RequestData as AlexaSessionEndedRequest;
                if (Logger.IsEnabled(LogLevel.Debug))
                {
                    Logger.LogDebug($"Received Alexa Session Ended Request: ID = {sessionEndedRequest.RequestId}, Reason={sessionEndedRequest.Reason.ToString()}");
                }
                HandleSessionEndedRequest(sessionEndedRequest, alexaRequest.Context, alexaRequest.Session);
                return(null);

            case AlexaRequestType.IntentRequest:
                AlexaIntentRequest intentRequest = alexaRequest.RequestData as AlexaIntentRequest;
                if (Logger.IsEnabled(LogLevel.Debug))
                {
                    string debug = $"Received Alexa Intent Request: ID = {intentRequest.RequestId}, ";
                    debug += $"IntentName = {intentRequest.Intent?.Name}, ";
                    if (intentRequest.Intent?.Slots != null)
                    {
                        debug += $"Slots = {string.Join(",", intentRequest.Intent?.Slots?.Keys)}, ";
                        debug += $"Slot Values = {string.Join(",", intentRequest.Intent?.Slots?.Values)}";
                    }
                    Logger.LogDebug(debug);
                }
                response = HandleIntentRequest(intentRequest, alexaRequest.Context, alexaRequest.Session);
                break;

            case AlexaRequestType.CanFulfillIntentRequest:
                AlexaCanFulfillIntentRequest canFulfillIntentRequest = alexaRequest.RequestData as AlexaCanFulfillIntentRequest;
                if (Logger.IsEnabled(LogLevel.Debug))
                {
                    string debug = $"Received Can Fulfill Intent Request: ID = {canFulfillIntentRequest.RequestId}, ";
                    Logger.LogDebug(debug);
                }
                response = HandleCanFulfillIntentRequest(canFulfillIntentRequest, alexaRequest.Context, alexaRequest.Session);
                break;

            default:
                Logger.LogError($"Received not implemented Alexa request type: {alexaRequest.RequestData.RequestType}");
                throw new NotImplementedException($"{alexaRequest.RequestData.RequestType} is not yet implemented.");
            }


            return(response);
        }
Exemple #2
0
        public override AlexaResponse HandleCanFulfillIntentRequest(AlexaCanFulfillIntentRequest canFulfillIntentRequest, AlexaContext context, AlexaSession session)
        {
            AlexaResponse         alexaResponse = new AlexaResponse();
            PlainTextOutputSpeech plainText     = new PlainTextOutputSpeech
            {
                Text = "AlexaCanFulfillIntentRequest"
            };
            AlexaResponseData responseData = new AlexaResponseData
            {
                OutputSpeech = plainText
            };

            alexaResponse.Response = responseData;
            return(alexaResponse);
        }
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            JToken           jObject = JToken.ReadFrom(reader);
            AlexaRequestType requestType;

            try
            {
                requestType = jObject["type"].ToObject <AlexaRequestType>();
            }
            catch (ArgumentException ae)
            {
                throw new JsonSerializationException(ae.Message);
            }

            AlexaRequestDataBase result;

            switch (requestType)
            {
            case AlexaRequestType.LaunchRequest:
                result = new AlexaLaunchRequest();
                break;

            case AlexaRequestType.SessionEndedRequest:
                result = new AlexaSessionEndedRequest();
                break;

            case AlexaRequestType.CanFulfillIntentRequest:
                result = new AlexaCanFulfillIntentRequest();
                break;

            case AlexaRequestType.IntentRequest:
                result = new AlexaIntentRequest();
                break;

            default:
                throw new ArgumentOutOfRangeException($"Request type {requestType} is not a valid Alexa request type.");
            }

            serializer.Populate(jObject.CreateReader(), result);

            return(result);
        }
 /// <summary>
 /// Function to handle Alexa can fullfill intent requests.
 /// </summary>
 /// <param name="canFulfillIntentRequest">The alexa can fulfill intent request.</param>
 /// <param name="context">Context of the Alexa execution.</param>
 /// <param name="session">Current Alexa session.</param>
 /// <returns>The Alexa response.</returns>
 public virtual AlexaResponse HandleCanFulfillIntentRequest(
     AlexaCanFulfillIntentRequest canFulfillIntentRequest,
     AlexaContext context,
     AlexaSession session)
 => throw new NotImplementedException("HandleCanFulfillIntentRequest not yet implemented.");