Reply in Telegram with the current conditions for whatever place someone names in the chat.
Uses
OpenWeatherMap
Telegram
Look up the weather from Telegram
Whenever a message in your Telegram chat starts with your chosen keyword followed by a place name, the current conditions there are looked up and the reply comes back in the same chat: conditions, temperature and what it feels like, humidity and wind. Multi-word places work, and so does a postal code or a name with a country code when the plain name is ambiguous.
The reply reports the readings that came back and nothing more. It does not warn about severe weather, because a current reading is not a warning, and any reading the service does not return is left out rather than shown as zero. A place that cannot be found gets a reply saying so, with a hint about adding a country code. Messages that do not start with the keyword are ignored, so the bot stays quiet in a busy group.
You need a Telegram bot in the chat and a keyword for it to listen for, and temperatures come back in the units you choose.
message.When a new message is received. Save it as message.weatherKeyword to blank.Set weatherKeyword to blank.units to metric.Set units to metric.chatId to message.chat_id.Set chatId to message.chat_id.messageText to blank.Set messageText to blank.noTextErrorIf a step below fails, save the error as noTextErrormessage.text and save it as messageText.Trim message.text and save it as messageText.This message carried no text, so there was nothing to look up..Show in the output: This message carried no text, so there was nothing to look up..messageText is emptyIf messageText is emptymessageText by a space and save it as words.Split messageText by a space and save it as words.words[0] lowercase and save it as commandWord.Make words[0] lowercase and save it as commandWord.commandWord is not weatherKeyword in lowercaseIf commandWord is not weatherKeyword in lowercasewords joined by a space and save it as place.Trim the items from index 1 onward of words joined by a space and save it as place.place is empty or the length of place is greater than 60If place is empty or the length of place is greater than 60chatId.Send a message to chat chatId.Send a place after '@weatherKeyword', for example: weatherKeyword Londonweather to nothing.Set weather to nothing.lookupFailed to false.Set lookupFailed to false.weatherErrorIf a step below fails, save the error as weatherErrorweather.Get the current weather. Save it as weather.lookupFailed to true.Change lookupFailed to true.lookupFailed is yesIf lookupFailed is yeschatId.Send a message to chat chatId.I could not look up the weather for place. Try adding a country code, like London,GB, or a postal code.place.Finish the run: No weather was found for place.temperatureUnit to K.Set temperatureUnit to K.windUnit to m/s.Set windUnit to m/s.weather.units is metricIf weather.units is metrictemperatureUnit to °C.Change temperatureUnit to °C.weather.units is imperialIf weather.units is imperialtemperatureUnit to °F.Change temperatureUnit to °F.windUnit to mph.Change windUnit to mph.replyLines to an empty list.Set replyLines to an empty list.heading to place.Set heading to place.weather.location isn't emptyIf weather.location isn't emptyheading to weather.location.Change heading to weather.location.weather.country isn't emptyIf weather.country isn't emptyheading to heading, weather.country.Change heading to heading, weather.country.heading to the end of replyLines and save it as replyLines.Add heading to the end of replyLines and save it as replyLines.weather.conditions isn't emptyIf weather.conditions isn't emptyweather.conditions to the end of replyLines and save it as replyLines.Add Conditions: weather.conditions to the end of replyLines and save it as replyLines.weather.temperature isn't emptyIf weather.temperature isn't emptyweather.temperature formatted as a plain number with 1 decimal place@temperatureUnit to the end of replyLines and save it as replyLines.Add Temperature: weather.temperature formatted as a plain number with 1 decimal place@temperatureUnit to the end of replyLines and save it as replyLines.weather.feels_like isn't emptyIf weather.feels_like isn't emptyweather.feels_like formatted as a plain number with 1 decimal place@temperatureUnit to the end of replyLines and save it as replyLines.Add Feels like: weather.feels_like formatted as a plain number with 1 decimal place@temperatureUnit to the end of replyLines and save it as replyLines.weather.humidity isn't emptyIf weather.humidity isn't emptyweather.humidity formatted as a plain number with 0 decimal places% to the end of replyLines and save it as replyLines.Add Humidity: weather.humidity formatted as a plain number with 0 decimal places% to the end of replyLines and save it as replyLines.weather.wind_speed isn't emptyIf weather.wind_speed isn't emptyweather.wind_speed formatted as a plain number with 1 decimal place@windUnit to the end of replyLines and save it as replyLines.Add Wind: weather.wind_speed formatted as a plain number with 1 decimal place@windUnit to the end of replyLines and save it as replyLines.Current conditions reported by OpenWeatherMap. to the end of replyLines and save it as replyLines.Add Current conditions reported by OpenWeatherMap. to the end of replyLines and save it as replyLines.chatId.Send a message to chat chatId.replyLines joined by a new line