Although we could use the raw REST API that Telegram offers, we’re going to use a library called Telegraf.

Read a little about it on its official site and on GitHub.

Why use a library? Because every abstraction that can make things easy for us, the better!

This library in particular is very well done, well maintained and has lots of users (all good signs).

Tip: as a general rule I avoid libraries that have one or more years without any update (sign of possible abandon) or a small user base (like very few stars), unless you know what you are doing.

Install the library using npm i telegraf locally, or add it to the package.json file on Glitch.

Add the Telegram token that Botfather gave you to the .env file, to a variable named TELEGRAM_BOT_TOKEN:

TELEGRAM_BOT_TOKEN="XXXXXXXXXXXXX"

Then create a bot.js file and require telegraf:

const Telegraf = require('telegraf')

and initialize it using new Telegraf():

const bot = new Telegraf(process.env.TELEGRAM_BOT_TOKEN)

Go to the next lesson