1.0.21 • Published 6 years ago
bot-tg v1.0.21
A package for Telegram's bot API
Table of contents
Examples
Here is an example to use this package:
const TelegramBot = require("bot-tg");
const bot = new TelegramBot({
token: '<YOUR_BOT_TOKEN_HERE>',
commands: [{
id: 'hello',
description: 'click here!',
call: function(userId) {
this.sendMessage(userId, 'World!');
}
}]
});
To get any kind of information from user you should do like that:
const TelegramBot = require("bot-tg");
const bot = new TelegramBot({
token: '<YOUR_BOT_TOKEN_HERE>',
commands: [{
id: 'set',
description: 'set something',
title: 'Send me something:',
done: function(userId, result) {
this.sendMessage(userId, `Result is: ${result}`);
}
}]
});
To make a command hidden when calling the help (or start) command:
const TelegramBot = require("bot-tg");
const bot = new TelegramBot({
token: '<YOUR_BOT_TOKEN_HERE>',
commands: [{
id: 'set',
description: 'set something',
title: 'Send me something:',
done: function(userId, result) {
this.sendMessage(userId, `Result is: ${result}`);
}
}, {
id: 'action',
description: 'admin action',
call: function(userId) {
this.sendMessage(userId, 'Hello, admin!');
}
}]
});
Guides
To make some command hidden from list when calling the help (or start) command use hidden: true property:
const TelegramBot = require("bot-tg");
const bot = new TelegramBot({
token: '<YOUR_BOT_TOKEN_HERE>',
commands: [{
id: 'set',
description: 'set something',
title: 'Send me something:',
done: function(userId, result) {
this.sendMessage(userId, `Result is: ${result}`);
}
}, {
id: 'action',
description: 'admin action',
hidden: true,
call: function(userId) {
this.sendMessage(userId, 'Hello, admin!');
}
}]
});
To enable logging use:
const bot = new TelegramBot({
token: '<YOUR_BOT_TOKEN_HERE>',
logging: true
...
});
New
- When there are no matches with commands list identified at bot's initialization, bot's instance emits a message:
const TelegramBot = require("bot-tg");
const bot = new TelegramBot({
token: '<YOUR_BOT_TOKEN_HERE>',
commands: [{
id: 'set',
description: 'set something',
title: 'Send me something:',
done: function(userId, result) {
this.sendMessage(userId, `Result is: ${result}`);
}
}]
});
bot.on('message', update => {
console.log(update);
});
1.0.21
6 years ago
1.0.20
6 years ago
1.0.19
6 years ago
1.0.18
6 years ago
1.0.17
6 years ago
1.0.16
6 years ago
1.0.15
6 years ago
1.0.14
6 years ago
1.0.13
6 years ago
1.0.12
6 years ago
1.0.11
6 years ago
1.0.10
6 years ago
1.0.9
6 years ago
1.0.8
6 years ago
1.0.7
6 years ago
1.0.6
6 years ago
1.0.5
6 years ago
1.0.4
6 years ago
1.0.3
6 years ago
1.0.2
6 years ago
1.0.1
6 years ago
1.0.0
6 years ago