private static SkillResponse BuildResponse(IOutputSpeech outputSpeech, bool shouldEndSession, Session sessionAttributes, Reprompt reprompt, ICard card)
        {
            SkillResponse response = new Response.SkillResponse();

            response.Version = "1.0";
            if (sessionAttributes != null)
            {
                response.SessionAttributes = sessionAttributes.Attributes;
            }

            ResponseBody body = new Response.ResponseBody();

            body.ShouldEndSession = shouldEndSession;
            body.OutputSpeech     = outputSpeech;

            if (reprompt != null)
            {
                body.Reprompt = reprompt;
            }
            if (card != null)
            {
                body.Card = card;
            }

            response.Response = body;

            return(response);
        }
        public static SkillResponse TellWithAskForPermissionsConsentCard(IOutputSpeech speechResponse, IEnumerable <string> permissions, Session sessionAttributes)
        {
            AskForPermissionsConsentCard card = new AskForPermissionsConsentCard();

            card.Permissions = permissions.ToList();
            return(BuildResponse(speechResponse, true, sessionAttributes, null, card));
        }
Пример #3
0
        private static CrunchResponse BuildResponse(IOutputSpeech outputSpeech, bool shouldEndSession, Session sessionAttributes, Reprompt reprompt, ICard card)
        {
            CrunchResponse response = new CrunchResponse {
                Version = "1.0"
            };

            if (sessionAttributes != null)
            {
                response.SessionAttributes = sessionAttributes.Attributes;
            }

            ResponseBody body = new ResponseBody
            {
                ShouldEndSession = shouldEndSession,
                OutputSpeech     = outputSpeech
            };

            if (reprompt != null)
            {
                body.Reprompt = reprompt;
            }
            if (card != null)
            {
                body.Card = card;
            }

            response.Response = body;

            return(response);
        }
Пример #4
0
        private static SkillResponse BuildResponse(IOutputSpeech outputSpeech, bool shouldEndSession, Reprompt reprompt, ICard card)
        {
            SkillResponse response = new SkillResponse {
                Version = "1.0"
            };

            ResponseBody body = new ResponseBody
            {
                ShouldEndSession = shouldEndSession,
                OutputSpeech     = outputSpeech
            };

            if (reprompt != null)
            {
                body.Reprompt = reprompt;
            }
            if (card != null)
            {
                body.Card = card;
            }

            response.Response          = body;
            response.SessionAttributes = sessionAttributes.ToDictionary();

            return(response);
        }
Пример #5
0
        /// <summary>
        /// Builds up the details required to ask a question and stores them in the
        /// sessionAtrtibutes array
        /// </summary>
        /// <param name="input"></param>
        /// <param name="innerReponse"></param>
        /// <returns>void</returns>
        private void AskQuestion(SkillRequest input, IOutputSpeech innerResponse)
        {
            if (counter <= 0)
            {
                (innerResponse as SsmlOutputSpeech).Ssml = START_QUIZ_MESSAGE + " ";
                counter = 0;
            }

            counter++;
            response.SessionAttributes.Add(COUNTER, counter);
            Item item = theItems[GetRandomNumber(0, theItems.Count - 1)];

            string property = Item.PropertyNames[GetRandomNumber(0, Item.PropertyNames.Length - 1)];

            response.SessionAttributes.Add(QUIZPROPERTY, property);

            response.SessionAttributes.Add(QUIZITEM, item);
            response.SessionAttributes.Add(QUIZSCORE, quizscore);

            string question = GetQuestion(counter, property, item);

            (innerResponse as SsmlOutputSpeech).Ssml += question;

            response.Response.Reprompt = new Reprompt();
            response.Response.Reprompt.OutputSpeech = new SsmlOutputSpeech();
            (response.Response.Reprompt.OutputSpeech as SsmlOutputSpeech).Ssml = DecorateSsml(question);
            response.SessionAttributes.Add(RESPONSE, (innerResponse as SsmlOutputSpeech).Ssml);
        }
Пример #6
0
        /// <summary>
        /// Returns bus times
        /// </summary>
        /// <param name="input"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public SkillResponse FunctionHandler(SkillRequest input, ILambdaContext context)
        {
            SkillResponse response = new SkillResponse
            {
                Response = new ResponseBody()
            };

            response.Response.ShouldEndSession = false;
            IOutputSpeech innerResponse = null;
            var           log           = context.Logger;

            log.LogLine($"Skill Request Object:");
            log.LogLine(JsonConvert.SerializeObject(input));

            //foreach (TimeZoneInfo z in TimeZoneInfo.GetSystemTimeZones())
            //    log.LogLine(z.Id);

            if (input.GetRequestType() == typeof(LaunchRequest))
            {
                log.LogLine($"Default LaunchRequest made: 'Alexa, open Busplan");
                innerResponse = new PlainTextOutputSpeech();
                (innerResponse as PlainTextOutputSpeech).Text =
                    GetNextBusAnnouncement(Moltkestrasse, Uni) +
                    GetNextBusAnnouncement(Moltkestrasse, Bahnhof);
                response.Response.ShouldEndSession = true;
            }
            else if (input.GetRequestType() == typeof(IntentRequest))
            {
                var intentRequest = (IntentRequest)input.Request;

                switch (intentRequest.Intent.Name)
                {
                case "AMAZON.CancelIntent":
                case "AMAZON.StopIntent":
                    log.LogLine($"{intentRequest.Intent.Name}: send StopMessage");
                    innerResponse = new PlainTextOutputSpeech();
                    (innerResponse as PlainTextOutputSpeech).Text = "Stopped";
                    response.Response.ShouldEndSession            = true;
                    break;

                case "AMAZON.HelpIntent":
                    log.LogLine($"AMAZON.HelpIntent: send HelpMessage");
                    innerResponse = new PlainTextOutputSpeech();
                    (innerResponse as PlainTextOutputSpeech).Text = "Help";
                    break;

                default:
                    log.LogLine($"default intent: " + intentRequest.Intent.Name);
                    innerResponse = new PlainTextOutputSpeech();
                    (innerResponse as PlainTextOutputSpeech).Text = "default";
                    break;
                }
            }

            response.Response.OutputSpeech = innerResponse;
            response.Version = "1.0";
            log.LogLine($"Skill Response Object...");
            log.LogLine(JsonConvert.SerializeObject(response));
            return(response);
        }
Пример #7
0
        public static CrunchResponse TellWithAskForPermissionsConsentCard(IOutputSpeech speechResponse, IEnumerable <string> permissions)
        {
            AskForPermissionsConsentCard card = new AskForPermissionsConsentCard {
                Permissions = permissions.ToList()
            };

            return(BuildResponse(speechResponse, true, null, null, card));
        }
Пример #8
0
 private void SetStandardResponse()
 {
     _response          = new SkillResponse();
     _innerResponse     = new PlainTextOutputSpeech();
     _response.Response = new ResponseBody();
     _response.Response.ShouldEndSession = true;
     _response.Version = "1.0";
 }
        public static SkillResponse TellWithCard(IOutputSpeech speechResponse, string title, string content, Session sessionAttributes)
        {
            SimpleCard card = new SimpleCard();

            card.Content = content;
            card.Title   = title;

            return(BuildResponse(speechResponse, true, sessionAttributes, null, card));
        }
Пример #10
0
        public SkillResponse FunctionHandler(SkillRequest input, ILambdaContext context)
        {
            IOutputSpeech innerResponse    = null;
            var           log              = context.Logger;
            var           shouldEndSession = false;

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

            if (input.GetRequestType() == typeof(ILaunchRequest))
            {
                // default launch request, let's just let them know what you can do
                log.LogLine("Default LaunchRequest made");

                innerResponse = Help;
            }
            else if (input.GetRequestType() == typeof(IIntentRequest))
            {
                // intent request, process the intent
                log.LogLine($"Intent Requested {input.Request.Intent.Name}");

                switch (input.Request.Intent.Name)
                {
                case "QuestionIntent":
                    innerResponse    = RandomAnswer;
                    shouldEndSession = true;
                    break;

                case "AMAZON.HelpIntent":
                    innerResponse = Help;
                    break;

                case "AMAZON.StopIntent":
                case "AMAZON.CancelIntent":
                    innerResponse    = End;
                    shouldEndSession = true;
                    break;

                default:
                    innerResponse = Error;
                    break;
                }
            }

            var response = new Response
            {
                ShouldEndSession = shouldEndSession,
                OutputSpeech     = innerResponse
            };

            var skillResponse = new SkillResponse
            {
                Response = response,
                Version  = "1.0"
            };

            return(skillResponse);
        }
        public SkillResponse FunctionHandler(SkillRequest input, ILambdaContext context)
        {
            IOutputSpeech innerResponse = null;
            var           result        = 0;

            if (input.GetRequestType() == typeof(Slight.Alexa.Framework.Models.Requests.RequestTypes.ILaunchRequest))
            {
                innerResponse = new PlainTextOutputSpeech();
                ((PlainTextOutputSpeech)innerResponse).Text = "Welcome to number functions.  You can ask us to add numbers!";
            }
            else if (input.GetRequestType() == typeof(Slight.Alexa.Framework.Models.Requests.RequestTypes.IIntentRequest))
            {
                Debug.WriteLine(input.Request.Intent.Name);

                var firstNumber  = Convert.ToDouble(input.Request.Intent.Slots["firstnum"].Value);
                var secondNumber = Convert.ToDouble(input.Request.Intent.Slots["secondnum"].Value);
                switch (input.Request.Intent.Name)
                {
                case "AddIntent":
                    result = (int)(firstNumber + secondNumber);
                    break;

                case "SubtractIntent":
                    result = (int)(firstNumber - secondNumber);
                    break;

                case "MultiplyIntent":
                    result = (int)(firstNumber * secondNumber);
                    break;

                case "DivideIntent":
                    result = (int)(firstNumber / secondNumber);
                    break;

                default:
                    result = 42;
                    break;

                    innerResponse = new PlainTextOutputSpeech();
                    ((PlainTextOutputSpeech)innerResponse).Text = $"The result is {result}.";
                }
            }


            var response = new Response
            {
                ShouldEndSession = true,
                OutputSpeech     = innerResponse
            };
            var skillResponse = new SkillResponse
            {
                Response = response,
                Version  = "1.0"
            };

            return(skillResponse);
        }
Пример #12
0
        public static CrunchResponse DialogConfirmIntent(IOutputSpeech outputSpeech, Session attributes, Intent updatedIntent = null)
        {
            var response = BuildResponse(outputSpeech, false, attributes, null, null);

            response.Response.Directives.Add(new DialogConfirmIntent {
                UpdatedIntent = updatedIntent
            });
            return(response);
        }
Пример #13
0
        public static CrunchResponse TellWithCard(IOutputSpeech speechResponse, string title, string content)
        {
            SimpleCard card = new SimpleCard();

            card.Content = content;
            card.Title   = title;

            return(BuildResponse(speechResponse, true, null, null, card));
        }
        public static SkillResponse AskWithCard(IOutputSpeech speechResponse, string title, string content, Reprompt reprompt, Session sessionAttributes)
        {
            SimpleCard card = new SimpleCard();

            card.Content = content;
            card.Title   = title;

            return(BuildResponse(speechResponse, false, sessionAttributes, reprompt, card));
        }
Пример #15
0
        public static CrunchResponse DialogElicitSlot(IOutputSpeech outputSpeech, string slotName, Session attributes, Intent updatedIntent = null)
        {
            var response = BuildResponse(outputSpeech, false, attributes, null, null);

            response.Response.Directives.Add(new DialogElicitSlot(slotName)
            {
                UpdatedIntent = updatedIntent
            });
            return(response);
        }
Пример #16
0
 /// <summary>
 /// run quiz or facts handler depending on state
 /// </summary>
 /// <param name="input"></param>
 /// <param name="innerResponse"></param>
 /// <returns>void</retur
 private void Answer(SkillRequest input, IOutputSpeech innerResponse)
 {
     if (appstate == AppState.Quiz)
     {
         AnswerQuiz(input, innerResponse);
     }
     else
     {
         AnswerFacts(input, innerResponse);
     }
 }
Пример #17
0
        public SkillResponse FunctionHandler(SkillRequest input, ILambdaContext context)
        {
            SkillResponse skillResponse = new SkillResponse();

            skillResponse.Response = new ResponseBody
            {
                ShouldEndSession = false
            };

            IOutputSpeech outputSpeech = null;

            var log = context.Logger;

            if (input.GetRequestType() == typeof(LaunchRequest))
            { // einfacher Aufruf des Skills ohne Aufgabenstellung ( Intent )
              //  log.LogLine("(Line:45) Der Skill " + skillName + " wurde gelaunched.");

                outputSpeech = new PlainTextOutputSpeech();
                (outputSpeech as PlainTextOutputSpeech).Text = "Ich bin bereit ";
            }
            else if (input.GetRequestType() == typeof(IntentRequest)) // hier werden alle nicht 'LaunchRequests' behandelt
            {
                var typeOfTntent = (IntentRequest)input.Request;
                log.LogLine("(Line:53)Ein " + typeOfTntent.ToString() + " wurde erkannt");
                switch (typeOfTntent.Intent.Name)
                {
                // case "CustomIntent":
                //
                //
                // break;
                case "AMAZON.CancelIntent":
                    outputSpeech = new PlainTextOutputSpeech();
                    (outputSpeech as PlainTextOutputSpeech).Text = "Jawohl, ich höre auf";
                    break;

                case   "AMAZON.StopIntent":
                    outputSpeech = new PlainTextOutputSpeech();
                    (outputSpeech as PlainTextOutputSpeech).Text = "Bis zum nächsten mal ";
                    break;

                case   "AMAZON.HelpIntent":
                    outputSpeech = new PlainTextOutputSpeech();
                    (outputSpeech as PlainTextOutputSpeech).Text = "Hilf dir selbst ";
                    break;

                default:
                    outputSpeech = new PlainTextOutputSpeech();
                    (outputSpeech as PlainTextOutputSpeech).Text = typeOfTntent.ToString() + "als " + typeOfTntent.Intent.Name + " erkannt." + " Das werde ich ignorieren "; break;
                }
            }
            skillResponse.Response.OutputSpeech = outputSpeech;
            skillResponse.Version = "1.0";
            return(skillResponse);
        }
Пример #18
0
        public static SkillResponse ToSkillResponse(this IOutputSpeech speech)
        {
            var skillResponse = new SkillResponse();

            skillResponse.Response = new Response {
                OutputSpeech = speech, ShouldEndSession = true
            };
            skillResponse.Version = "1.0";

            return(skillResponse);
        }
        private SkillResponse GetResponseFromEvents(List <MeetupEvent> events)
        {
            if (events == null || !events.Any(e => e != null))
            {
                string speechText = "Quelque chose cloche, je n'ai trouvé aucun événement antérieur.";
                return(ResponseBuilder.Tell(speechText));
            }

            MeetupEvent lastEvent = events.First();

            IOutputSpeech speechResponse = GetSpeechResponse(lastEvent);

            return(ResponseBuilder.Tell(speechResponse));
        }
Пример #20
0
        private SkillResponse GetResponseFromEvents(List <MeetupEvent> events)
        {
            if (events == null || !events.Any(e => e != null))
            {
                string speechText = "Il n'y a présentement pas de prochain événement annoncé.";
                return(ResponseBuilder.Tell(speechText));
            }

            MeetupEvent nextEvent = events.First();

            IOutputSpeech speechResponse = GetSpeechResponse(nextEvent);

            return(ResponseBuilder.Tell(speechResponse));
        }
Пример #21
0
        public SkillResponse FunctionHandlerAsync(SkillRequest input, ILambdaContext context)
        {
            // Objekte vor Aufruf erzeugen
            SkillResponse skillResponse = new SkillResponse();

            skillResponse.Response = new ResponseBody {
                ShouldEndSession = false
            };
            IOutputSpeech outputSpeech  = null;
            IntentRequest intentRequest = input.Request as IntentRequest;
            ILambdaLogger lambdaLogger  = context.Logger;  // log to CloudWatch


            //S3   to be evaluated.

            //  db Connect , problem mit nicht passenden assemblys

            /* string dbconnectstring =StaticValues.SERVER+StaticValues.DATABASE+StaticValues.UID+StaticValues.PASSWORD;
             * MySqlConnection connection = new MySqlConnection(dbconnectstring);
             * MySqlCommand command = connection.CreateCommand();
             * command.CommandText = "SELECT * FROM Waren";
             * MySqlDataReader Reader;
             * connection.Open();
             * Reader = command.ExecuteReader(); */

            if (logging)
            {
                lambdaLogger.LogLine("Log started");
                lambdaLogger.LogLine("FunctionName:" + context.FunctionName + "last edited by " + StaticValues.company);
                lambdaLogger.LogLine("Log ended");
            }

            /* direktes Schreiben in eine Datei geht nicht, da es ein read-only Verzeichnis ist
             * try
             * { System.IO.File.WriteAllText("logfile.txt", "Log started from " + context.FunctionName); }
             * catch(Exception e)
             * {
             *  lambdaLogger.LogLine("Fehler bei logFile :" + e.Message);
             * }
             */



            // (Sprach)ausgabe erstellen
            skillResponse.Response.OutputSpeech = outputSpeech;

            skillResponse.Version = "1.0";
            return(skillResponse);
        }
Пример #22
0
 /// <summary>
 /// Handler for RandomColorIntent. Returns a value indicating whether to end the session. Returns the inner response as an out parameter.
 /// </summary>
 /// <param name="output">Response output speech.</param>
 /// <returns></returns>
 private bool HandleRandomColorIntent(out IOutputSpeech output)
 {
     try
     {
         var r = new Random((int)DateTime.Now.Ticks);
         output = Shared.GetOutput(coolColors[r.Next(coolColors.Length)]);
         return(true);
     }
     catch (Exception ex)
     {
         Shared.LogError("HandleRandomColorIntent", "output", ex);
         output = Shared.GetOutput(Error_Unknown);
         return(false);
     }
 }
Пример #23
0
        /// <summary>
        /// Handler for RandomPizzaIntent. Returns a value indicating whether to end the session. Returns the inner response as an out parameter.
        /// </summary>
        /// <param name="intentRequest">IntentRequest to handle.</param>
        /// <param name="output">Response output speech.</param>
        /// <returns></returns>
        private bool HandleRandomPizzaIntent(IntentRequest intentRequest, out IOutputSpeech output)
        {
            try
            {
                if (intentRequest.Intent.Slots["toppingCount"].Value == null)
                {
                    output = GetOutput(GetRandomPizza());
                    return(true);
                }

                var valid = int.TryParse(intentRequest.Intent.Slots["toppingCount"].Resolution.Authorities[0].Values[0].Value.Id, out var count);

                if (valid && count <= 10 && count >= 0)
                {
                    output = GetOutput(GetRandomPizza(count));
                    return(true);
                }
                else if (count > 10)
                {
                    output = GetOutput(Error_TooManyToppings);
                    return(false);
                }
                else if (count < 0)
                {
                    output = GetOutput(Error_NegativeToppings);
                    return(false);
                }
                else if (!valid && decimal.TryParse(intentRequest.Intent.Slots["toppingCount"].Value, out var countD))
                {
                    output = GetOutput(GetRandomPizza((int)Math.Floor(countD)));
                    return(true);
                }
                else
                {
                    output = GetOutput(Error_BadSlot);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                Log($"....Error: HandleRandomPizzaIntent\r\nRequestId: {_requestId}\r\n{ex.Message}\r\nParamaters: intentRequest = {intentRequest}\r\n{ex}");
                output = GetOutput(Error_Unknown);
                return(false);
            }
        }
Пример #24
0
        public SkillResponse HandleLaunchRequest(string skillID)
        {
            //outSpeech = new PlainTextOutputSpeech();
            outSpeech = new SsmlOutputSpeech();
            switch (skillID)
            {
            case vidCtrlSkillID:
                //(outSpeech as PlainTextOutputSpeech).Text = "How may I help you on Collins Video Control ?";
                (outSpeech as SsmlOutputSpeech).Ssml = SsmlDecorate("Hi There!");
                break;

            default:
                (outSpeech as PlainTextOutputSpeech).Text = "How may I help you on Rockwell's CES system ?";
                break;
            }
            skillResponse.Response.OutputSpeech = outSpeech;
            return(skillResponse);
        }
Пример #25
0
        /// <summary>
        /// Return the response fact, if user enters a known detail for a state e.g. says "17" find the
        /// information for that state e.g. Ohio, and then return the complete set
        /// </summary>
        /// <param name="input"></param>
        /// <param name="innerResponse"></param>
        /// <returns>void</returns>
        private void AnswerFacts(SkillRequest input, IOutputSpeech innerResponse)
        {
            SsmlOutputSpeech output = (innerResponse as SsmlOutputSpeech);

            string textout       = string.Empty;
            var    intentRequest = input.Request;
            Item   item          = GetItem(intentRequest.Intent.Slots, out textout);

            if (item != null && item.Capital != null)
            {
                if (this.USE_CARDS_FLAG)
                {
                    StandardCard card = new StandardCard();

                    card.Title             = GetCardTitle(item);
                    card.text              = GetTextDescription(item);
                    response.Response.Card = card;

                    card.Image = new CardImage();
                    card.Image.LargeImageUrl = GetLargeImage(item);
                    card.Image.SmallImageUrl = GetSmallImage(item);

                    output.Ssml = GetSpeechDescriptionWithCard(item);
                    response.SessionAttributes.Add(RESPONSE, output.Ssml);
                }
                else
                {
                    output.Ssml = GetSpeechDescription(item);
                    response.SessionAttributes.Add(RESPONSE, output.Ssml);
                }

                SsmlOutputSpeech repromptResponse = new SsmlOutputSpeech();
                repromptResponse.Ssml      = DecorateSsml(REPROMPT_SPEECH);
                response.Response.Reprompt = new Reprompt();
                response.Response.Reprompt.OutputSpeech = repromptResponse;
            }
            else
            {
                output.Ssml = GetBadAnswer(textout);
                response.SessionAttributes.Add(RESPONSE, output.Ssml);
                response.Response.Reprompt = new Reprompt();
                response.Response.Reprompt.OutputSpeech = innerResponse;
            }
        }
Пример #26
0
        public SkillResponse FunctionHandler(SkillRequest input, ILambdaContext context)
        {
            SkillResponse skillResponse = new SkillResponse();

            skillResponse.Response = new ResponseBody
            {
                ShouldEndSession = false
            };

            IOutputSpeech outputSpeech  = null;
            var           log           = context.Logger;
            var           intentRequest = input.Request as IntentRequest;

            outputSpeech = new PlainTextOutputSpeech();

            if (input.GetRequestType() == typeof(LaunchRequest))
            { // einfacher Aufruf des Skills ohne Aufgabenstellung ( Intent )
                log.LogLine("39: Launch ");

                (outputSpeech as PlainTextOutputSpeech).Text = "Ergebnis der Suche nach Datenbanken: ";
                AmazonRDSClient amazonRDSClient = new AmazonRDSClient(StaticValues.AWS_ACCESS_KEY, StaticValues.AWS_SECRET_KEY, Amazon.RegionEndpoint.EUCentral1);
                try
                {
                    DescribeDBInstancesRequest request = new DescribeDBInstancesRequest();
                    // request.DBInstanceIdentifier = "opensandbox";
                    var response = amazonRDSClient.DescribeDBInstancesAsync(request);
                    foreach (var instance in response.Result.DBInstances)
                    {
                        log.LogLine(instance.DBName);
                        (outputSpeech as PlainTextOutputSpeech).Text += instance.DBName;
                        (outputSpeech as PlainTextOutputSpeech).Text += instance.Engine + " Version: " + instance.EngineVersion;
                    }
                }
                catch (Exception e)
                {
                    log.LogLine("58:" + e.Message);
                }
            }

            skillResponse.Response.OutputSpeech = outputSpeech;
            skillResponse.Version = "1.0";
            return(skillResponse);
        }
Пример #27
0
        /// <summary>
        /// Check the answer returned and determine the correct response
        /// then configure the next question if there is to be one storing the data
        /// inthe sessionAttributes array
        /// </summary>
        /// <param name="input"></param>
        /// <param name="innerReponse"></param>
        /// <returns>void</returns>
        private void  AnswerQuiz(SkillRequest input, IOutputSpeech innerResponse)
        {
            var intentRequest = input.Request;

            Item item = GetItemAttributeProperty(input.Session.Attributes, QUIZITEM);

            if (item == null)
            {
                GetLaunchRequest();
                return;
            }

            string property = GetStringAttributeProperty(input.Session.Attributes, QUIZPROPERTY);

            quizscore = GetIntAttributeProperty(input.Session.Attributes, QUIZSCORE);

            if (CompareSlots(intentRequest.Intent.Slots, item.PropertyValue(property)))
            {
                quizscore++;
                (innerResponse as SsmlOutputSpeech).Ssml = GetSpeechCon(true);
            }
            else
            {
                (innerResponse as SsmlOutputSpeech).Ssml = GetSpeechCon(false);
            }

            (innerResponse as SsmlOutputSpeech).Ssml += GetAnswer(property, item);
            if (counter < MAX_QUESTION)
            {
                (innerResponse as SsmlOutputSpeech).Ssml += GetCurrentScore(quizscore, counter);
                AskQuestion(input, innerResponse);
            }
            else
            {
                (innerResponse as SsmlOutputSpeech).Ssml += GetFinalScore(quizscore, counter);
                (innerResponse as SsmlOutputSpeech).Ssml += " " + EXIT_SKILL_MESSAGE;
                response.SessionAttributes.Add(RESPONSE, (innerResponse as SsmlOutputSpeech).Ssml);
                appstate = AppState.Start;
                ClearAppState();
            }
        }
Пример #28
0
        /// <summary>
        /// A simple function that takes a string and does a ToUpper
        /// </summary>
        /// <param name="input"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public SkillResponse FunctionHandler(SkillRequest input, ILambdaContext context)
        {
            Response      response;
            IOutputSpeech innerResponse = null;
            var           log           = context.Logger;

            if (input.GetRequestType() == typeof(Slight.Alexa.Framework.Models.Requests.RequestTypes.ILaunchRequest))
            {
                // default launch request, let's just let them know what you can do
                log.LogLine($"Default LaunchRequest made");

                innerResponse = new PlainTextOutputSpeech();
                (innerResponse as PlainTextOutputSpeech).Text = "Welcome to number functions.  You can ask us to add numbers!";
            }
            else if (input.GetRequestType() == typeof(Slight.Alexa.Framework.Models.Requests.RequestTypes.IIntentRequest))
            {
                // intent request, process the intent
                log.LogLine($"Intent Requested {input.Request.Intent.Name}");

                // AddNumbersIntent
                // get the slots
                var n1 = Convert.ToDouble(input.Request.Intent.Slots["firstnum"].Value);
                var n2 = Convert.ToDouble(input.Request.Intent.Slots["secondnum"].Value);

                double result = n1 + n2;

                innerResponse = new PlainTextOutputSpeech();
                (innerResponse as PlainTextOutputSpeech).Text = $"The result is {result.ToString()}.";
            }

            response = new Response();
            response.ShouldEndSession = true;
            response.OutputSpeech     = innerResponse;
            SkillResponse skillResponse = new SkillResponse();

            skillResponse.Response = response;
            skillResponse.Version  = "1.0";

            return(skillResponse);
        }
Пример #29
0
      public async Task <SkillResponse> FunctionHandler(SkillRequest input, ILambdaContext context)
      {
          Response      response;
          IOutputSpeech innerResponse = null;

          log = context.Logger;
          bool shouldEndSession = true;

          textForLog = "";
          string intentName = "";

          try {
              log.LogLine("1");
              innerResponse = new PlainTextOutputSpeech();
              (innerResponse as PlainTextOutputSpeech).Text = "Hi,  Just keep speaking and ask alexa to stop when you are done.";

              log.LogLine("2");
              // intent request, process the intent
              //log.LogLine($"Intent Requested {input.Request.Intent.Name}");
              try
              {
                  intentName = input.Request.Intent.Name;
              } catch
              {
                  try
                  {
                      intentName = input.Request.Type;
                  } catch
                  {
                      intentName = "-no request-";
                  }
              }

              log.LogLine("3");
              log.LogLine("intentName:" + intentName);
              textForLog += Environment.NewLine + "INTENT NAME:";
              textForLog += intentName;
              textForLog += ": BEFORE SWITCH";
              switch (intentName)
              {
              //case "AMAZON.HelpIntent":
              //    (innerResponse as PlainTextOutputSpeech).Text = "Welcome to Pick My Game.  Please try Alexa, Ask Pick My Game to decide for me";
              //    break;
              case "AMAZON.StopIntent":
                  (innerResponse as PlainTextOutputSpeech).Text = "";
                  shouldEndSession = true;
                  break;

              case "AMAZON.CancelIntent":
                  (innerResponse as PlainTextOutputSpeech).Text = "";
                  shouldEndSession = true;
                  break;

              //case "AMAZON.NextIntent":
              //    (innerResponse as PlainTextOutputSpeech).Text = "Welcome to Pick My Game.  Please try Alexa, Ask Pick My Game to decide for me";
              //    break;
              //case "AMAZON.NoIntent":
              //    (innerResponse as PlainTextOutputSpeech).Text = "OK";
              //    break;
              //case "AMAZON.PreviousIntent":
              //    (innerResponse as PlainTextOutputSpeech).Text = "OK";
              //    break;
              //case "AMAZON.RepeatIntent":
              //    (innerResponse as PlainTextOutputSpeech).Text = "OK";
              //    break;
              //case "AMAZON.ResumeIntent":
              //    (innerResponse as PlainTextOutputSpeech).Text = "OK";
              //    break;
              //case "AMAZON.YesIntent":
              //    (innerResponse as PlainTextOutputSpeech).Text = "OK";
              //    break;
              case "StopIntent":
                  (innerResponse as PlainTextOutputSpeech).Text = "";
                  shouldEndSession = true;
                  break;

              case "CancelIntent":
                  (innerResponse as PlainTextOutputSpeech).Text = "";
                  shouldEndSession = true;
                  break;

              case "LaunchRequest":
                  (innerResponse as PlainTextOutputSpeech).Text = "Hi, let me listen to you.  Just keep speaking and ask alexa to stop when you are done.";
                  shouldEndSession = false;
                  break;

              //case "HelpIntent":
              //    //(innerResponse as PlainTextOutputSpeech).Text = "Welcome to Pick My Game.  Please try Alexa, Ask Pick My Game to decide for me";
              //    shouldEndSession = false;
              //    break;
              case "UnknownIntent":
                  (innerResponse as PlainTextOutputSpeech).Text = "Uh huh";
                  break;

              case "ListenIntent":
                  (innerResponse as PlainTextOutputSpeech).Text = "Uh huh";
                  shouldEndSession = false;
                  break;

              default:
                  (innerResponse as PlainTextOutputSpeech).Text = "Uh huh";
                  shouldEndSession = false;
                  break;
              }

              //}
          }
          catch (Exception ex)
          {
              textForLog += Environment.NewLine + ex.Message + Environment.NewLine + textForLog + Environment.NewLine + ex.StackTrace.ToString();
          }
          //if (textForLog != string.Empty) { await SaveTextToLog(textForLog, input); }
          response = new Response();
          response.ShouldEndSession = shouldEndSession;
          response.OutputSpeech     = innerResponse;
          SkillResponse skillResponse = new SkillResponse();

          skillResponse.Response          = response;
          skillResponse.Version           = "1.0";
          skillResponse.SessionAttributes = new System.Collections.Generic.Dictionary <string, object>();

          return(skillResponse);
      }
Пример #30
0
        // LambdaFunction::LambdaFunction.Function::FunctionHandler
        public SkillResponse FunctionHandler(SkillRequest input, ILambdaContext context)
        {
            var log = context.Logger;

            try
            {
                SkillResponse response = new SkillResponse();
                response.Response = new ResponseBody();
                response.Response.ShouldEndSession = false;
                IOutputSpeech innerResponse = null;
                log.LogLine($"Skill Request Object:");
                log.LogLine(JsonConvert.SerializeObject(input));

                var currentQuestion = 0; // TODO get from session

                if (input.GetRequestType() == typeof(LaunchRequest))
                {
                    log.LogLine($"Default LaunchRequest made: 'Alexa, open numbers game");
                    innerResponse = new PlainTextOutputSpeech()
                    {
                        Text = "Welcome to the numbers game! Let's get started: " +
                               numberFacts[currentQuestion].Question
                    };
                }
                else if (input.GetRequestType() == typeof(IntentRequest))
                {
                    var intentRequest = (IntentRequest)input.Request;

                    switch (intentRequest.Intent.Name)
                    {
                    case "AnswerIntent":
                        log.LogLine($"Answer intent");

                        long answer;
                        if (!long.TryParse(intentRequest.Intent.Slots["Answer"].Value, out answer))
                        {
                            (innerResponse as PlainTextOutputSpeech).Text = "Sorry, I didn't quite get that. Please say a number.";
                            break;
                        }

                        log.LogLine($"Answer provided: {answer}");

                        innerResponse = new PlainTextOutputSpeech();

                        var correctAnswer = numberFacts[currentQuestion].Answer;

                        if (answer < correctAnswer)
                        {
                            (innerResponse as PlainTextOutputSpeech).Text = $"No, it's more than {answer}.";
                        }
                        else if (answer > correctAnswer)
                        {
                            (innerResponse as PlainTextOutputSpeech).Text = $"No, it's less than {answer}.";
                        }
                        else
                        {
                            (innerResponse as PlainTextOutputSpeech).Text = $"Yes! {answer} is correct!";
                            response.Response.ShouldEndSession            = true;
                        }

                        break;

                    case "RepeatQuestionIntent":
                        log.LogLine($"RepeatQuestionIntent");
                        innerResponse = new PlainTextOutputSpeech()
                        {
                            Text = numberFacts[currentQuestion].Question
                        };
                        break;

                    case "AMAZON.CancelIntent":
                        log.LogLine($"AMAZON.CancelIntent: send StopMessage");
                        innerResponse = new PlainTextOutputSpeech();
                        //(innerResponse as PlainTextOutputSpeech).Text = resource.StopMessage;
                        response.Response.ShouldEndSession = true;
                        break;

                    case "AMAZON.StopIntent":
                        log.LogLine($"AMAZON.StopIntent: send StopMessage");
                        innerResponse = new PlainTextOutputSpeech();
                        //(innerResponse as PlainTextOutputSpeech).Text = resource.StopMessage;
                        response.Response.ShouldEndSession = true;
                        break;

                    case "AMAZON.HelpIntent":
                        log.LogLine($"AMAZON.HelpIntent: send HelpMessage");
                        innerResponse = new PlainTextOutputSpeech();
                        //(innerResponse as PlainTextOutputSpeech).Text = resource.HelpMessage;
                        break;

                    default:
                        log.LogLine($"Unknown intent: " + intentRequest.Intent.Name);
                        innerResponse = new PlainTextOutputSpeech();
                        //(innerResponse as PlainTextOutputSpeech).Text = resource.HelpReprompt;
                        break;
                    }
                }

                response.Response.OutputSpeech = innerResponse;
                response.Version = "1.0";

                if (response.SessionAttributes == null)
                {
                    response.SessionAttributes = new System.Collections.Generic.Dictionary <string, object>();
                }
                //response.SessionAttributes.Add("foo", count++);

                log.LogLine($"Skill Response Object...");
                log.LogLine(JsonConvert.SerializeObject(response));
                return(response);
            }
            catch (Exception ex)
            {
                log.LogLine("Unhandled exception:");
                log.LogLine(ex.ToString());
                log.LogLine(JsonConvert.SerializeObject(ex));
                throw;
            }
        }