# telegram-free

> Sends message by Telegram API and SMS by the free-mobile API

Latest version **2.0.5** (published 2020-04-08) · ISC license · 0 weekly downloads

## Install

```sh
npm install telegram-free
pnpm add telegram-free
yarn add telegram-free
bun add telegram-free
```

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.5 |
| Published | 2020-04-08 |
| First published | 2020-03-18 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 16.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| Author | Baudev |
| Maintainers | baudev |
| Keywords | Telegram, Free, API |

## Links

- npm: https://www.npmjs.com/package/telegram-free
- npm.io page: https://npm.io/package/telegram-free

## Dependencies (4)

- [express](https://npm.io/package/express.md) ^4.17.1
- [freemobile-sms](https://npm.io/package/freemobile-sms.md) ^1.2.1
- [node-telegram-bot-api](https://npm.io/package/node-telegram-bot-api.md) ^0.40.0
- [@types/node-telegram-bot-api](https://npm.io/package/@types/node-telegram-bot-api.md) ^0.40.2

## Recent versions

- 2.0.5 (latest) — 2020-04-08
- 2.0.4 — 2020-03-22
- 2.0.3 — 2020-03-22
- 2.0.2 — 2020-03-21
- 2.0.1 — 2020-03-21
- 2.0.0 — 2020-03-20
- 1.0.3 — 2020-03-18

## README

# Telegram - Free Mobile 

This library has been developed for specific needs.
It combines communication with Telegram and the free mobile API.
## Configuration

+ Install the library
```
npm install --save telegram-free
```

+ Define the configuration variables

1. Using a json file (example in [`config.json`](config.json))

```typescript
let communicationApi = new TelegramFreeMobile("/home/user/config.json");
```

2. Using an object

```typescript
let config = {
    free_mobile: [
        {
            user: 123,
            password: "xxxxx"
        }
    ],
    telegram: {
        group_id: 123456,
        bot_token: "xxxxxxxxxx"
    }
};

let communicationApi = new TelegramFreeMobile(config);
```

## Usage

### Free Mobile

**Send a message**

```typescript
let free = communicationApi.freeMobile;
free.sendMessage("Hello World!")
    .then(()=> {
        console.log("Sent to all specified users!");
    })
    .catch((err: Error | null) => {
        console.log("Error...", err);
    });
```

### Telegram

**Send a message**

```typescript
let telegram = communicationApi.telegram;
telegram.sendMessage("Hello World!")
.then((message) => {
    console.log("Message sent!");
});
```

**Send a message with a picture**

```typescript
let telegram = communicationApi.telegram;
telegram.sendMessageWithPicture("Hello World!", "/home/user/image.png")
.then((message) => {
    console.log("Photo sent!");
});
```

**Launch Telegram Bot and set OnMessageListener**

```typescript
let telegram = communicationApi.telegram;
telegram.launchTelegramServer()
    .setOnMessageListener((message) => {
        console.log("Message received:", message);
    });
```

## API

### Class TelegramFreeMobile

**TelegramFreeMobile([config])**

+ config - (_`ConfigurationInterface` or string_) The configuration variables. If `config` is a string, then it should be the absolute path of the json configuration file (example in [`config.json`](config.json)). If `config` is an object, it should implements [`ConfigurationInterface`](src/Interfaces/ConfigurationInterface.ts). **Default:** `config.json` of this current directory. 

**telegram(): Telegram**

Returns an instance of `Telegram`.

**freeMobile(): FreeMobile**

Returns an instance of `FreeMobile`.

**configuration(): Configuration**

Returns an instance of `Configuration`.

### Class Telegram

**sendMessage(content): Promise<TelegramBot.Message>**

+ content - (_string_) Message to be sent.

**sendMessageWithPicture(content, picture): Promise<TelegramBot.Message>**

+ content - (_string_) Message to be sent.
+ picture - (_string_) Absolute path or public URL of the picture to be sent.

**sendMessageWithVideo(content, video): Promise<TelegramBotDefinition.Message>**

+ content - (_string_) Message to be sent.
+ video - (_string_) Absolute path or public URL of the video to be sent.

**launchTelegramServer(): Telegram**

Launches the telegram bot server. Required to use listeners.

**setOnMessageListener(onMessageReceived): void**

+ onMessageReceived - (_(message: TelegramBot.Message) => void_) Callback called each time a message is received.

**bot: TelegramBot**

Returns an instance of `TelegramBot` from [node-telegram-bot-api](https://github.com/yagop/node-telegram-bot-api) library.

### Class FreeMobile

**sendMessage(content): Promise<void[]>**

+ content - (_string_) Message to be sent.

### Interface ConfigurationInterface

+ telegram - (_TelegramConfigurationInterface_) Telegram group configuration. The bot will listen for messages into the group specified.
+ free_mobile - (_Array\<FreeMobileConfigurationInterface>_) Free mobile configuration. The `FreeMobile` class will send messages to all specified users.

### Interface TelegramConfigurationInterface

+ bot_token - (_string_) Token of the telegram bot. 
+ group_id - (_number_) Group ID. The bot will listen for messages into the group specified.

### Interface FreeMobileConfigurationInterface

+ user - (_number_) Account number of the free mobile user.
+ password - (_string_) Token of the free mobile user.

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