Learn how to create your own Telegram bot using Node.js for free. This is a great alternative for those who are tech-savvy and want to avoid using third-party services.
/newbot
to create a new bot and receive your Bot Token.npm init -y
in the terminal.npm install node-telegram-bot-api
.Create a file called bot.js
and use the following code:
const TelegramBot = require('node-telegram-bot-api');
const token = 'YOUR_BOT_TOKEN_HERE';
const bot = new TelegramBot(token, { polling: true });
bot.on('message', (msg) => {
const chatId = msg.chat.id;
if (msg.text.toLowerCase() === '/start') {
bot.sendMessage(chatId, 'Welcome! I am your new bot. Use /help to see what I can do!');
} else if (msg.text.toLowerCase() === '/help') {
bot.sendMessage(chatId, 'Available commands: \n/start - Start the bot\n/help - Get help');
}
});
Replace YOUR_BOT_TOKEN_HERE
with the token from BotFather.
node bot.js
./start
and /help
.To ensure your bot runs continuously, consider hosting it:
axios
.If creating and maintaining your own bot sounds too complex or time-consuming, consider using our easy-to-use, no-code platform! With BotsOfTelegram, you can create, configure, and deploy complex workflows without any coding knowledge.
Get Started with Our Bot Service