-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.js
More file actions
33 lines (23 loc) · 1.03 KB
/
index.js
File metadata and controls
33 lines (23 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
require('dotenv').config()
const fetch = require("node-fetch")
const Telegram = require("node-telegram-bot-api")
const bot = new Telegram(process.env.TELEGRAM_TOKEN)
const weatherToken = process.env.WEATHER_API_TOKEN
const weatherURL = new URL("https://api.openweathermap.org/data/2.5/weather")
weatherURL.searchParams.set("q", "Haldwani,IN")
weatherURL.searchParams.set("APPID", weatherToken)
weatherURL.searchParams.set("units", "metric")
const getWeatherData = async () => {
const resp = await fetch(weatherURL.toString())
const body = await resp.json()
return body
}
const generateWeatherMessage = weatherData =>
`Good morning! 😊 There will be ${weatherData.weather[0].description} today in ${weatherData.name}. Currently, the temperature is ${weatherData.main.temp} °C. 🌡`
const main = async () => {
const weatherData = await getWeatherData()
const weatherString = generateWeatherMessage(weatherData)
bot.sendMessage(process.env.TELEGRAM_CHAT_ID, weatherString)
console.log(weatherString)
}
main()