예제 #1
0
        private async Task HandleLaunchRequestAsync(ITurnContext turnContext, CancellationToken cancellationToken)
        {
            var alexaConversation = await _accessors.AlexaConversation.GetAsync(turnContext, () => new AlexaConversation());

            var greetingMessage = string.IsNullOrEmpty(alexaConversation.Phrase)
                ? "Hola, soy tu logopeda virtual, tienes que decirme qué frase o palabra vamos a trabajar"
                : $@"Hola, continuamos trabajando la {(alexaConversation.Phrase.Contains(" ") ? "frase" : "palabra")} ""{alexaConversation.Phrase}"". A ver José Manuel, dime ""{alexaConversation.Phrase}""";

            DisplayDirective directive = new DisplayDirective
            {
                Template = GenerateImageTemplate("Human Learning", "https://esalcedoost.blob.core.windows.net/public/background.png")
            };

            turnContext.AlexaResponseDirectives().Add(directive);
            await turnContext.SendActivityAsync(MessageFactory.Text(greetingMessage, inputHint: InputHints.ExpectingInput), cancellationToken : cancellationToken);
        }
예제 #2
0
        private static async Task Greetings(ITurnContext turnContext, CancellationToken cancellationToken)
        {
            IMessageActivity activity = MessageFactory.SuggestedActions(
                new List <CardAction>()
            {
                new CardAction(type: ActionTypes.ImBack, title: "Crea mi propia aventura", displayText: "Comenzar", value: "Crea mi propia aventura"),
                new CardAction(type: ActionTypes.ImBack, title: "Ayuda", displayText: "Ayuda", value: "Ayuda")
            },
                text: "¡Hola! Soy el Narrador de Historias");


            if (turnContext.Activity.ChannelId.Equals("Alexa", StringComparison.InvariantCultureIgnoreCase) &&
                turnContext.AlexaDeviceHasDisplay())
            {
                activity.InputHint = InputHints.AcceptingInput;
                turnContext.AlexaResponseDirectives().Add(activity.ToAlexaDirective());
            }

            await turnContext.SendActivityAsync(activity, cancellationToken);
        }
예제 #3
0
 private static void AddDirectivesToResponse(ITurnContext context, AlexaResponseBody response)
 {
     response.Response.Directives = context.AlexaResponseDirectives().Select(a => a).ToArray();
 }
예제 #4
0
        protected override async Task OnMessageActivityAsync(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken)
        {
            var message           = turnContext.Activity.Text.ToLower();
            var alexaConversation = await _accessors.AlexaConversation.GetAsync(turnContext, () => new AlexaConversation());

            _logger.LogInformation(@"----- Retrieved alexaConversation ({@AlexaConversation})", alexaConversation);

            // ** Handle goodbye message
            if (message == "adiós")
            {
                // ** Echo user message to monitor
                await EchoUserMessageAsync(turnContext);

                await turnContext.SendActivityAsync(MessageFactory.Text("Adiós José Manuel! Buenas noches."), cancellationToken);

                await ClearConversationAsync(turnContext, "end");

                return;
            }

            if (message == "pausa")
            {
                // ** Echo user message to monitor
                await EchoUserMessageAsync(turnContext);

                await turnContext.SendActivityAsync(MessageFactory.Text("Muy bien, me pongo en pausa y seguimos luego."), cancellationToken);

                return;
            }

            var commandConfirmation = string.Empty;

            if (message == "cambiar palabra")
            {
                // ** Echo user message to monitor
                await EchoUserMessageAsync(turnContext);

                await ClearConversationAsync(turnContext, "end");

                commandConfirmation = "Acabo de dar por terminado el ejercicio, así que ";
            }

            if (message == "eliminar palabra")
            {
                // ** Echo user message to monitor
                await EchoUserMessageAsync(turnContext);

                await ClearConversationAsync(turnContext, "delete");

                commandConfirmation = "Acabo de eliminar el ejercicio, así que ";
            }

            if (message.StartsWith(newTargetPhraseUtterance))
            {
                // ** Echo user message to monitor
                await EchoUserMessageAsync(turnContext);

                alexaConversation.Phrase   = GetTargetPhrase(message);
                alexaConversation.Language = turnContext.Activity.Locale;

                if (!string.IsNullOrWhiteSpace(alexaConversation.Phrase))
                {
                    alexaConversation.CurrentExercise = await CreateExerciseAsync(alexaConversation);

                    alexaConversation.Count = 0;

                    _logger.LogInformation("----- Current exercise saved ({@AlexaConversation})", alexaConversation);

                    await _accessors.AlexaConversation.SetAsync(turnContext, alexaConversation);

                    await turnContext.SendActivityAsync(MessageFactory.Text($@"Muy bien, vamos a trabajar con ""{alexaConversation.Phrase}"". A ver José Manuel, di ""{alexaConversation.Phrase}"" ahora!", inputHint: InputHints.ExpectingInput));

                    return;
                }
            }

            var replyMessage = string.Empty;
            var audio        = string.Empty;

            if (string.IsNullOrEmpty(alexaConversation.Phrase))
            {
                replyMessage = $@"{commandConfirmation} necesito saber qué otra palabra vamos a trabajar. Dime, ""Trabajar"", y luego la frase o palabra que quieras.";
            }
            else
            {
                _logger.LogInformation(@"----- Registering utterance ""{Utterance}"" for exercise ({@Exercise})", message, alexaConversation.CurrentExercise);

                var utterance = await RegisterUtteranceAsync(alexaConversation.CurrentExercise, message);

                // ** Echo user utterance to monitor
                await EchoUserUtteranceAsync(turnContext, utterance);

                replyMessage = GetResultMessage(turnContext, alexaConversation);

                await _accessors.AlexaConversation.SetAsync(turnContext, alexaConversation);

                DisplayDirective directive = new DisplayDirective
                {
                    Template = GenerateUtteranceTemplate(message, utterance.PercentDeviation)
                };

                turnContext.AlexaResponseDirectives().Add(directive);

                audio = GetAudio(utterance.PercentDeviation);
            }

            var activity = MessageFactory.Text(replyMessage, inputHint: InputHints.ExpectingInput);
            await turnContext.SendActivityAsync(activity, cancellationToken);
        }