Telegram bots

Learn how to create a bot for Telegram on the easy way.

A bot is only a Telegram account managed by software. You can give it some IA. It could do anything that you can do with Telegram, you should be creative.

I have a starter template on GitHub, you can clone it from https://github.com/jesusgn90/telegram-node, next step is get a token from the https://core.telegram.org/bots#3-how-do-i-create-a-bot. Once you have cloned the repository and you have requested a valid token, create a file named config.js with the following content:

1
2
3
4
// config.js
module.exports = {
TOKEN : 'YOUR_TOKEN'
}

Install the dependencies and start the bot:

1
2
$ npm install
$ npm start

Example

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

// Dependencies
const TeleBot = require('telebot');
const config = require('./config');

// Initialize
const bot = new TeleBot(config.TOKEN);

// Command listener
bot.on(['/bar'], msg => {
msg.reply.text('You are under /bar command controller');
});

// Event listener
bot.on('text', msg => {
msg.reply.text('Someone write something');
});

// Event listener
bot.on('sticker', msg => {
msg.reply.text('Someone sent a sticker');
});

// Starts the bot
bot.start();

It’s very simple to use, you can make it more and more complex, you have the power of a Node.js backend.

References