Ejemplo n.º 1
0
 public void RegisterHandler(IIntentHandler handler)
 {
     foreach (var intent in handler.IntentsToListen)
     {
         _handlers[intent] = handler.Handle;
     }
 }
Ejemplo n.º 2
0
        public async Task <SpeechletResponse> OnIntentAsync(IntentRequest intentRequest, Session session, Context context)
        {
            await logHelper.Log($"{session.User.Id} in session {session.SessionId} asked for {intentRequest.Intent.Name}");

            IIntentHandler handler = handlers.TryGetValue(intentRequest.Intent.Name, out handler) ? handler : defaultHandler;

            return(await handler.OnIntentAsync(intentRequest, session));
        }
Ejemplo n.º 3
0
 public AlexaHandler(
     IIntentHandler intentHandler,
     IMessages messages,
     ILogger <AlexaHandler> logger)
 {
     m_messages      = messages;
     m_logger        = logger;
     m_intentHandler = intentHandler;
 }
Ejemplo n.º 4
0
        public void Test_FlashCardBotIntentCreator()
        {
            FlashCardBotIntentCreator intentCreator = new FlashCardBotIntentCreator();

            IIntentHandler intentHandler = intentCreator.GetIntentHandler(Constants.INTENT_NAME_MANAGE_DECKS);

            Assert.Equal(typeof(ManageDeckHandler), intentHandler.GetType());

            intentHandler = intentCreator.GetIntentHandler("SomeInvalidIntent");
            Assert.Null(intentHandler);
        }
Ejemplo n.º 5
0
        protected override IIntentHandler CreateIntentHandler(string intentName)
        {
            IIntentHandler intentHandler = null;

            if (intentName == "managedecks")
            {
                intentHandler = new ManageDeckHandler();
            }
            if (intentName == "quiz")
            {
                intentHandler = new QuizIntentHandler();
            }
            return(intentHandler);
        }
Ejemplo n.º 6
0
        public dynamic FunctionHandler(dynamic inputModel, ILambdaContext context)
        {
            _logger.Info("Called Function Handler");
            //_logger.Info(inputModel.ToString());

            string intentName = String.Empty;

            if (inputModel.currentIntent != null)
            {
                intentName = inputModel.currentIntent.name.ToString();
            }
            IIntentHandler intentHandler = _intentCreator.GetIntentHandler(intentName);

            return(JsonConvert.DeserializeObject <dynamic>(intentHandler.HandleIntent(inputModel)));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// A simple function that takes a string and does a ToUpper
        /// </summary>
        /// <param name="request"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public LexResponse FunctionHandler(LexEvent request, ILambdaContext context)
        {
            LambdaLogger.Log(JsonSerializer.Serialize(request));

            if (request.SessionAttributes == null || !request.SessionAttributes.ContainsKey("Initialized"))
            {
                var validationResult = new InitialValidation(request).HandleJob();
                if (validationResult.DialogAction.FulfillmentState == FulfillmentState.Failed.ToString())
                {
                    return(validationResult);
                }
            }

            IIntentHandler validator = null;

            switch (request.CurrentIntent.Name)
            {
            case "OrderPizza":
                switch (request.InvocationSource)
                {
                case "DialogCodeHook":
                    validator = new OrderPizzaIntentValidation(request);
                    break;

                case "FulfillmentCodeHook":
                    validator = new SaveOrder(request);
                    break;
                }

                break;

            case "QueryOrder":
                validator = new QueryOrder(request);
                break;

            default:
                return(new HandlerBase(request).DelegateToLex());
            }

            return(validator?.HandleJob());
        }
Ejemplo n.º 8
0
 public void RegisterDefault(IIntentHandler handler)
 {
     defaultHandler = handler;
 }
Ejemplo n.º 9
0
 public void Register(string intent, IIntentHandler handler)
 {
     handlers[intent] = handler;
 }
Ejemplo n.º 10
0
        public SkillResponse EntryPoint(SkillRequest alexaRequestInput)
        {
            SkillResponse response = new SkillResponse();

            response.Version = "1.0";
            //start logging
            try
            {
                logger.Debug("Request:" + JsonConvert.SerializeObject(alexaRequestInput.Request));

                string userId    = alexaRequestInput.Context.System.User.UserId;
                string sessionId = alexaRequestInput.Session.SessionId;

                //get last active game for user
                IGameController gameMaker = new ScoreKeepingGameController();
                List <Player>   players   = gameMaker.GetGameScore(alexaRequestInput.Context.System.User.UserId, null);
                switch (alexaRequestInput.Request.Type)
                {
                case "LaunchRequest":

                    logger.Debug("Launch request in");
                    response.Response      = new ResponseBody();
                    response.Response.Card = new SimpleCard()
                    {
                        //                        Content = "Hello! Enjoy your game while I keep the scores. You can tell me to start a game or ask for the score of your current game.",
                        Content = "Start a game?",

                        Title = "Welcome!!"
                    };
                    response.Response.OutputSpeech = new PlainTextOutputSpeech()
                    {
                        Text = "Start a game or get score?"
                    };
                    response.Response.ShouldEndSession = false;

                    logger.Debug("Launch request out");
                    break;

                case "IntentRequest":

                    logger.Debug("intent request in");
                    IntentRequest intentRequest = (IntentRequest)(alexaRequestInput.Request);

                    //switch (intentRequest.Intent.Name)
                    //{
                    var            type    = Type.GetType("GameMaker.IntentHandlers." + intentRequest.Intent.Name.Replace('.', '_') + ", GameMaker, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null");
                    IIntentHandler handler = (IIntentHandler)Activator.CreateInstance(type);
                    response = handler.HandleIntent(gameMaker, intentRequest, userId, sessionId, logger);
                    break;
                //case "PlayerCountIntent":

                //            logger.Debug("player count request in");

                //            handler = new PlayerCountIntent();
                //            return handler.HandleIntent(gameMaker,intentRequest,userId,sessionId,logger);

                //        case "SetPlayerNameIntent":
                //            handler = new SetPlayerNameIntent();
                //            return handler.HandleIntent(gameMaker, intentRequest, userId, sessionId, logger);

                //        case "GetScoreIntent":
                //            logger.Debug("in score intent");
                //            handler = new GetScoreIntent();
                //            return handler.HandleIntent(gameMaker, intentRequest, userId, sessionId, logger);
                //            //say score

                //        case "playintent":

                //            break;
                //    }

                case "SessionEndedRequest":
                    response.Response      = new ResponseBody();
                    response.Response.Card = new SimpleCard()
                    {
                        Content = "Thanks! You can now add scores!",
                        Title   = "Players"
                    };
                    response.Response.OutputSpeech = new PlainTextOutputSpeech()
                    {
                        Text = "Thanks! You can now add scores"
                    };

                    break;

                case "CanFulfillIntentRequest":
                    logger.Debug("in can fulfill"); break;

                case "FallbackIntent":
                    response.Response.OutputSpeech = new PlainTextOutputSpeech()
                    {
                        Text = "Didn't catch that. Please try again."
                    };
                    break;

                default:

                    break;
                    //error
                }
                logger.Debug("Response: " + JsonConvert.SerializeObject(response.Response));
                return(response);
            }
            catch (Exception e)
            {
                logger.Debug(e.StackTrace);
                response.Response      = new ResponseBody();
                response.Response.Card = new SimpleCard()
                {
                    Content = e.Message,
                    Title   = "Players"
                };
                response.Response.OutputSpeech = new PlainTextOutputSpeech()
                {
                    Text = e.Message
                };

                return(response);
            }
        }
Ejemplo n.º 11
0
        public async Task <SkillResponse> FunctionHandler(SkillRequest input, ILambdaContext context)
        {
            var           log           = context.Logger;
            var           output        = new SkillResponse();
            var           response      = new Response();
            IOutputSpeech innerResponse = null;

            response.ShouldEndSession = true;

            output.Response = response;

            Tuple <ICard, IOutputSpeech, Reprompt> responseBody = null;

            log.LogLine(JsonConvert.SerializeObject(input));

            if (input.GetRequestType() == typeof(ILaunchRequest))
            {
                log.LogLine($"Default launch request made: 'Alexa open chromecast menu'");
                responseBody = await(new HelpIntentHandler().HandleAsync(null));
            }
            else if (input.GetRequestType() == typeof(IIntentRequest))
            {
                var            intentRequest = input.Request as IIntentRequest;
                IIntentHandler intentHandler = null;
                INotifier      notifier      = new SNSClientAdapter();

                switch (intentRequest.Intent.Name)
                {
                case "PowerOff":
                    intentHandler = new PowerOffIntentHandler(notifier);
                    break;

                case "AMAZON.PauseIntent":
                    intentHandler = new PauseIntentHandler(notifier);
                    break;

                case "AMAZON.ResumeIntent":
                    intentHandler = new ResumeIntentHandler(notifier);
                    break;

                case "AMAZON.StopIntent":
                    intentHandler = new StopIntentHandler(notifier);
                    break;

                case "AMAZON.HelpIntent":
                    intentHandler = new HelpIntentHandler();
                    break;

                case "SetVolume":
                    intentHandler = new SetVolumeIntentHandler(notifier);
                    break;

                default:
                    intentHandler = new FallbackIntentHandler();
                    break;
                }
                responseBody = await intentHandler.HandleAsync(intentRequest.Intent);
            }

            output.Response.Card         = responseBody.Item1;
            output.Response.OutputSpeech = responseBody.Item2;
            output.Response.Reprompt     = responseBody.Item3;
            return(output);
        }