The application is powered by Github Actions to automatically push weather notification to a personal telegram bot at specific intervals. It is built on Javascript making use of NodeJS libraries.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
You will need the below installed on your computer
$ git clone https://github.com/richierich25/weather-bot.git
$ cd weather-bot
$ npm i
Create a file called .env
in the root directory of your project. OR Note: Instead of creating a .env
file, create a replica of the env.example
file provided
$ cp env.example .env
Inside the .env
file, add key WEATHER_API_TOKEN
obtained from OpenWeather App. One must create an account and copy the API Key from My API Key Section.
WEATHER_API_TOKEN = "YOUR OPEN WEATHER API TOKEN HERE"
Inside the .env
file, add key TELEGRAM_TOKEN
and TELEGRAM_CHAT_ID
obtained from Telegram Bots App. Follow the below steps:
@BotFather
)start
and type /newbot
bot
at its end, for instance Richierich25_bot
HTTP API Key
or TELEGRAM_TOKEN
. Open the link provided. important as the bot has to be started for it to receive messages laterstart
or to start chatting with the newly created botTELEGRAM_CHAT_ID
, search for the @get_id_bot
account and pressstart
TELEGRAM_TOKEN = "YOUR TELEGRAM TOKEN HERE"
TELEGRAM_CHAT_ID = "YOUR TELEGRAM CHAT ID HERE"
Inside the index.js
, set the id
corresponding to your city obtained from here.
search
, for instance, Delhi
https://openweathermap.org/city/1273294
where 1273294 will be the ID corresponding to the city weatherURL.searchParams.set('id', '1273294'); // use the desired id here
When you are done with the setup, and have tested locally, we recommend you to deploy it using Github Actions. We highly recommend to read through the Using Github Actions docs.
Inside the .github/workflows/run-weather-bot.yml
file, set the desired time interval in CRON FORMAT after which you wish the Application to execute and push further notifications
schedule:
- cron: '0 */3 * * *' #after every 3 hours
Adding API Tokens and Secrets into the repository
Settings
from the Github Menu optionsSecrets
from the left sectionNew Secret
and add your tokens one by one by giving it a suitable Name
and Value
WEATHER_API_TOKEN
, TELEGRAM_TOKEN
and TELEGRAM_CHAT_ID
If you wish to contribute and make it much better for other developers, please have a look at Issues.
If you can help us with these. Please donβt hesitate to open a pull request.
We encourage you to contribute. Please check out the Contributing guide for guidelines on how to proceed.
Author: richierich25
Source Code: https://github.com/richierich25/weather-bot
#nodejs #node #javascript