# Integration with an external messenger

*You can set up integration with an external messenger using webhooks. A webhook is sending requests based on events.*

### Integration setup

1. Create a channel of the «Page messenger» type.

In the control panel, go to the «[*Channels*](https://selarti.com/panel?menu=channels)» section and click the «*Add channel*» button located in the upper right corner of the screen.

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

Next, in the «Add channel» window, select the channel type «*Page messenger*».

<figure><img src="/files/7MFJHjNwcToMA1Wxgf05" alt="" width="458"><figcaption></figcaption></figure>

Specify any required parameters below and click «*Add channel*».

<figure><img src="/files/TPiGXeKd1v4x42CuzZLq" alt="" width="458"><figcaption></figcaption></figure>

More about creating channels in the article «[Channels](/manual-en/main-sections-of-the-service/channels.md)».

2. Create AI for incoming messages.

To create AI, go to the «[*AI*](https://selarti.com/panel?menu=ai)» section and click the «*Create AI*».

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

More in the article «[AI](/manual-en/main-sections-of-the-service/ai.md)»[.](/manual-en/main-sections-of-the-service/ai.md)

3. Create an integration of the «All messages» type to receive webhooks about new messages.

To create an integration of the «All messages» type, go to the «[*Integration*](https://selarti.com/panel?menu=integration)» section and click the «*Create integration*».

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

In the «Add integration» window, select the integration type «*Another*».

<figure><img src="/files/mlKaUX3nmlETrNzmsIFs" alt="" width="461"><figcaption></figcaption></figure>

In the «Name» field, enter a name. In the «webhook url» field, enter the URL to receive webhooks. Then in the dropdown list «*webhook type*» select «*All messages*». Click «*Create integration*».

<figure><img src="/files/cijwhmw8qeerhO0znOgG" alt="" width="461"><figcaption></figcaption></figure>

More in the article «[Integration](/manual-en/main-sections-of-the-service/integration.md)».

4. Create a task of the «Web» type.

To create a task of the «Web» type, go to the «[*Tasks*](https://selarti.com/panel?menu=tasks)» section and click the «*Create task*».

<figure><img src="/files/4BmQXVPlVMlW3nICvgDY" alt=""><figcaption></figcaption></figure>

In the «Create task» window, in the «Type» dropdown, select «*Web*».

<figure><img src="/files/O7FdaIKslXPIyZCI02uC" alt="" width="461"><figcaption></figcaption></figure>

Next, select the service operation format, the previously created channel, AI, integration, and click the «*Create task*».

<figure><img src="/files/CJvLXaigkE28lpVr09Bq" alt="" width="467"><figcaption></figcaption></figure>

After creation, copy the task id, you will need it for API requests.

More in the article «[Tasks](/manual-en/main-sections-of-the-service/tasks.md)»[.](/manual-en/main-sections-of-the-service/tasks.md)

5. Integrate the method for sending a message from the user to AI:

## send message external

> 🇬🇧 Send external message\
> \
> 🇷🇺 Отправить внешнее сообщение\
> \
> 🇺🇿 Tashqi xabar yuborish

```json
{"openapi":"3.0.3","info":{"title":"Selarti public api","version":"1.0.0"},"tags":[{"name":"Send message","description":"**Base URL:** https://selarti.com"}],"servers":[{"url":"https://selarti.com","description":"Main API server (for /api/1.1/wf/* endpoints)"},{"url":"https://api.selarti.com","description":"Advanced API server (for /v1/* endpoints)"}],"security":[{"bearerAuth":[]}],"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer"}}},"paths":{"/api/1.1/wf/send_message_external":{"post":{"tags":["Send message"],"summary":"send message external","description":"🇬🇧 Send external message\n\n🇷🇺 Отправить внешнее сообщение\n\n🇺🇿 Tashqi xabar yuborish","operationId":"sendMessageExternal","requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"task_id":{"type":"string"},"chat_id":{"type":"string","description":"unique chat_id in your system"},"message":{"type":"string"}},"required":["task_id","chat_id","message"]}}}},"responses":{"200":{"description":"example","headers":{"CF-Cache-Status":{"schema":{"type":"string"}},"CF-RAY":{"schema":{"type":"string"}},"Connection":{"schema":{"type":"string"}},"Content-Encoding":{"schema":{"type":"string"}},"Date":{"schema":{"type":"string"}},"Server":{"schema":{"type":"string"}},"Transfer-Encoding":{"schema":{"type":"string"}},"access-control-allow-origin":{"schema":{"type":"string"}},"alt-svc":{"schema":{"type":"string"}},"vary":{"schema":{"type":"string"}}},"content":{"application/json":{"schema":{"type":"object","properties":{"response":{"type":"object","properties":{"thread":{"type":"object","properties":{"Created By":{"type":"string"},"Created Date":{"type":"number"},"Modified Date":{"type":"number"},"_id":{"type":"string"},"ai_thread_id":{"type":"string"},"chat_id":{"type":"string"},"close":{"type":"boolean"},"company":{"type":"string"},"contact":{"type":"string"},"count_message":{"type":"number"},"get_contact":{"type":"boolean"},"interest":{"type":"boolean"},"is_bot":{"type":"boolean"},"operator":{"type":"boolean"},"success":{"type":"boolean"},"task":{"type":"string"},"title":{"type":"string"},"user_replied":{"type":"boolean"},"wh_get_contact":{"type":"boolean"},"wh_interest":{"type":"boolean"},"wh_success":{"type":"boolean"}}}}},"status":{"type":"string"}}}}}}}}}}}
```

Pass the unique user identifier, for example, Telegram user\_id, in chat\_id. The dialog context will be combined by this id, and you will be able to identify webhooks.

6. Receive a webhook after the AI generates a message and send the message to the user in the dialog.

### List of parameters and description

| Parameter          | Parameter description                                                                                                                                                                                        |
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| channel\_id        | i**d of the channel**. Used to identify the specific channel through which communication is carried out. May be useful for routing and processing messages on your side.                                     |
| close              | **Dialog closed/not closed**. Used to indicate the closing of a dialog or completion of communication. It signals the end of the communication session with the user or the closure of a specific task.      |
| company\_id        | **company id**. Used to identify the organization to which the incoming message or command belongs. Allows accurate processing of data in the context of a specific company or department within the system. |
| contacts           | **Contact**. Used to transmit contact information, such as phone, username, etc. Allows automatic updating and synchronization of contact data between systems.                                              |
| external\_chat\_id | **dialog id**. Used to identify a specific chat or dialog in an external system or messenger. Allows linking messages and interactions with the required external dialog.                                    |
| get\_contact       | **Contact received/not received**. Informs that the user sent a phone, email, etc. in the dialog.                                                                                                            |
| interest           | **Interest shown yes/no**. Used to indicate the client's interest or activation of interest in a specific product or service.                                                                                |
| is\_bot            | <p><strong>Dialog is with a bot yes/no</strong>.<br>If yes, our system has determined that this dialog is with a bot.</p>                                                                                    |
| message\_id        | **message id**. Used for the unique identification of a specific message. Allows you to track, process, and refer to specific messages in the system.                                                        |
| message\_text      | **Message text**. Used to transmit the message text. It allows you to receive and process the content of the message sent by the user or system in the required format.                                      |
| message\_type      | Message type bot/operator/user.                                                                                                                                                                              |
| operator           | **Dialog transferred to operator yes/no.**                                                                                                                                                                   |
| panel\_url         | Link to the dialog in the personal account with the ability to reply to the user.                                                                                                                            |
| share\_url         | Link to the dialog for viewing only, without the ability to reply.                                                                                                                                           |
| success            | Dialog is **successful yes/no**.                                                                                                                                                                             |
| task\_id           | **task id**. Used for the unique identification of a task in the system.                                                                                                                                     |
| thread\_id         | **thread id**. Used to identify the dialog with the user.                                                                                                                                                    |
| title              | **Title**. Full name of the user.                                                                                                                                                                            |
| wh\_type           | **Webhook type**. Indicates the type of webhook, events, or actions. It helps to distinguish which event occurred or what information is being transmitted via the webhook for appropriate processing.       |

#### Webhook example:

<pre class="language-bison"><code class="lang-bison"><strong>{
</strong>  "channel_id": "5q",
  "close": "no",
  "company_id": "1708251850060x460235863640434700",
  "contacts": "123456789",
  "external_chat_id": "123456789", // Your dialog id, you can identify by it
  "get_contact": "no",
  "interest": "no",
  "is_bot": "no",
  "manager_id": "4q",
  "message_id": "1731336491876x582725124419040400",
  "message_text": "It looks like you are testing API functionality by sending a test message along with metadata like a timestamp and timezone. If you have any questions or need assistance with this, feel free to ask!",
  "message_type": "bot", // Send only bot and operator types to the dialog with the user. You can ignore a webhook with the user type by responding with status 200 
  "operator": "no",
  "panel_url": "https://selarti.com/panel?menu=chats&#x26;thread=1731336491572x316716105037601100",
  "share_url": "https://selarti.com/share?thread=1731336491572x316716105037601100",
  "success": "no",
  "task_id": "1721129985149x478019552540622850",
  "thread_id": "1731336491572x316716105037601100",
  "title": "API chat 123456789",
  "wh_type": "all_messages" // Set up processing only for this type of webhook, as webhooks of other types may be sent to your url 
}
</code></pre>

{% hint style="info" %}
A new parameter panel\_url has appeared. It contains a link to the dialog in your personal account. Unlike share\_url, where you can only view the dialog, with panel\_url you can reply to the user directly. Note that access requires authorization and company access rights.
{% endhint %}

7. Try replying to the user through your personal account.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://manual.selarti.com/manual-en/external-integrations/integration-with-an-external-messenger.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
