# @xalbex/telegram-bot

> Telegram Bot API for Node.js

Latest version **0.0.4** (published 2018-10-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install @xalbex/telegram-bot
pnpm add @xalbex/telegram-bot
yarn add @xalbex/telegram-bot
bun add @xalbex/telegram-bot
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2018-10-03 |
| First published | 2018-09-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 469.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Alberto Boldrini |
| Maintainers | xalbex |
| Keywords | Telegram, Bot, API |

## Links

- npm: https://www.npmjs.com/package/@xalbex/telegram-bot
- Repository: https://github.com/AlbertoBoldrini/telegram-bot-ts
- Homepage: https://github.com/AlbertoBoldrini/telegram-bot-ts#readme
- Issues: https://github.com/AlbertoBoldrini/telegram-bot-ts/issues
- npm.io page: https://npm.io/package/@xalbex/telegram-bot

## Recent versions

- 0.0.4 (latest) — 2018-10-03
- 0.0.3 — 2018-09-28
- 0.0.2 — 2018-09-28
- 0.0.1 — 2018-09-28

## README

# Telegram Bot API for Node.js

This is a Node.js module to communicate with official Telegram Bot API. To use this module the bot token is **required** and can be obtained by talking to [@botfather](https://telegram.me/BotFather).

Why use this module insead compared to others?
 - It has no dependencies. It reduce the size of your project.

 - It is written in Typescript and contains the definitions of all [official methods and structures](https://core.telegram.org/bots/api) useful for type checking. This means that the editor can suggest you errors, name and the official documentation for each member.
 
 - It can be used without or with a little abstraction. This allows you to finely control your bot without being limited by this module.

 - For all the requests it return a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), this simplify the asynchronous procedures.

# How to install
Go in your project folder and run the following command:
```bash
$ npm install --save @xalbex/telegram-bot
```


# How to use
This module exports different object to do the same things:
- [Raw](#Raw) (only official methods)
- [Emitter](#Emitter) (official methods + emitting an event for each new update)



## Raw
It provide all the official methods without any abstraction. All methods accept the same parameters specified in the [Telegram Bot API documentation](https://core.telegram.org/bots/api) and return a Promise with the result specified in the official documentation.
 ```ts
import * as TelegramBot from 'telegram-bot-js'

// Replace the value below with the Telegram token you receive from @BotFather
const token = '<BOT-TOKEN>';

// Create an object that manages the Telegram bot and receives the updates.
const bot = new TelegramBot.Raw (token);

// Send the message to a specific chat
let promise = bot.sendMessage ({ chat_id: '<A chat id>', text: 'Hello world!' });
 ```

## Emitter
It simplifies the management of updates. It is a EventEmitter and is possible to add listners. The events emitted have the same names of the update types specified in the [Update](https://core.telegram.org/bots/api#update) object in the documentation: *message*, *edited_message*, *channel_post*, ...
 
 
It contains a member *api* that is the raw client discussed above.

 
 ```ts
import * as TelegramBot from 'telegram-bot-js'

// Replace the value below with the Telegram token you receive from @BotFather
const token = '<BOT-TOKEN>';

// Create an object that manages the Telegram bot and receives the updates.
const bot = new TelegramBot.Emitter (token);

// Listen for message events. The list of possible events is specified 
// here (https://core.telegram.org/bots/api#update)
bot.on ('message', async msg => 
{
    // Send a message to the chat acknowledging receipt of their message
    let result = await bot.api.sendMessage ({ chat_id: msg.chat.id, text: 'Hi!' });

    // Write the server response to the terminal
    console.log (result);
});

---
_Source: https://npm.io/package/@xalbex/telegram-bot · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
