tgapi
Actual Telegram bot API JS implementation
Installation
- npm:
npm install --save tgapi
- yarn:
yarn add tgapi
Usage
Calling bot API methods
In order to send requests to API, we need to create the Bot
instance.
The Bot
is an object that contains all bot API methods.
Each bot API method returns a promise, on successful execution of which the
result will be the response object of the API server
described in the documentation.
In this example, we call getMe and sendPhoto methods:
const Bot = const fs = const bot = '<your bot token>' bot // { ok: true, // result: { // id: 12345, // is_bot: true, // first_name: "My awesome bot", // username: "myawesomebot" } } const chat_id = 100500const photo = fs bot // { ok: true, result: { Message object } } bot // { ok: true, result: { Message object } }
Etc. for all other methods.
Serializable method parameters
Telegram requires serializing some parameters of methods. You do not need to do this, because this is done automatically.
Working with updates
EventEmitter
As // All options are optioalconst polling = bot pollingpollingpolling
As Observable stream
const from = const updates$ = const messages$ = updates$