Back to articles
how to build a telegram bot in node.js from scratch (no frameworks)

how to build a telegram bot in node.js from scratch (no frameworks)

via Dev.to JavaScriptTateLyman

so you want to build a telegram bot. cool. most tutorials tell you to install telegraf or some bloated framework. you don't need any of that. i've built bots with 40+ commands and thousands of users using nothing but node.js and the telegram bot API directly. here's how to do it from zero. why skip the frameworks telegraf, grammY, node-telegram-bot-api — they all add abstraction you don't need. the telegram bot API is just HTTP requests. you already know how to do that. plus when something breaks (and it will), you want to understand what's actually happening. not dig through some framework's source code at 2am. step 1: get your bot token talk to @botfather on telegram. send /newbot , pick a name, get your token. save it somewhere safe. don't commit it to github (yes people do this). const TOKEN = process . env . BOT_TOKEN || require ( ' fs ' ). readFileSync ( ' .token ' , ' utf8 ' ). trim (); const API = `https://api.telegram.org/bot ${ TOKEN } ` ; i usually keep mine in a .token file

Continue reading on Dev.to JavaScript

Opens in a new tab

Read Full Article
3 views

Related Articles