Esempio n. 1
0
 public SpeechletResponse Say(SsmlBuilder ssmblBuilder, bool shouldEndSession = true)
 {
     return(new SpeechletResponse()
     {
         OutputSpeech = new SsmlOutputSpeech()
         {
             Ssml = ssmblBuilder.ToString()
         },
         ShouldEndSession = shouldEndSession
     });
 }
        private static SsmlOutputSpeech BuildSsmlResponseMessage(string computedOtp)
        {
            SsmlBuilder ssml = new SsmlBuilder();

            ssml.StartSpeech();

            ssml.AddSpeech("Enter this code into the app: ");
            ssml.AddSpeechWithBreaks(computedOtp.ToCharArray(), 500);

            ssml.AddSpeech("Again, the code is: ");
            ssml.AddSpeechWithBreaks(computedOtp.ToCharArray(), 500);

            ssml.AddSpeech("This code will expire in 5 minutes.");

            ssml.EndSpeech();

            return(new SsmlOutputSpeech(ssml.Speak()));
        }
        public override SpeechletResponse OnIntent(IntentRequest intentRequest, Session session, Context context)
        {
            try
            {
                switch (intentRequest.Intent.Name)
                {
                case Amazon_BuiltIns.CancelIntent:
                case Amazon_BuiltIns.StopIntent:
                    return(Say("OK"));

                case Amazon_BuiltIns.HelpIntent:
                    return(Say("Ask: is the answer 42 or what is the answer to life, the universe and everything"));


                case "number":     // is the answer {slot_number}?
                {
                    var slot_number = intentRequest.Intent.Slots["slot_number"];

                    // failsafe
                    if (slot_number == null)
                    {
                        return(Say("Something went wrong with the slot"));
                    }

                    #region         // Show ElicitSlot

                    // Check if the Number is recognized
                    if (slot_number.GetResolutionsCode() != ResolutionStatusCodeEnum.ER_SUCCESS_MATCH)
                    {
                        return(DialogElicitSlot(slot_number, new PlainTextOutputSpeech()
                            {
                                Text = "Say a Number, please?"
                            }));
                    }

                    #endregion

                    #region         // Show Slot Confirm

                    // Confirm the recognized value...because....i can
                    switch (slot_number.ConfirmationStatus)
                    {
                    case ConfirmationStatusEnum.NONE:
                    default:
                        return(DialogConfirmSlot(slot_number, new PlainTextOutputSpeech($"Did you say {slot_number.Value}?")));

                    case ConfirmationStatusEnum.DENIED:
                        return(DialogElicitSlot(slot_number, new PlainTextOutputSpeech()
                            {
                                Text = "Say a Number, please"
                            }));

                    case ConfirmationStatusEnum.CONFIRMED:
                        break;
                    }

                    #endregion

                    if (slot_number.Value == "42")
                    {
                        return(Say("that's correct"));
                    }

                    // Build a SSML Answer
                    var ssml = new SsmlBuilder();
                    ssml.Append("No");
                    ssml.Break(1500);
                    ssml.Whisper("The correct answer is 42");

                    // Return a SSML Answer
                    return(Say(ssml));
                }

                case "question":     // what is the answer to life the universe and everything?

                    #region Show Dialog Delegate
                    if (intentRequest.DialogState != DialogStateEnum.COMPLETED)
                    {
                        switch (intentRequest.Intent.ConfirmationStatus)
                        {
                        default:
                        case ConfirmationStatusEnum.NONE:
                            return(DialogDelegate());        // Ask "Was your Question what is the answer to life the universe and everything?" Set in Intent Setting

                        case ConfirmationStatusEnum.DENIED:
                            Say("hmm Sorry");
                            break;

                        case ConfirmationStatusEnum.CONFIRMED:
                            break;
                        }
                    }
                    #endregion

                    return(SayWithCard("42", "Alexa Testapp", "The Answer is 42", true));

                default:
                    return(Error_NoIntentFound());
                }
            }
            catch (Exception exception)
            {
                log.Error(exception);

                return(Error_GenericError());
            }
        }