telekit • teleapi
[](https://travis-ci.org/telekits/teleapi) [](https://www.npmjs.com/package/teleapi) [](https://www.npmjs.com/package/teleapi) [](https://github.com/sindresorhus/xo) [](./LICENSE) > 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.](https://core.telegram.org/bots "Bots: an introduction for developers") ## Install npm ```console $ npm install teleapi --save ``` yarn ```console $ yarn add teleapi ``` ## How it use? Elementary! Look at the next example that show you how to send request to `getMe` method: ```javascript /** First be we've required the teleapi */ const teleapi = require('teleapi'); /** * Next we need a get an instance of the teleapi. * Also, we should set the bot token. */ const api = teleapi('telegram_bot_token'); /** * And now we can send requests to the Telegram Bot API; * This method returns info about the bot to us. * * (`getMe` method is available in the Telegram Bot API). */ api.getMe().then((response) => { /** Bot ID */ console.log('id:', response.id); /** and username of the our bot */ console.log('username:', response.username); /** * And also first name and last name and lang code. * See about it below. */ }).catch((error) => { /** Something is wrong! */ console.log(error); }); ``` > If you want to see available methods and types: > [Please, have a look at here first.](https://core.telegram.org/bots/api#available-types "Telegram Bot API") ## API #### `teleapi(token, [api]);` * `token:String` - Token of the Bot that you can get from the BotFather * `api:Object` - **(optional)** An Object with Custom API(see [api.json](./api.json "Default API")) * Returns: `api` - An instance of the teleapi. Creates an new instance of the teleapi with your token of the bot. #### `teleapi.version:String` A contain of the current API version. #### `teleapi.methods:Array` A contain an Array of String with all available methods. #### `api.getFile(id);` * `id:String` - File ID * Returns: `Stream` - A stream with file data Get file from the Telegram. #### `api.method(name, [params]);` * `name:String` - Name of the method that available in the Telegram Bot API * `params:Object` - **(optional)** 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. #### `api.