I will explain how to create a simple telegram bot using Node.js. While creating the Telegram bot, I made the resume pool project that human resources can use
- Receiving job applications from telegram bot
- Receiving applications and transferring them to excel
Here are the steps to run the project locally.
-
Clone the repository
git clone https://github.com/FRTYZ/telegram-bot-nodejs.git
-
Install dependencies
npm install
-
Create Telegram bot
3.1. Open BotFather to create a bot
3.2. Write the command to create a bot
/newbot
3.3. after you set the name and username, the process will look like the following. in the yellow area there will be a shortcut to open your bot. in the red area there is a token, use this token in the env file
-
Make a few connection settings to MongoDB
4.1. Create a cluster from MongoDB Create a new cluster named 'telegramBot'
4.2. Connect Cluster.
Copy the link code in the red field
-
Create the .env file
BOT_TOKEN = <Bot Token> BOT_CHAT_ID = <Bot Chat ID> MONGO_URI = <Bot_Chat_ID>
-
Run the project
npm run dev
-
Project setup is ready. To get bot chat id, open your bot and type the following command. The bot will tell you the chat id.
/chatid
7.1. Copy the chat id and update the
BOT_CHAT_ID
value in the.env
file -
🎉 Project is now ready. The project will run on port
8080
{
"name": "telegram-bot-nodejs",
"version": "1.0.0",
"description": "Create a Telegram Bot with Node.js",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "npx nodemon src/index.js",
"start": "node src/index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"dotenv": "^16.4.5",
"ejs": "^3.1.10",
"exceljs": "^4.4.0",
"express": "^4.21.0",
"express-session": "^1.18.0",
"mongoose": "^8.6.3",
"multer": "^1.4.5-lts.1",
"telegraf": "^4.16.3"
},
"devDependencies": {
"nodemon": "^3.1.6"
}
}