コード例 #1
0
ファイル: Function.cs プロジェクト: tejavictory/AlexaApp
        /// <summary>
        ///  Get planetary travel time. Delegate to the dialog
        ///  if the "Complete" protocol flag is not set
        /// </summary>
        /// <param name="factdata"></param>
        /// <param name="request"></param>
        /// <returns>string of travel time</returns>
        private string GetTravelTime(FactData factdata, Request request)
        {
            string speech_message = string.Empty;

            Slot departslot;

            if (request.Intent.Slots.TryGetValue(DEPARTINGPLANET, out departslot))
            {
                Slot arriveslot;
                if (request.Intent.Slots.TryGetValue(ARRIVINGPLANET, out arriveslot))
                {
                    var p1 = departslot.Value.ToLower();
                    var p2 = arriveslot.Value.ToLower();

                    if (factdata.Planets.ContainsKey(p1) && factdata.Planets.ContainsKey(p2))
                    {
                        Planet fromplanet = factdata.Planets[p1];
                        Planet toplanet   = factdata.Planets[p2];

                        speech_message = "It would take about ";
                        var distance      = Math.Abs(fromplanet.ftDistanceFromSun - toplanet.ftDistanceFromSun);
                        var speedOfTravel = factdata.Vehicles["rocket"].ftSpeed;

                        var travelTimeHours = (distance * 1000000) / speedOfTravel;
                        if (travelTimeHours < 24)
                        {
                            var travelTimeMinutes = Math.Round(travelTimeHours * 60);
                            speech_message += travelTimeMinutes + " minutes";
                        }
                        else if (travelTimeHours > 8760)
                        {
                            var travelTimeYears = (travelTimeHours / 8760).ToString("0.##");
                            speech_message += travelTimeYears + " years";
                        }
                        else if (travelTimeHours > 730)
                        {
                            var travelTimeMonths = (travelTimeHours / 730).ToString("0.##");
                            speech_message += travelTimeMonths + " months";
                        }
                        else if (travelTimeHours > 24)
                        {
                            var travelTimeDays = (travelTimeHours / 24).ToString("0.##");
                            speech_message += travelTimeDays + " days";
                        }
                        else
                        {
                            speech_message += travelTimeHours + " hours";
                        }
                        speech_message += " to travel from " + fromplanet.PrintName + " to "
                                          + toplanet.PrintName + " " + factdata.Vehicles["rocket"].VehicleType + "." +
                                          factdata.AskMessage;
                    }
                    else
                    {
                        speech_message = InvalidSlotMessage(factdata, p1, p2);
                    }
                }
            }
            return(speech_message);
        }
コード例 #2
0
ファイル: Function.cs プロジェクト: tejavictory/AlexaApp
        // <summary>
        ///  Process intents that are dialog based and may not have a speech
        ///  response. Speech responses cannot be returned with a delegate response
        /// </summary>
        /// <param name="factdata"></param>
        /// <param name="input"></param>
        /// <param name="response"></param>
        /// <returns>bool true if processed</returns>
        private bool ProcessDialogRequest(FactData factdata, SkillRequest input, SkillResponse response)
        {
            var    intentRequest  = input.Request;
            string speech_message = string.Empty;
            bool   processed      = false;

            switch (intentRequest.Intent.Name)
            {
            case "GetWeather":
                speech_message = GetWeather(factdata, intentRequest);
                if (!string.IsNullOrEmpty(speech_message))
                {
                    response.Response.OutputSpeech = new SsmlOutputSpeech();
                    (response.Response.OutputSpeech as SsmlOutputSpeech).Ssml = SsmlDecorate(speech_message);
                }
                processed = true;
                break;

            case "GetTravelTime":
                speech_message = GetTravelTime(factdata, intentRequest);
                if (!string.IsNullOrEmpty(speech_message))
                {
                    response.Response.OutputSpeech = new SsmlOutputSpeech();
                    (response.Response.OutputSpeech as SsmlOutputSpeech).Ssml = SsmlDecorate(speech_message);
                }
                processed = true;
                break;
            }

            return(processed);
        }
コード例 #3
0
ファイル: Function.cs プロジェクト: tejavictory/AlexaApp
 /// <summary>
 /// Process and respond to the LaunchRequest with launch
 /// and reprompt message
 /// </summary>
 /// <param name="factdata"></param>
 /// <param name="response"></param>
 /// <returns>void</returns>
 private void ProcessLaunchRequest(FactData factdata, ResponseBody response)
 {
     if (factdata != null)
     {
         IOutputSpeech innerResponse = new SsmlOutputSpeech();
         (innerResponse as SsmlOutputSpeech).Ssml = SsmlDecorate(factdata.LaunchMessage);
         response.OutputSpeech = innerResponse;
         IOutputSpeech prompt = new PlainTextOutputSpeech();
         (prompt as PlainTextOutputSpeech).Text = factdata.LaunchMessageReprompt;
         response.Reprompt = new Reprompt()
         {
             OutputSpeech = prompt
         };
     }
 }
コード例 #4
0
ファイル: Function.cs プロジェクト: tejavictory/AlexaApp
        /// <summary>
        ///  Get a new random fact from the fact list.
        /// </summary>
        /// <param name="factdata"></param>
        /// <param name="withPreface"></param>
        /// <returns>string newfact</returns>
        private string GetNewFact(FactData factdata, bool withPreface)
        {
            string preface = string.Empty;

            if (factdata == null)
            {
                return(string.Empty);
            }

            if (withPreface)
            {
                preface = factdata.GetFactMessage;
            }

            return(preface + factdata.Facts[rand.Next(factdata.Facts.Count)] + factdata.AskMessage);
        }
コード例 #5
0
ファイル: Function.cs プロジェクト: tejavictory/AlexaApp
        /// <summary>
        ///  create a invalid slot value message
        /// </summary>
        /// <param name="factdata"></param>
        /// <param name="departKey"></param>
        /// <param name="arriveKey"></param>
        /// <returns>string invalid planet name or empty string</returns>
        private string InvalidSlotMessage(FactData factdata, string departKey, string arriveKey)
        {
            string output = String.Empty;

            if (!factdata.Planets.ContainsKey(departKey))
            {
                output = "There is no planet by name " + departKey + ", would you please provide a valid planet name ? " +
                         factdata.HelpMessage;
            }
            else if (!factdata.Planets.ContainsKey(arriveKey))
            {
                output = "There is no planet by name " + arriveKey + ", would you please provide a valid planet name ? " +
                         factdata.HelpMessage;
            }
            return(output);
        }
コード例 #6
0
ファイル: Function.cs プロジェクト: tejavictory/AlexaApp
        /// <summary>
        /// Process all not dialog based Intents
        /// </summary>
        /// <param name="factdata"></param>
        /// <param name="input"></param>
        /// <returns>IOutputSpeech innerResponse</returns>
        private IOutputSpeech ProcessIntentRequest(FactData factdata, SkillRequest input)
        {
            var           intentRequest = input.Request;
            IOutputSpeech innerResponse = new PlainTextOutputSpeech();

            switch (intentRequest.Intent.Name)
            {
            case "GetNewFactIntent":
                innerResponse = new SsmlOutputSpeech();
                (innerResponse as SsmlOutputSpeech).Ssml = GetNewFact(factdata, true);
                break;

            case "GetJoke":
                innerResponse = new SsmlOutputSpeech();
                (innerResponse as SsmlOutputSpeech).Ssml = GetJoke(factdata);
                break;

            case AlexaConstants.CancelIntent:
                (innerResponse as PlainTextOutputSpeech).Text = factdata.StopMessage;
                response.Response.ShouldEndSession            = true;
                break;

            case AlexaConstants.StopIntent:
                (innerResponse as PlainTextOutputSpeech).Text = factdata.StopMessage;
                response.Response.ShouldEndSession            = true;
                break;

            case AlexaConstants.HelpIntent:
                (innerResponse as PlainTextOutputSpeech).Text = factdata.HelpMessage;
                break;

            default:
                (innerResponse as PlainTextOutputSpeech).Text = factdata.HelpReprompt;
                break;
            }
            if (innerResponse.Type == AlexaConstants.SSMLSpeech)
            {
                BuildCard(factdata.SkillName, (innerResponse as SsmlOutputSpeech).Ssml);
                (innerResponse as SsmlOutputSpeech).Ssml = SsmlDecorate((innerResponse as SsmlOutputSpeech).Ssml);
            }
            return(innerResponse);
        }
コード例 #7
0
ファイル: Function.cs プロジェクト: tejavictory/AlexaApp
        /// <summary>
        /// Get the fatcs and questions for the specified locale
        /// </summary>
        /// <param name="locale"></param>
        /// <returns>factdata for the locale</returns>
        private FactData GetFacts(string locale)
        {
            if (resources == null)
            {
                resources = FactData.LoadFacts();
            }

            if (string.IsNullOrEmpty(locale))
            {
                locale = USA_Locale;
            }

            foreach (FactData factdata in resources)
            {
                if (factdata.Locale.Equals(locale))
                {
                    return(factdata);
                }
            }
            return(null);
        }
コード例 #8
0
ファイル: Function.cs プロジェクト: tejavictory/AlexaApp
        /// <summary>
        ///  Get weather information for a planet. Delegate to the dialog
        ///  if the Complete protocol flag is not set
        /// </summary>
        /// <param name="factdata"></param>
        /// <param name="request"></param>
        /// <returns>string weather newfact or empty string</returns>
        private string GetWeather(FactData factdata, Request request)
        {
            string speech_message = string.Empty;

            if (request.Intent.Slots.ContainsKey(PLANETS))
            {
                Slot slot = null;
                if (request.Intent.Slots.TryGetValue(PLANETS, out slot))
                {
                    if (slot.Value != null && factdata.Planets.ContainsKey(slot.Value.ToLower()))
                    {
                        Planet planet = factdata.Planets[slot.Value.ToLower()];
                        speech_message = "The forecast for " + planet.PrintName + " is " + planet.Weather +
                                         factdata.AskMessage;
                    }
                    else
                    {
                        speech_message = InvalidSlotMessage(factdata, slot.Value, "");
                    }
                }
            }
            return(speech_message);
        }
コード例 #9
0
ファイル: Function.cs プロジェクト: tejavictory/AlexaApp
 /// <summary>
 ///  Get a new random joke, are these funny?
 /// </summary>
 /// <param name="factdata"></param>
 /// <returns>string joke</returns>
 private string GetJoke(FactData factdata)
 {
     return(factdata.Jokes[rand.Next(factdata.Jokes.Count)] + factdata.AskMessage);
 }
コード例 #10
0
        /// <summary>
        ///  Load the resources into the resourse array for processing
        /// </summary>
        /// <returns>void</returns>
        public static List <FactData> LoadFacts()
        {
            List <FactData> facts = new List <FactData>();

            FactData factUS = new FactData("en-US");


            factUS.SkillName      = "Spacey";
            factUS.GetFactMessage = "Here's an interesting one: ";
            factUS.HelpMessage    = "You can say tell me a space fact, ask me for the travel time between two planets," +
                                    "the weather on a planet, or, ask me to tell a joke, or, you can say exit...What can I help you with ?";
            factUS.HelpReprompt  = "What can I help you with?";
            factUS.StopMessage   = "Goodbye!";
            factUS.LaunchMessage = "Welcome to Spacey. I know facts about space, how long it takes to travel between " +
                                   "two planets, the weather when you get there, and I even know a joke. What would you like to know?";
            factUS.LaunchMessageReprompt = "Try asking me to tell you something about space.";
            factUS.AskMessage            = " what else would you like to know?";

            factUS.Facts.Add("A year on Mercury is just 88 days long.");
            factUS.Facts.Add("Despite being farther from the Sun, Venus experiences higher temperatures than Mercury.");
            factUS.Facts.Add("Venus rotates counter-clockwise, possibly because of a collision in the past with an asteroid.");
            factUS.Facts.Add("On Mars, the Sun appears about half the size as it does on Earth.");
            factUS.Facts.Add("Earth is the only planet not named after a god.");
            factUS.Facts.Add("Jupiter has the shortest day of all the planets.");
            factUS.Facts.Add("The Milky Way galaxy will collide with the Andromeda Galaxy in about 5 billion years.");
            factUS.Facts.Add("The Sun contains 99.86% of the mass in the Solar System.");
            factUS.Facts.Add("The Sun is an almost perfect sphere.");
            factUS.Facts.Add("A total solar eclipse can happen once every 1 to 2 years. This makes them a rare event.");
            factUS.Facts.Add("Saturn radiates two and a half times more energy into space than it receives from the sun.");
            factUS.Facts.Add("The temperature inside the Sun can reach 15 million degrees Celsius.");
            factUS.Facts.Add("The Moon is moving approximately 3.8 cm away from our planet every year.");

            factUS.Jokes.Add("What is a spaceman’s favorite chocolate? <break time=\"1s\"/>A marsbar!");
            factUS.Jokes.Add("What kind of music do planets sing? <break time=\"1s\"/>Neptunes!'");
            factUS.Jokes.Add("What do aliens on the metric system say? <break time=\"1s\"/>Take me to your liter.");
            factUS.Jokes.Add("Why did the people not like the restaurant on the moon? <break time=\"1s\"/>Because there was no atmosphere.");
            factUS.Jokes.Add("I’m reading a book about anti-gravity. <break time=\"1s\"/>It’s impossible to put down!");
            factUS.Jokes.Add("How many ears does Captain Kirk have? <break time=\"1s\"/>Three. A left ear, a right ear, and a final frontier!");
            factUS.Jokes.Add("What did Mars say to Saturn? <break time=\"1s\"/>Give me a ring sometime!'");

            factUS.Vehicles.Add("car", new Vehicle("65", "in a car"));
            factUS.Vehicles.Add("jet", new Vehicle("500", "in a jetliner"));
            factUS.Vehicles.Add("concorde", new Vehicle("1350", "in a Concorde"));
            factUS.Vehicles.Add("rocket", new Vehicle("11250", "by rocket"));
            factUS.Vehicles.Add("light", new Vehicle("670616629", "at the speed of light"));

            factUS.Planets.Add("mercury", new Planet("36", "high of 840 and low of minus 275 fahrenheit. Nothing but sun.", "Mercury"));
            factUS.Planets.Add("venus", new Planet("67.2", "high and low of 870 fahrenheit. Expect thick cloud cover <break time=\"1s\"/> forever.", "Venus"));
            factUS.Planets.Add("earth", new Planet("93", "high of 136 and low of minus 129 fahrenheit. Anything can happen on this planet.", "Earth"));
            factUS.Planets.Add("mars", new Planet("141.6", "high of 70 and low of minus 195 fahrenheit. Sunny with a chance of sandstorms later in the day.", "Mars"));
            factUS.Planets.Add("jupiter", new Planet("483.6", "high of minus 148 and low of minus 234 fahrenheit. Storms are highly likely, bringing heavy rain and high winds.", "Jupiter"));
            factUS.Planets.Add("saturn", new Planet("886.7", "high of 134 and low of minus 288 fahrenheit. Cloudy with a chance of super storm.", "Saturn"));
            factUS.Planets.Add("uranus", new Planet("1784", "high and low of minus 357 fahrenheit. Cloudy with a chance of storms.", "Uranus"));
            factUS.Planets.Add("neptune", new Planet("2794.4", "high of minus 328 and low of minus 360 fahrenheit. Extreme wind and a change of storms.", "Neptune"));
            factUS.Planets.Add("pluto", new Planet("3674.5", "high of minus 387 and low of minus 396 fahrenheit. Snow is expected.", "Pluto"));

            facts.Add(factUS);

            FactData factGB = new FactData("en-GB");

            factGB.SkillName      = "Spacey";
            factGB.GetFactMessage = "Here's an interesting one: ";
            factGB.HelpMessage    = "You can say tell me a space fact, ask me for the travel time between two planets," +
                                    "the weather on a planet, or, ask me to tell a joke, or, you can say exit...What can I help you with ?";
            factGB.HelpReprompt  = "What can I help you with?";
            factGB.StopMessage   = "Goodbye!";
            factGB.LaunchMessage = "Welcome to Spacey. I know facts about space, how long it takes to travel between two planets, " +
                                   "their weather, and I even know a joke. What would you like to know?";
            factGB.LaunchMessageReprompt = "Try asking me to tell you something about space.";
            factGB.AskMessage            = " what else would you like to know?";

            factGB.Facts.Add("A year on Mercury is just 88 days long.");
            factGB.Facts.Add("Despite being farther from the Sun, Venus experiences higher temperatures than Mercury.");
            factGB.Facts.Add("Venus rotates counter-clockwise, possibly because of a collision in the past with an asteroid.");
            factGB.Facts.Add("On Mars, the Sun appears about half the size as it does on Earth.");
            factGB.Facts.Add("Earth is the only planet not named after a god.");
            factGB.Facts.Add("Jupiter has the shortest day of all the planets.");
            factGB.Facts.Add("The Milky Way galaxy will collide with the Andromeda Galaxy in about 5 billion years.");
            factGB.Facts.Add("The Sun contains 99.86% of the mass in the Solar System.");
            factGB.Facts.Add("The Sun is an almost perfect sphere.");
            factGB.Facts.Add("A total solar eclipse can happen once every 1 to 2 years. This makes them a rare event.");
            factGB.Facts.Add("Saturn radiates two and a half times more energy into space than it receives from the sun.");
            factGB.Facts.Add("The temperature inside the Sun can reach 15 million degrees Celsius.");
            factGB.Facts.Add("The Moon is moving approximately 3.8 cm away from our planet every year.");

            factGB.Jokes.Add("What is a spaceman’s favorite chocolate? <break time=\"1s\"/>A marsbar!");
            factGB.Jokes.Add("What kind of music do planets sing? <break time=\"1s\"/>Neptunes!'");
            factGB.Jokes.Add("What do aliens on the metric system say? <break time=\"1s\"/>Take me to your liter.");
            factGB.Jokes.Add("Why did the people not like the restaurant on the moon? <break time=\"1s\"/>Because there was no atmosphere.");
            factGB.Jokes.Add("I’m reading a book about anti-gravity. <break time=\"1s\"/>It’s impossible to put down!");
            factGB.Jokes.Add("How many ears does Captain Kirk have? <break time=\"1s\"/>Three. A left ear, a right ear, and a final frontier!");
            factGB.Jokes.Add("What did Mars say to Saturn? <break time=\"1s\"/>Give me a ring sometime!'");

            factGB.Vehicles.Add("car", new Vehicle("65", "in a car"));
            factGB.Vehicles.Add("jet", new Vehicle("500", "in a jetliner"));
            factGB.Vehicles.Add("concorde", new Vehicle("1350", "in a Concorde"));
            factGB.Vehicles.Add("rocket", new Vehicle("11250", "by rocket"));
            factGB.Vehicles.Add("light", new Vehicle("670616629", "at the speed of light"));

            factGB.Planets.Add("mercury", new Planet("36", "high of 840 and low of minus 275 fahrenheit. Nothing but sun.", "Mercury"));
            factGB.Planets.Add("venus", new Planet("67.2", "high and low of 870 fahrenheit. Expect thick cloud cover <break time=\"1s\"/> forever.", "Venus"));
            factGB.Planets.Add("earth", new Planet("93", "high of 136 and low of minus 129 fahrenheit. Anything can happen on this planet.", "Earth"));
            factGB.Planets.Add("mars", new Planet("141.6", "high of 70 and low of minus 195 fahrenheit. Sunny with a chance of sandstorms later in the day.", "Mars"));
            factGB.Planets.Add("jupiter", new Planet("483.6", "high of minus 148 and low of minus 234 fahrenheit. Storms are highly likely, bringing heavy rain and high winds.", "Jupiter"));
            factGB.Planets.Add("saturn", new Planet("886.7", "high of 134 and low of minus 288 fahrenheit. Cloudy with a chance of super storm.", "Saturn"));
            factGB.Planets.Add("uranus", new Planet("1784", "high and low of minus 357 fahrenheit. Cloudy with a chance of storms.", "Uranus"));
            factGB.Planets.Add("neptune", new Planet("2794.4", "high of minus 328 and low of minus 360 fahrenheit. Extreme wind and a change of storms.", "Neptune"));
            factGB.Planets.Add("pluto", new Planet("3674.5", "high of minus 387 and low of minus 396 fahrenheit. Snow is expected.", "Pluto"));

            facts.Add(factGB);
            return(facts);
        }