public async Task <SkillResponse> FunctionHandler(SkillRequest input, ILambdaContext context) { var requestType = input.GetRequestType(); if (requestType == typeof(IntentRequest)) { if (input.Request is IntentRequest intentRequest) { if (intentRequest.Intent.Slots.ContainsKey("Origin") && intentRequest.Intent.Slots.ContainsKey("Destiny")) { var originCode = CityNameCityCodeMapper.MapToCode(intentRequest.Intent.Slots["Origin"].Value.ToLower()); var destinyCode = CityNameCityCodeMapper.MapToCode(intentRequest.Intent.Slots["Destiny"].Value.ToLower()); DateTime?date = intentRequest.Intent.Slots.ContainsKey("Date") ? DateTime.Parse(intentRequest.Intent.Slots["Date"].Value) : (DateTime?)null; var response = await GetItineraryInfo(originCode, destinyCode, date, context); return(MakeSkillResponse(response, false)); } } else { context.Logger.LogLine($"The country was not understood."); return(MakeSkillResponse("I'm sorry, but I didn't understand the country you were asking for. Please ask again.", false)); } } return(MakeSkillResponse( $"I don't know how to handle this intent. Please say something like Alexa, ask {INVOCATION_NAME} from New York City to Los Angeles.", true)); }
private string GetScheduleMessage(List <ScheduleDesc> schedule) { var message = new StringBuilder(); if (schedule.Count == 1) { var flight = schedule.Single(); DateTime time = DateTime.Parse(flight.departure.time); var depart = !string.IsNullOrEmpty(CityNameCityCodeMapper.MapToLocation(flight.departure.airport)) ? CityNameCityCodeMapper.MapToLocation(flight.departure.airport) : flight.departure.airport; var arrival = !string.IsNullOrEmpty(CityNameCityCodeMapper.MapToLocation(flight.arrival.airport)) ? CityNameCityCodeMapper.MapToLocation(flight.arrival.airport) : flight.arrival.airport; message.AppendLine($"It's direct flight from {depart} to {arrival} at {time.TimeOfDay}"); } else { foreach (var flight in schedule) { DateTime time = DateTime.Parse(flight.departure.time); var depart = !string.IsNullOrEmpty(CityNameCityCodeMapper.MapToLocation(flight.departure.airport)) ? CityNameCityCodeMapper.MapToLocation(flight.departure.airport) : flight.departure.airport; var arrival = !string.IsNullOrEmpty(CityNameCityCodeMapper.MapToLocation(flight.arrival.airport)) ? CityNameCityCodeMapper.MapToLocation(flight.arrival.airport) : flight.arrival.airport; message.AppendLine($"Take {depart} to {arrival} at {time.TimeOfDay}."); } } return(message.ToString()); }