Esempio n. 1
0
        public async Task <SkillResponse> GetWeatherAsync(SkillRequest input)
        {
            try
            {
                string icao;
                AirportIdentifier.Models.AirportIdentifier airportIdentifier;

                var airportName = _slotManager.GetSlotValue(input.Request.Intent.Slots, "AirportName");
                if (airportName.Equals("help", StringComparison.CurrentCultureIgnoreCase))
                {
                    return(GetSkillResponse(HelpText, false));
                }
                if (airportName.Equals("exit", StringComparison.CurrentCultureIgnoreCase) ||
                    airportName.Equals("cancel", StringComparison.CurrentCultureIgnoreCase) ||
                    airportName.Equals("stop", StringComparison.CurrentCultureIgnoreCase))
                {
                    return(GetSkillResponse("", true));
                }

                if (!string.IsNullOrEmpty(airportName))
                {
                    airportIdentifier = await _airportNameConverter.GetAirportIdentifierAsync(airportName, null);

                    icao = airportIdentifier != null ? airportIdentifier.Icao : "";
                }
                else
                {
                    icao = GetIcaoFromSlots(input.Request.Intent.Slots);
                    airportIdentifier = await _airportNameConverter.GetAirportIdentifierByIcaoAsync(icao);
                }

                var metar = string.IsNullOrEmpty(icao) ? null : await _aviationWeatherRetriever.GetMetarAsync(icao);

                return(GetSkillResponse(metar != null
                    ? TranslateMetarToText(metar, airportIdentifier)
                    : "I was unable to find a weather report for " +
                                        (string.IsNullOrEmpty(icao) ? "the given airport." : icao.ToPhonetic()), true));
            }
            catch (Exception e)
            {
                LambdaLogger.Log(e.StackTrace);
                throw;
            }
        }
Esempio n. 2
0
        public async Task <SkillResponse> GetAirportIdentifierAsync(SkillRequest input)
        {
            var airportName = _slotManager.GetSlotValue(input.Request.Intent.Slots, "AirportName");
            var airport     = string.IsNullOrEmpty(airportName)
                ? null
                : await _airportNameConverter.GetAirportIdentifierAsync(airportName, null);

            return(new SkillResponse
            {
                Response = new Response
                {
                    ShouldEndSession = true,
                    OutputSpeech = new PlainTextOutputSpeech
                    {
                        Text = airport == null
                            ? $"I was unable to find an airport identifier for {(string.IsNullOrEmpty(airportName) ? "the given airport" : airportName)}"
                            : $"The airport identifier for {airportName} is {airport.Letters.Replace(" ", ",")}, that's {airport.Phonetic.Replace(" ", ",")}"
                    }
                },
                Version = "1.0"
            });
        }