telekit • teleapi

Now support the Telegram Bot API 3.6

What is it?

This is useful library to simplify your work with the Telegram Bot API

Before you start, please, read an introduction for developers.

Just a moment, I'll read it.

Install

npm

$ npm install teleapi --save

yarn

$ yarn add teleapi

How it use?

Elementary! Look at the next example that show you how to send request to getMe method:

const teleapi = require ( ' teleapi ' ) ; const api = teleapi ( ' telegram_bot_token ' ) ; api . getMe ( ) . then ( ( response ) => { console . log ( ' id: ' , response . id ) ; console . log ( ' username: ' , response . username ) ; } ) . catch ( ( error ) => { console . log ( error ) ; } ) ;

If you want to see available methods and types:

Please, have a look at here first.

API

token:String - Token of the Bot that you can get from the BotFather

- Token of the Bot that you can get from the BotFather api:Object - (optional) An Object with Custom API(see api.json)

- An Object with Custom API(see api.json) Returns: api - An instance of the teleapi.

Creates an new instance of the teleapi with your token of the bot.

A contain of the current API version.

A contain an Array of String with all available methods.

id:String - File ID

- File ID Returns: Stream - A stream with file data

Get file from the Telegram.

name:String - Name of the method that available in the Telegram Bot API

- Name of the method that available in the Telegram Bot API params:Object - (optional) An Object with body params for the request

- An Object with body params for the request Returns: Promise with response in then

This method send request to the Telegram Bot API;

It's private method but you can use it.

params:Object - An Object with body params for the request

- An Object with body params for the request Returns: Promise with response in then

The <method> is one of the available methods from Telegram Bot API.

See all available methods here.

Examples

Send text message to chat

const teleapi = require ( ' teleapi ' ) ; const api = teleapi ( ' telegram_bot_token ' ) ; api . sendMessage ( { chat_id : 0000 , text : ' Hello! ' , } ) ;

Save file from the Telegram

const teleapi = require ( ' teleapi ' ) ; const api = teleapi ( ' telegram_bot_token ' ) ; api . getFile ( ' file_id ' ) . pipe ( fs . createWriteStream ( ' image.png ' ) ) ;

Send sticker(file_id)

const teleapi = require ( ' teleapi ' ) ; const api = teleapi ( ' telegram_bot_token ' ) ; api . sendSticker ( { chat_id : 0000 , sticker : ' file_id ' , } ) ;

Send document(stream.Readable)

const teleapi = require ( ' teleapi ' ) ; const fs = require ( ' fs ' ) ; const api = teleapi ( ' telegram_bot_token ' ) ; api . sendDocument ( { chat_id : 0000 , document : fs . readFile ( ' book_from_tpb.pdf ' ) , } ) ;

Send photo(URL)

const teleapi = require ( ' teleapi ' ) ; const api = teleapi ( ' telegram_bot_token ' ) ; api . sendPhoto ( { chat_id : 0000 , photo : ' https://upload.wikimedia.org/wikipedia/commons/d/d9/Test.png ' , } ) ;

Send voice(Buffer)

const teleapi = require ( ' teleapi ' ) ; const api = teleapi ( ' telegram_bot_token ' ) ; api . sendVoice ( { chat_id : 0000 , voice : new Buffer ( [ 1 , 2 , 3 ] ) , } ) ;

Send document(strict)

const teleapi = require ( ' teleapi ' ) ; const fs = require ( ' fs ' ) ; const api = teleapi ( ' telegram_bot_token ' ) ; api . sendDocument ( { chat_id : 000000 , document : { filename : ' photo.png ' , value : fs . readFile ( ' family_photo.dat ' ) , mime : ' image/png ' , } , } ) ;

A more is coming soon.

LICENSE

MIT © Denis Maslennikov