Telegram bot can be used to know the complete weather details of any city, state, a country without going using another application. Telegram provides a bunch of API methods to perform different functions. You can use telegram bot API to create a Chatbot that returns the weather-based information about a city, state, or country based on the parameters and command sent to the bot.
- The latest version of Node (version > 10)
- The latest version of npm (version > 6)
Command to check if Node and npm are present in your system:
$ npm --v 6.14.5 $ node --version v10.15.0
Creating Bot and getting API token:
- Open the telegram app and search for @BotFather.
- Click on the start button or send “/start”.
- Then send “/newbot” message to set up a name and a username.
- The BotFather will then give you an API token.
Getting Weather API key:
- Go to the Open weather map website.
- Create an account as per the limit.
- You will receive your own API key.
- Read the documentation if you want to use different parameters instead of the city name.
Install requests and node-telegram-bot-api (Node.js module to interact with the official Telegram Bot API)
$ npm install --save requests node-telegram-bot-api
Steps to run the program: Run weather.js file using the following command:
$ node weather.js
Go to your bot and type /city city-name and see the results.