> For the complete documentation index, see [llms.txt](https://docs.suvvy.ai/en/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.suvvy.ai/en/main-settings/opovesheniya-ot-savvi/customizable-notifications-in-telegram.md).

# Customizable notifications in Telegram

If Suvvy's standard notifications don't suit you, you can set up notifications in your TG bot using the [Webhooks](/en/workflows/veb-khuki.md) mechanism.

To set up custom alerts for your Telegram bot, follow a few simple steps:

1. Create a bot in **BotFather**.

You can find detailed instructions on how to create a bot in BotFather in the [Telegram manual section](/en/channels/messendzhery/telegram.md).

2. Get the chat id (**chat\_id**) to which notification messages will be sent.

a. If you want to receive notifications in the bot, you must obtain your personal user\_id, which will also be used as your chat\_id in the future. You can learn how to obtain your personal user\_id by following this link.

b. If you want to receive notifications in a group, you need to get the **chat\_id** of the group to which notifications will be sent.

<details>

<summary>Instructions on how to get a group's chat_id.</summary>

### Step 1: Add your bot to the group

1. Open Telegram.
2. Go to the desired group.
3. Add your bot as a regular member.
4. Assign it as an admin (if you want it to be able to post messages to the group).

### Step 2: Write any message to the group

Anything—whether it's a "test" from yourself or something else entirely. This is necessary to get the group active.

### Step 3: Get updates via the Telegram Bot API

1. In your browser, enter the following URL:

```
https://api.telegram.org/bot<ТВОЙ_ТОКЕН>/getUpdates
```

> Where \<YOUR\_TOKEN> is the token of your TG bot.

Example:

```
https://api.telegram.org/bot123456789:ABCDEF1234567890abcdef12345678/getUpdates
```

2. The response will be JSON, which will contain something like:

```
{
"update_id": 123456789,
"message": {
"chat": {
"id": -1001234567890,
"title": "Название группы",
"type": "supergroup"
},
...
}
}
```

### Step 4: Use the `chat_id` from the response

Here is this `id`:

```
-1001234567890
```

— and there's the group's `chat_id`. **It's always negative**.

</details>

3. In Savvy, go to **Workflows** and click **Add**:

<figure><img src="/files/JdiGpO3YC1R0hVz4VDzD" alt=""><figcaption></figcaption></figure>

4. Select **Webhook** from the list:

<figure><img src="/files/djW1rW3YDwG1kOz6FeQs" alt=""><figcaption></figcaption></figure>

5. Filling in the function fields

<figure><img src="/files/W0FTt3Urc4JfZDBzFz5g" alt=""><figcaption></figcaption></figure>

6. Add **arguments** and **constants** that will be passed to the **webhook**:

<figure><img src="/files/AXjnKz2jhWdDTni9dRjT" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/j4ypa9WWyIU5QfOhWacw" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
**Arguments** are variables that the bot will generate during the conversation. They depend on the user's responses.\
**Constants** are parameters that will be passed to the webhook invariably. In our case, the bot name will always be passed to the webhook, such as **"Bot - Elsa**."
{% endhint %}

7. Configure the **Webhook** step:

<figure><img src="/files/Ss9f10nw0JuZFZwCJVvs" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
Paste the URL into the field: `https://api.telegram.org/bot<YOUR_TOKEN>/sendMessage` , where \<YOUR\_TOKEN> is **your Telegram bot's** token obtained when creating the bot through BotFather. \
Request method: **POST** \
Body type: **JSON**
{% endhint %}

8. We write the Request Body in JSON format:

Example:

<figure><img src="/files/nxcCWsY7KXLDbw3TFAPd" alt=""><figcaption></figcaption></figure>

{% hint style="danger" %}
Please note that arguments to the Request Body are added using the ➕ sign on the right side of the input field:
{% endhint %}

<figure><img src="/files/DPPVzihFsTEb7Txfsx1r" alt=""><figcaption></figcaption></figure>

{% tabs %}
{% tab title="Example of a JSON request" %}

```
{
"chat_id": "446298654",
"text": "﻿{bot_name}﻿, Имя клиента: ﻿{client_name﻿}, Номер телефона: ﻿{phone_number}﻿, Как прошёл диалог: ﻿{summary}﻿"
}
```

❗️ Arguments in curly brackets must be replaced with arguments added through ➕.
{% endtab %}
{% endtabs %}

9. Click **Save**:

<figure><img src="/files/THmshCsPCBCpPdCgKUOH" alt=""><figcaption></figcaption></figure>

10. Now that we've configured the Action to send a notification to our TG, we need to add instructions to the central prompt for the bot, telling it how to generate arguments and when to pass them to the webhook sending function.

{% tabs %}
{% tab title="Forming arguments in a dialogue" %}

```
#TASK
Say hello and ask the client:
1. Name and convert the response into the {client_name} argument.
2. Phone number and convert the response into the {phone_number} argument.
3. Company type of activity
After the client answers the last question, write a brief summary of the dialogue and convert it into the {summary} argument.

Once you've generated all the arguments, call the tg_bot function and pass it the {client_name}, {phone_number}, and {summary} arguments.
```

{% endtab %}

{% tab title="Working with placeholder arguments" %}

```
#TASK
Say hello and ask the client:
1. Name
2. Phone number
3. Company type
The client will answer all questions. Call the tg_bot function and pass the arguments {contact_id}, {lead_id}, {manager_id}, {origin}, and {source}.
```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}
Where can we get the parameters {contact\_id}, {lead\_id}, {manager\_id}, {origin} and {source} from the example above if we did not generate them during the dialogue?
{% endhint %}

> In addition to arguments generated during the dialogue from the client's responses, the bot can pass parameters located in placeholders to the function.

Placeholder parameters can be found in the dialog export at the very top of the page. It looks like this:

<figure><img src="/files/dtHq1JT5aCmluSq02Xst" alt=""><figcaption></figcaption></figure>

{% hint style="danger" %}
Depending on the connected channel, the parameters passed to placeholders may differ.\
The easiest way to find out what parameters we can pass to our function from placeholders is to export the dialog and check which parameters are passed to the Bot.
{% endhint %}

Structuring Messages

If your notification text is quite long, it's best to set it up so that each line is on a new line to make the information easier to read. You can set up text wrapping for this purpose.

Settings

In the action, you need to add a **Constant** containing the line feed operator **"\n"**.

<figure><img src="/files/JJh2grOx66q0UsV4TWnc" alt=""><figcaption></figcaption></figure>

Next, in the body of the request, before the first word of the phrase, which should be on a new line, you need to add a constant with a hyphenation operator.

<figure><img src="/files/nWmYlV2QKiuGlm8RbnpK" alt=""><figcaption></figcaption></figure>

After these actions, phrases that were preceded by the hyphenation operator will start on a new line.
