Пример #1
0
        public string emitNewFact(FactResource resource, bool withPreface)
        {
            Random r = new Random();

            if (withPreface)
            {
                return(resource.GetFactMessage + resource.Facts[r.Next(resource.Facts.Count)]);
            }
            return(resource.Facts[r.Next(resource.Facts.Count)]);
        }
Пример #2
0
        public List <FactResource> GetResources()
        {
            List <FactResource> resources    = new List <FactResource>();
            FactResource        enGBResource = new FactResource("en-GB");

            enGBResource.SkillName      = "Veggie Drinks";
            enGBResource.GetFactMessage = "Here's your science fact: ";
            enGBResource.HelpMessage    = "You can say tell me a science fact, or, you can say exit... What can I help you with?";
            enGBResource.HelpReprompt   = "You can say tell me a science fact to start";
            enGBResource.StopMessage    = "Goodbye!";
            enGBResource.Facts.Add("Tim, do you like sandwiches?.");
            enGBResource.Facts.Add("Tim, what's your favourite colour?.");
            enGBResource.Facts.Add("Tim, how much wood could a woodchuck chuck if a wood chuck could chuck wood?.");
            enGBResource.Facts.Add("Tim, why does this room smell like egg?.");

            resources.Add(enGBResource);
            return(resources);
        }
Пример #3
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)
        {
            SkillResponse response = new SkillResponse();

            response.Response = new ResponseBody();
            response.Response.ShouldEndSession = false;
            IOutputSpeech innerResponse = null;
            var           log           = context.Logger;

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

            List <FactResource> allResources = GetResources();
            FactResource        resource     = allResources.FirstOrDefault();

            if (input.GetRequestType() == typeof(LaunchRequest))
            {
                log.LogLine($"Default LaunchRequest made: 'Alexa, open Veggie Drinks");
                innerResponse = new PlainTextOutputSpeech();
                (innerResponse as PlainTextOutputSpeech).Text = emitNewFact(resource, true);
            }
            else if (input.GetRequestType() == typeof(IntentRequest))
            {
                IntentRequest intentRequest = (IntentRequest)input.Request;

                switch (intentRequest.Intent.Name)
                {
                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;

                case "GetFactIntent":
                    log.LogLine($"GetFactIntent sent: send new fact");
                    innerResponse = new PlainTextOutputSpeech();
                    (innerResponse as PlainTextOutputSpeech).Text = emitNewFact(resource, false);
                    break;

                case "GetNewFactIntent":
                    log.LogLine($"GetFactIntent sent: send new fact");
                    innerResponse = new PlainTextOutputSpeech();
                    (innerResponse as PlainTextOutputSpeech).Text = emitNewFact(resource, false);
                    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";
            log.LogLine($"Skill Response Object...");
            log.LogLine(JsonConvert.SerializeObject(response));
            return(response);
        }