1.0.21 • Published 5 years ago

bot-tg v1.0.21

Weekly downloads
3
License
ISC
Repository
github
Last release
5 years ago

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

5 years ago

1.0.20

5 years ago

1.0.19

5 years ago

1.0.18

5 years ago

1.0.17

5 years ago

1.0.16

5 years ago

1.0.15

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago