# bot-tg

> A bot for Telegram Bot's API

Latest version **1.0.21** (published 2019-05-24) · ISC license · 0 weekly downloads

## Install

```sh
npm install bot-tg
pnpm add bot-tg
yarn add bot-tg
bun add bot-tg
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.21 |
| Published | 2019-05-24 |
| First published | 2019-04-26 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 9.2 KB |
| Known vulnerabilities | 0 (+24 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | ikerya |
| Maintainers | i.kerya |
| Keywords | telegram, telegram bot, tg bot, tg |

## Links

- npm: https://www.npmjs.com/package/bot-tg
- Repository: https://github.com/ikerya/bot-tg
- Homepage: https://github.com/ikerya/bot-tg#readme
- Issues: https://github.com/ikerya/bot-tg/issues
- npm.io page: https://npm.io/package/bot-tg

## Dependencies (2)

- [axios](https://npm.io/package/axios.md) ^0.18.0
- [form-data](https://npm.io/package/form-data.md) ^2.3.3

## Recent versions

- 1.0.21 (latest) — 2019-05-24
- 1.0.20 — 2019-05-24
- 1.0.19 — 2019-05-24
- 1.0.18 — 2019-05-22
- 1.0.17 — 2019-05-15
- 1.0.16 — 2019-05-12
- 1.0.15 — 2019-05-11
- 1.0.14 — 2019-05-11
- 1.0.13 — 2019-05-11
- 1.0.12 — 2019-05-11
- 1.0.11 — 2019-05-11
- 1.0.10 — 2019-05-07
- 1.0.9 — 2019-05-04
- 1.0.8 — 2019-05-04
- 1.0.7 — 2019-05-04
- … 7 more at https://npm.io/package/bot-tg/versions

## README

# A package for Telegram's bot API

## Table of contents

* [Examples](#examples)
* [Guides](#guides)
* [New](#new)

# Examples

Here is an example to use this package:

```javascript
const TelegramBot = require("bot-tg");
const bot = new TelegramBot({
	token: '<YOUR_BOT_TOKEN_HERE>',
	commands: [{
		id: 'hello',
		description: 'click here!',
		call: function(userId) {
			this.sendMessage(userId, 'World!');
		}
	}]
});
```

To get any kind of information from user you should do like that:

```javascript
const TelegramBot = require("bot-tg");
const bot = new TelegramBot({
    token: '<YOUR_BOT_TOKEN_HERE>',
    commands: [{
        id: 'set',
        description: 'set something',
        title: 'Send me something:',        
        done: function(userId, result) {
            this.sendMessage(userId, `Result is: ${result}`);
        }
    }]
});
```

To make a command hidden when calling the **help** (or **start**) command:

```javascript
const TelegramBot = require("bot-tg");
const bot = new TelegramBot({
    token: '<YOUR_BOT_TOKEN_HERE>',
    commands: [{
        id: 'set',
        description: 'set something',
        title: 'Send me something:',        
        done: function(userId, result) {
            this.sendMessage(userId, `Result is: ${result}`);
        }
    }, {
        id: 'action',
        description: 'admin action',
        call: function(userId) {
            this.sendMessage(userId, 'Hello, admin!');
        }
    }]
});
```

# Guides

To make some command hidden from list when calling the **help** (or **start**) command use **hidden: true** property:

```javascript
const TelegramBot = require("bot-tg");
const bot = new TelegramBot({
    token: '<YOUR_BOT_TOKEN_HERE>',
    commands: [{
        id: 'set',
        description: 'set something',
        title: 'Send me something:',        
        done: function(userId, result) {
            this.sendMessage(userId, `Result is: ${result}`);
        }
    }, {
        id: 'action',
        description: 'admin action',
        hidden: true,
        call: function(userId) {
            this.sendMessage(userId, 'Hello, admin!');
        }
    }]
});
```

To enable logging use:

```javascript
const bot = new TelegramBot({
    token: '<YOUR_BOT_TOKEN_HERE>',
    logging: true
    ...
});
```

# New

* When there are no matches with commands list identified at bot's initialization, bot's instance emits a message:

```javascript
const TelegramBot = require("bot-tg");
const bot = new TelegramBot({
    token: '<YOUR_BOT_TOKEN_HERE>',
    commands: [{
        id: 'set',
        description: 'set something',
        title: 'Send me something:',        
        done: function(userId, result) {
            this.sendMessage(userId, `Result is: ${result}`);
        }
    }]
});

bot.on('message', update => {
    console.log(update);
});
```

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