0.1.18 • Published 3 years ago

libtelegram v0.1.18

Weekly downloads
1
License
MIT
Repository
-
Last release
3 years ago

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

ParamTypeDescription
tokenStringTelegram 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

ParamTypeDescription
callbackfunctionMiddleware function

telegram.getUserByID(id) ⇒ User

Getting User by ID

Kind: instance method of Telegram

ParamTypeDescription
idNumberUnique identificator

telegram.hear(name, condition, callback) ⇒ Event

Event creation

Kind: instance method of Telegram

ParamTypeDescription
nameStringNew Event name
conditionfunction | RegExp | StringMessage match.
callbackfunctionCallback function

telegram.createUser(params) ⇒ User

User creation

Kind: instance method of Telegram

ParamTypeDescription
paramsobjectStandart User values

telegram.startPolling(interval) ⇒ Null

Start polling

Kind: instance method of Telegram

ParamTypeDescription
intervalNumberOptional, 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

ParamTypeDescription
pathStringSecret path

telegram.startWebhook(path, tls, port) ⇒ Null

Start receiving messages from webhook

Kind: instance method of Telegram

ParamTypeDescription
pathpathSecret path
tlstlsTLS options, see https module
portportServer port. Default is 8080

Event

Kind: global class

new Event(name, condition, firstStep)

Init Event

ParamTypeDescription
nameStringEvent name. Default is 'menu'
conditionfunction | RegExp | StringMessage match
firstStepfunctionFirst step in the stack

event.condition(message) ⇒ Boolean

Checks if a message matches the condition

Kind: instance method of Event

ParamTypeDescription
messageStringMessage text

event.folow(callback) ⇒ Event

Creates a new step in the event stack

Kind: instance method of Event

ParamTypeDescription
callbackfunctionCallback 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

0.1.18

3 years ago

0.0.17

4 years ago

0.0.18

4 years ago

0.0.15

4 years ago

0.0.16

4 years ago

0.0.14

4 years ago

0.0.13

4 years ago

0.0.12

4 years ago

0.0.11

4 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.3

5 years ago

0.0.4

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

6 years ago