# Telegram bot CLI

# Introduction

<p class="callout info">**Version** 080621.</p>

**Telegram®** bots CLI connector for use in [Pandora FMS alerts](https://pandorafms.com/manual/en/documentation/pandorafms/management_and_operation/01_alerts "PFMS: Alerts system").

# Compatibility matrix

- Python 3 for source code.
- Linux® x64 for compiled code.
- **Incompatible with MS Windows® systems.**

# Requirements

The requirements are as follows:

- A Telegram® account to create the bot.
- Add the bot to the notification group.
- Get the group **id**.
- Python version 3 installed on the PFMS server with the module: `request` (only for source code).

# Configuration

#### <span dir="ltr" role="presentation">Creation of the BOT on Telegram</span>

<span dir="ltr" role="presentation">From a Telegram® account, you must type</span> `<span dir="ltr" role="presentation">/start</span>` <span dir="ltr" role="presentation">to the user</span> [**<span dir="ltr" role="presentation">BotFather</span>**](https://telegram.me/botfather "BotFather is the one bot to rule them all. Use it to create new bot accounts and manage your existing bots.") <span dir="ltr" role="presentation">to create a *bot*.</span>

<span dir="ltr" role="presentation">It will return a series of parameters and instructions</span> <span dir="ltr" role="presentation">available for the </span><span dir="ltr" role="presentation">creation and manipulation of *bots*:</span>

[![image-1626693442412.png](https://pandorafms.com/guides/public/uploads/images/gallery/2021-07/scaled-1680-/image-1626693442412.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2021-07/image-1626693442412.png)

Use the `/newbot` option to create a new *bot*.

<span dir="ltr" role="presentation"><span dir="ltr" role="presentation">It will ask for the name, in this case `Pandora_FMS_Test_bot` , you can use any name you prefer</span><span dir="ltr" role="presentation">.</span></span>

Now you will be asked for a user ID for the bot, which must end in `_bot`. In this case, use the same one as before: `Pandora_FMS_Test_bot`.

It will now return information about our bot and some instructions for its administration. You must copy and save the API token, which is what we will use to authenticate ourselves as that bot.

[![image-1629719317095.png](https://pandorafms.com/guides/public/uploads/images/gallery/2021-08/scaled-1680-/image-1629719317095.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2021-08/image-1629719317095.png)<span dir="ltr" role="presentation"> </span>

#### <span dir="ltr" role="presentation">Create a group and add the bot</span>

  
<span dir="ltr" role="presentation">To create a group from Telegram, you must </span><span dir="ltr" role="presentation">click on create group and </span><span dir="ltr" role="presentation">select the users who will be in that group. **It is important that one of those users** </span><span dir="ltr" role="presentation">**is our bot in order to send messages to that group specifically**.</span>

<p class="callout info"><span dir="ltr" role="presentation"><span dir="ltr" role="presentation">You can also </span><span dir="ltr" role="presentation">simply add the *bot* to an existing group</span><span dir="ltr" role="presentation">.</span></span></p>

#### [![image-1626695074691.png](https://pandorafms.com/guides/public/uploads/images/gallery/2021-07/scaled-1680-/image-1626695074691.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2021-07/image-1626695074691.png)

#### <span dir="ltr" role="presentation">Obtain the group ID to send messages from</span> <span dir="ltr" role="presentation">the CLI</span>

Now we need to obtain the **id** of the group where we added our *bot*. There are different ways to do this. One of the simplest is to add another bot that extracts this information very easily: [**GetIDs Bot**](https://t.me/getidsbot "This bot gives you telegram-internal information about messages").

We add it to the group we want to know the **id** of, and it will give a series of instructions for its use. Just by adding it, it provides the information we need (**id** of the group).

[![image-1629719396585.png](https://pandorafms.com/guides/public/uploads/images/gallery/2021-08/scaled-1680-/image-1629719396585.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2021-08/image-1629719396585.png)

<span dir="ltr" role="presentation">Once we have the group ID, we copy and save it.</span>

<p class="callout info">We can remove this [**GetIDs Bot**](https://t.me/getidsbot "This bot gives you telegram-internal information about messages") from the group because it has already fulfilled its purpose of giving us the ID.</p>

#### Configure Pandora-Telegram CLI

<span dir="ltr" role="presentation">  
</span><span dir="ltr" role="presentation">To use Pandora Telegram CLI (source code), you must </span><span dir="ltr" role="presentation">have Python version 3 and Pip version 3 installed for dependencies. To install the dependencies, in the package to be downloaded, you will see the file `requirements.txt`. Go to its directory and run:</span>

```bash
pip3 install -r requirements.txt
```

<span dir="ltr" role="presentation">This will download and install the necessary dependencies.</span>

<span dir="ltr" role="presentation">Once the dependencies are installed, run the</span> <span dir="ltr" role="presentation">`pandora-telegram-cli.py -h` file with </span><span dir="ltr" role="presentation">the Python interpreter to view its help:</span>

```bash
python3 pandora-telegram-cli.py -h
usage: pandora-telegram-cli.py [-h] -m MESSAGE -t TOKEN -c CHAT_ID
Bot telegram cli
optional arguments:
-h, --help show this help message and exit
-m MESSAGE, --message MESSAGE
Message to be send
-t TOKEN, --token TOKEN
Bot token
-c CHAT_ID, --chat_id CHAT_ID
chat id to send messages
```

<p class="callout success"><span dir="ltr" role="presentation">If we see the help without any errors, then we are ready to use it.</span></p>

# General plugin parameters

```
# [Optional parameter]
python pandora-telegram-cli.py \ 
  -t <bot_token> \ 
  -c <chat_id> \ 
  -m <MESSAGE> \ 
  [ --api_conf <API_CONF> ] \ 
  [ --module_graph <MODULE_GRAPH> ] \ 
  [ --tmp_dir <TMP_DIR> ]
```

[![image-1629719533273.png](https://pandorafms.com/guides/public/uploads/images/gallery/2021-08/scaled-1680-/image-1629719533273.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2021-08/image-1629719533273.png)

If the credentials are correct, it will return in JSON format the information of the message we have just sent, which we will be able to see received in our Telegram group:

[![image-1629719541503.png](https://pandorafms.com/guides/public/uploads/images/gallery/2021-08/scaled-1680-/image-1629719541503.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2021-08/image-1629719541503.png)

# Use in Pandora FMS

<p class="callout info">The Telegram® plugin is fully integrated into Pandora FMS version 800.</p>

<span dir="ltr">The default *script* is located at:</span><span dir="ltr"> </span><span dir="ltr">`/usr/share/pandora_server/util/pandora-telegram-cli.py`. </span><span dir="ltr">However, any location can be used as long as the PFMS Server has access to it.</span>

<span dir="ltr">**You must ensure that all dependencies are installed**,</span><span dir="ltr"> check this, run</span><span dir="ltr">:</span>

```
python3 pandora-telegram-cli.py
```

You will get a response similar to this:

[![image-1629719592284.png](https://pandorafms.com/guides/public/uploads/images/gallery/2021-08/scaled-1680-/image-1629719592284.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2021-08/image-1629719592284.png)

If there is an error, the dependencies must be reinstalled:

```bash
pip3 install -r requirements.txt
```

#### Telegram alert command

To verify the installation of its command, use the **Management → Alerts→Commands** menu and enter the search key in **Filter**:

[![pfms-telegram-integration-140.png](https://pandorafms.com/guides/public/uploads/images/gallery/2026-01/scaled-1680-/pfms-telegram-integration-140.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2026-01/pfms-telegram-integration-140.png)

This command does not allow editing or deletion, so it is considered read-only and is used by the system. Therefore, you must go to the general settings to save the token obtained in the previous topic.

**Managements → Settings → System settings → General setup → Alerts configuration** menu:

[![pfms-telegram-integration-142.png](https://pandorafms.com/guides/public/uploads/images/gallery/2026-01/scaled-1680-/pfms-telegram-integration-142.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2026-01/pfms-telegram-integration-142.png)

<p class="callout warning">The field displays the token in plain text. Take the necessary precautions to prevent third parties from viewing it.</p>

When finished, click the **Update** button to save the Telegram token in the database.

#### Telegram action command

Go to the **Management→Alerts→ Actions** menu and in **Filter** select **Pandora Telegram** in the **Command** field. The alert actions that use the **Pandora Telegram** command will be displayed:

[![pfms-telegram-integration-144.png](https://pandorafms.com/guides/public/uploads/images/gallery/2026-01/scaled-1680-/pfms-telegram-integration-144.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2026-01/pfms-telegram-integration-144.png)

You may:

- Use the default action when installing Pandora FMS.
- Copy the previous action and customize it as needed. It may be the case that several groups of agents use different alert actions configured according to each case.
- Create an action based on the Telegram alert command (read-only).

<p class="callout info">For any of the three cases, the Chat ID must always be configured, obtained as indicated in the [previous topic](https://pandorafms.com/guides/public/books/telegram-bot-cli-8f8/page/configuration).</p>

Whether editing, copying and editing, or creating, the configuration process is similar:

[![pfms-telegram-integration-146.png](https://pandorafms.com/guides/public/uploads/images/gallery/2026-01/scaled-1680-/pfms-telegram-integration-146.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2026-01/pfms-telegram-integration-146.png)

- Indicate and select the name and group as appropriate.
- Ensure that **Pandora Telegram** is selected in **Command** list.
- In **Chat ID**, enter the corresponding identifier. *This field does not accept macros; only enter the identifier.*
- In the **Message** field for **Triggering**, if it is empty, insert `[PANDORA] Alert FIRED on _agent_ / _module_ / _timestamp_ / _data_` . See the other [macros available](https://pandorafms.com/manual/en/documentation/pandorafms/management_and_operation/01_alerts#ks15) to insert more information.
- In the **Message** field for **Recovery**, if it is empty, insert `[PANDORA] Alert RECOVERED on _agent_ / _module_ / _timestamp_ / _data_` . See the other [macros available](https://pandorafms.com/manual/en/documentation/pandorafms/management_and_operation/01_alerts#ks15) to insert more information.
- Press the **Create** button if you are creating an alert action or (**Update** if you are editing) to save the parameters.

Click **Create**. Once you have created this alert action, it can be included in [a policy](https://pandorafms.com/manual/en/documentation/pandorafms/complex_environments_and_optimization/02_policy "PFMS: Policies monitoring"), [a template](https://pandorafms.com/manual/en/documentation/pandorafms/technical_annexes/34_pfms_templates_policies_massives "PFMS: Differences between Templates, Policies, and Mass Operations"), or [Module](https://pandorafms.com/manual/es/documentation/pandorafms/management_and_operation/01_alerts#ks5_2 "PFMS: Gestionar alertas desde el agente").

<p class="callout info">If additional information is required, please visit the [documentation for the *plugin*](https://pandorafms.com/library/telegram-bot-cli/).</p>