libtelegram v0.1.18
LibTelegram
Modern Library for Telegram Bots Api 🤖
Installation
$ npm install libtelegram
Example:
const telegram = require('libtelegram')(<TOKEN>);
telegram.hear('menu', '/start', (msg, next) => {
telegram.sendMessage({ id:msg.from.id, text: '1st step' });
next();
}).folow((msg, next, prev, quit) => {
telegram.sendMessage({ id:msg.from.id, text: '2nd step' });
next();
}).folow((msg, next, prev, quit) => {
telegram.sendMessage({ id:msg.from.id, text: '3rd step' });
quit();
}).folow((msg, next, prev, quit) => {
telegram.sendMessage({ id:msg.from.id, text: '4th step' });
prev();
});
telegram.startPolling();
Classes
Telegram
Kind: global class
new Telegram(token)
Init Telegram class
Param | Type | Description |
---|---|---|
token | String | Telegram bot token |
telegram.use(callback) ⇒ Null
Middleware allows you to modify requests and responses as they pass between the Telegram and your bot.
Kind: instance method of Telegram
Param | Type | Description |
---|---|---|
callback | function | Middleware function |
telegram.getUserByID(id) ⇒ User
Getting User by ID
Kind: instance method of Telegram
Param | Type | Description |
---|---|---|
id | Number | Unique identificator |
telegram.hear(name, condition, callback) ⇒ Event
Event creation
Kind: instance method of Telegram
Param | Type | Description |
---|---|---|
name | String | New Event name |
condition | function | RegExp | String | Message match. |
callback | function | Callback function |
telegram.createUser(params) ⇒ User
User creation
Kind: instance method of Telegram
Param | Type | Description |
---|---|---|
params | object | Standart User values |
telegram.startPolling(interval) ⇒ Null
Start polling
Kind: instance method of Telegram
Param | Type | Description |
---|---|---|
interval | Number | Optional, polling interval (ms). Default is 300 |
telegram.webhookCallback(path) ⇒ function
Use webhookCallback() if you want to attach libtelegram to existing http server
Kind: instance method of Telegram
Param | Type | Description |
---|---|---|
path | String | Secret path |
telegram.startWebhook(path, tls, port) ⇒ Null
Start receiving messages from webhook
Kind: instance method of Telegram
Param | Type | Description |
---|---|---|
path | path | Secret path |
tls | tls | TLS options, see https module |
port | port | Server port. Default is 8080 |
Event
Kind: global class
new Event(name, condition, firstStep)
Init Event
Param | Type | Description |
---|---|---|
name | String | Event name. Default is 'menu' |
condition | function | RegExp | String | Message match |
firstStep | function | First step in the stack |
event.condition(message) ⇒ Boolean
Checks if a message matches the condition
Kind: instance method of Event
Param | Type | Description |
---|---|---|
message | String | Message text |
event.folow(callback) ⇒ Event
Creates a new step in the event stack
Kind: instance method of Event
Param | Type | Description |
---|---|---|
callback | function | Callback to be called when the condition matches |
User
Kind: global class
Params: object - Often used values
new User()
Containing user state and offten used values
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago