public static async Task Geocode(TelegramBotClient botHandle, Message source, GroupCollection matches) { var responseText = Strings.GeocodeDefault; if (!string.IsNullOrWhiteSpace(matches[2].Value)) { var addresses = await Geocoder.GetAddresses(matches[2].Value); var address = addresses?.FirstOrDefault(); responseText = address != null?FormatGeolocation(address) : Strings.GeocodeNotFound; } await botHandle.SendSmartTextMessageAsync(source, responseText, ParseMode.Html); }
private static async Task <string> GetLocationWeather(string location) { var addressResults = await Geocoder.GetAddresses(location); var address = addressResults.FirstOrDefault(); if (address != null) { var weatherInfo = await Weather.GetForecast(address.Coordinates.Latitude, address.Coordinates.Longitude); return(FormatWeather(weatherInfo, address)); } return(Strings.WeatherNotFound); }
public static async Task SetLocation(TelegramBotClient botHandle, Message source, GroupCollection matches) { var responseText = Strings.GeocodeDefault; if (!string.IsNullOrWhiteSpace(matches[2].Value)) { var addresses = await Geocoder.GetAddresses(matches[2].Value); var address = addresses?.FirstOrDefault(); if (address != null) { await AddOrUpdateLocation(source.From.Id, address); responseText = string.Format(Strings.GeocodeLocationSet, address.FormattedAddress); } else { responseText = Strings.GeocodeNotFound; } } await botHandle.SendSmartTextMessageAsync(source, responseText); }