# Webhook de descarregamento

O webhook de repasse permite que você integre qualquer plataforma de chat de transferência para humano. Você pode usar o webhook para:

* Receber mensagens de usuários recebidas
* Receber mensagens de bot enviadas
* Agir mediante solicitações de repasse de um usuário

{% hint style="warning" %}
O Webhook de Repasse é para repassar usuários do bot para um agente humano. O [canal Webhook](https://docs.chatlayer.ai/channels/webhook-api) é um canal de integração personalizado, certifique-se de não confundir esses dois!
{% endhint %}

## Configuração

Para configurar seu Webhook de Repasse do Chatlayer, vá para **Configurações > Repasse** e crie uma **Webhook** integração.

![](/files/b82cd2fc90a899722b3c52b4e12ebf70b32a5e6c)

Insira a URL da API do seu serviço web e um Token de Verificação que permita validar solicitações recebidas.

Enviaremos uma solicitação de teste para sua URL de API quando você pressionar Salvar para validar se seu serviço web está ativo e pronto para receber solicitações, descrito no método Health Check.

Parabéns! Você está pronto para começar a usar sua integração personalizada de transferência para humano.

## Referência de Implementação do Serviço Web

Seu serviço web precisará implementar os seguintes métodos de API para que possamos nos comunicar. Todas as solicitações chegarão em formato JSON na URL da API configurada durante a configuração do webhook de repasse no Chatlayer. Toda solicitação POST em JSON tem um corpo com um **evento** parâmetro que permite distinguir entre os diferentes tipos de dados recebidos. Diferentes tipos são explicados abaixo.

Esperamos um código de status HTTP 200 para toda solicitação feita ao serviço web. Os dados de resposta devem estar em formato JSON.

## Verificação de Saúde da API

<mark style="color:azul;">`GET`</mark> `<sua_url_de_api>`

Você deve enviar a resposta conforme descrito na aba Resposta.&#x20;

#### Parâmetros de Consulta

| Nome                  | Tipo   | Descrição                                                                |
| --------------------- | ------ | ------------------------------------------------------------------------ |
| challenge.verifyToken | string | O verifyToken permite validar que a solicitação foi feita pelo Chatlayer |

{% tabs %}
{% tab title="200 " %}

```
{ "status": "ok" }
```

{% endtab %}
{% endtabs %}

## Mensagens

<mark style="color:verde;">`POST`</mark> `<sua_url_de_api>`

#### Parâmetros de Consulta

| Nome                  | Tipo   | Descrição                                                                |
| --------------------- | ------ | ------------------------------------------------------------------------ |
| challenge.verifyToken | string | O verifyToken permite validar que a solicitação foi feita pelo Chatlayer |

#### Corpo da Solicitação

| Nome      | Tipo   | Descrição                                         |
| --------- | ------ | ------------------------------------------------- |
| timestamp | string | O horário em que a mensagem foi gerada            |
| mensagens | array  | Um array de mensagens de usuário e bot            |
| evento    | string | O tipo de solicitação, neste caso **`mensagens`** |
| canal     | string | O tipo de canal                                   |
| sessionId | string | O ID da sessão do usuário                         |
| version   | string | A versão do bot, DRAFT ou LIVE                    |
| botId     | string | O ID do bot                                       |

{% tabs %}
{% tab title="200 Não esperamos um corpo de resposta." %}

```
```

{% endtab %}
{% endtabs %}

Os itens no array messages têm o seguinte formato -

```javascript
{
    "actor": "bot" | "user",
    "message": UserMessage | BotMessage
}
```

**BotMessage** objetos seguem a mesma estrutura que a API do Canal Webhook, documentada [aqui](https://docs.chatlayer.ai/channels/webhook-api#message-objects).

```javascript
// Exemplo de Mensagem de Texto do Bot
{
    "botId": "ko3123ze",
    "version": "DRAFT",
    "sessionId": "emulator-18878e66-03fb-4ee7-b2c4-eb9db1848291",
    "event": "messages",
    "messages": [
        {
            "actor": "bot",
            "message": {
                "text": "Hi Welcome"
            },
            "timestamp": "2021-11-15T07:38:31.387Z"
        }
    ],
    "timestamp": "2021-11-15T07:38:31.387Z"
}

// Exemplo de Mensagem de Bot com resposta rápida
{
    "botId": "ko3123ze",
    "version": "DRAFT",
    "sessionId": "emulator-d3dac415-5263-482c-a30b-d1588c52d918",
    "event": "messages",
    "messages": [
        {
            "actor": "bot",
            "message": {
                "text": "Hi Welcome"
            },
            "timestamp": "2021-11-15T07:47:08.383Z",
        },
        {
            "actor": "bot",
            "message": {
                "text": "Choose what you want to do?",
                "quick_replies": [
                    {
                        "title": "Do API FROM CODE",
                        "payload": "{\"title\":\"Do API FROM CODE\",\"caption\":\"Do API FROM CODE\",\"type\":\"quickreply\",\"parameters\":[],\"nextDialogstateId\":\"19f87132-e23c-4335-877d-6a36f511c2cc\",\"originalTitle\":\"Do API FROM CODE\"}",
                        "content_type": "text"
                    },
                    {
                        "title": "Api Plugin",
                        "payload": "{\"title\":\"Api Plugin\",\"caption\":\"Api Plugin\",\"type\":\"quickreply\",\"parameters\":[],\"nextDialogstateId\":\"e0b327e0-bfa0-42a7-9685-c68491625b6e\",\"originalTitle\":\"Api Plugin\"}",
                        "content_type": "text"
                    },
                    {
                        "title": "SendMessageFromCode",
                        "payload": "{\"title\":\"SendMessageFromCode\",\"caption\":\"SendMessageFromCode\",\"type\":\"quickreply\",\"parameters\":[],\"nextDialogstateId\":\"c125a34e-7fec-4385-8333-6a91e25cdcff\",\"originalTitle\":\"SendMessageFromCode\"}",
                        "content_type": "text"
                    }
                ]
            },
            "timestamp": "2021-11-15T07:47:08.384Z"
        }
    ],
    "timestamp": "2021-11-15T07:47:08.383Z",
}

// mensagem carrossel / modelo Genérico
{
    "botId": "ko3123ze",
    "version": "DRAFT",
    "sessionId": "emulator-39ac2f23-07ce-4878-bd7d-729e6b39efdf",
    "event": "messages",
    "messages": [
        {
            "actor": "bot",
            "message": {
                "attachment": {
                    "type": "template",
                    "payload": {
                        "template_type": "generic",
                        "elements": [
                            {
                                "title": "Item 1",
                                "image_url": "https://st.depositphotos.com/1708346/1858/i/600/depositphotos_18582903-stock-photo-carousel-at-night.jpg",
                                "buttons": [
                                    {
                                        "title": "Docs",
                                        "url": "https://docs.chatlayer.ai",
                                        "type": "web_url"
                                    }
                                ]
                            },
                            {
                                "title": "Item 2",
                                "image_url": "https://st.depositphotos.com/1708346/1858/i/600/depositphotos_18582903-stock-photo-carousel-at-night.jpg",
                                "subtitle": "Item 2 Subtitle",
                                "buttons": [
                                    {
                                        "title": "Docs",
                                        "url": "https://docs.chatlayer.ai",
                                        "type": "web_url"
                                    }
                                ],
                                "default_action": {
                                    "url": "https://docs.chatlayer.ai",
                                    "type": "web_url"
                                }
                            }
                        ]
                    }
                }
            },
            "timestamp": "2021-11-15T08:24:32.871Z"
        }
    ],
    "timestamp": "2021-11-15T08:24:32.871Z"
}
```

**UserMessage** objetos podem ter as seguintes estruturas:

```javascript
// Exemplos de UserMessage

// Intro
{
    "botId": "ko3123ze",
    "version": "DRAFT",
    "sessionId": "emulator-942c05c5-b9b7-4319-81e7-6d687afaa23f",
    "event": "messages",
    "messages": [
        {
            "actor": "user",
            "message": {
                "channelType": "web",
                "sender": {
                    "id": "emulator-942c05c5-b9b7-4319-81e7-6d687afaa23f",
                    "botId": "ko3123ze",
                    "botType": "web",
                    "preferredLanguage": "en",
                    "firstname": "Guest",
                    "isEmulator": "true"
                },
                "timestamp": "2021-11-15T08:28:05.872Z",
                "messageType": "intro",
                "id": "61921a15cdee7f37a16ee5fc"
            },
            "timestamp": "2021-11-15T08:28:05.872Z"
        }
    ],
    "timestamp": "2021-11-15T08:28:05.908Z"
}

// Texto
{
    "botId": "ko3123ze",
    "version": "DRAFT",
    "sessionId": "emulator-8f5873aa-8fee-471a-9467-81e30dec693d",
    "event": "messages",
    "messages": [
        {
            "actor": "user",
            "message": {
                "channelType": "web",
                "sender": {
                    "id": "emulator-8f5873aa-8fee-471a-9467-81e30dec693d",
                    "botId": "ko3123ze",
                    "botType": "web",
                    "isEmulator": "true"
                },
                "timestamp": "2021-11-15T08:26:13.154Z",
                "messageType": "text",
                "text": "hi there",
                "id": "619219a5cdee7f9f1b6ee5f7"
            },
            "timestamp": "2021-11-15T08:26:13.154Z"
        }
    ],
    "timestamp": "2021-11-15T08:26:13.193Z"
}

// Upload
{
    "botId": "ko3123ze",
    "version": "DRAFT",
    "sessionId": "1636964964162",
    "event": "messages",
    "messages": [
        {
            "actor": "user",
            "message": {
                "channelType": "web",
                "sender": {
                    "id": "1636964964162",
                    "botId": "ko3123ze",
                    "botType": "web",
                    "firstname": "Guest"
                },
                "timestamp": "2021-11-15T08:29:38.900Z",
                "messageType": "fileUploadInputResult",
                "urls": [
                    "https://minio.dev.chatlayer.ai/chatlayer-dev-eu-storage/f42af93e42b350fd7b874300c775756b168cc9ea4475b0c8c80e947228a26404/1636964964162_full.png"
                ],
                "data": {
                    "uploadStatus": "SUCCEEDED",
                    "fileUrl": "https://minio.dev.chatlayer.ai/chatlayer-dev-eu-storage/f42af93e42b350fd7b874300c7asdasdcc9ea4475b0c8c80e947228a26404/1636964964162_full.png"
                },
                "id": "61921a72cdee7fd1c56ee614"
            },
            "timestamp": "2021-11-15T08:29:38.900Z"
        }
    ],
    "timestamp": "2021-11-15T08:29:38.934Z"
}}

// Localização
{
    "botId": "ko3123ze",
    "version": "DRAFT",
    "sessionId": "emulator-8f5873aa-8fee-471a-9467-81e30dec693d",
    "event": "messages",
    "messages": [
        {
            "actor": "user",
            "message": {
                "channelType": "web",
                "sender": {
                    "id": "emulator-8f5873aa-8fee-471a-9467-81e30dec693d",
                    "botId": "ko3123ze",
                    "botType": "web",
                    "isEmulator": "true"
                },
                "timestamp": "2021-11-15T08:26:13.154Z",
                "messageType": "location", 
                "coordinates": { "lat": 0, "long": 0 } 
                "id": "619219a5cdee7f9f1b6ee5f7"
            },
            "timestamp": "2021-11-15T08:26:13.154Z"
        }
    ],
    "timestamp": "2021-11-15T08:26:13.193Z"
}

// Postback
{
    "botId": "ko3123ze",
    "version": "DRAFT",
    "sessionId": "emulator-6d09d652-a971-47ab-8484-223a86ff316e",
    "event": "messages",
    "messages": [
        {
            "actor": "user",
            "message": {
                "channelType": "web",
                "sender": {
                    "id": "emulator-6d09d652-a971-47ab-8484-223a86ff316e",
                    "botId": "ko3123ze",
                    "botType": "web",
                    "isEmulator": "true"
                },
                "timestamp": "2021-11-15T08:33:39.276Z",
                "messageType": "postback",
                "title": "Set Variables",
                "parameters": [],
                "nextDialogstateId": "071abbc7-1d6e-4689-adef-1ea825178a72",
                "id": "61921b63cdee7f21ab6ee621"
            },
            "timestamp": "2021-11-15T08:33:39.276Z"
        }
    ],
    "timestamp": "2021-11-15T08:33:39.309Z"
}
```

## Repasse

<mark style="color:verde;">`POST`</mark> `<sua_url_de_api>`

#### Corpo da Solicitação

| Nome        | Tipo   | Descrição                                                           |
| ----------- | ------ | ------------------------------------------------------------------- |
| payload     | object | A carga útil que você configurou no dialogstate de ação             |
| canal       | string |                                                                     |
| transcrição | array  | Um array contendo todas as mensagens enviadas ao longo da conversa. |
| evento      | string | O tipo de solicitação, neste caso **`repasse`**                     |
| timestamp   | string |                                                                     |
| sessionId   | string |                                                                     |
| version     | string |                                                                     |
| botId       | string |                                                                     |

{% tabs %}
{% tab title="200 Para repasse bem-sucedido, esperamos a seguinte resposta" %}

```
{
    "offloadSuccess": true,
    "pauseBot": true
}
```

{% endtab %}
{% endtabs %}

Os itens no array transcript têm o mesmo formato que no **mensagens** método descrito acima.

Um exemplo de solicitação de repasse pode ser o seguinte:

```
// Algum código
{
    "botId": "ko3123ze",
    "version": "DRAFT",
    "sessionId": "emulator-714a7b79-d674-4a62-a9a9-49581d7451e5",
    "timestamp": "2021-11-15T08:36:21.527Z",
    "event": "offload",
    "transcript": [
        {
            "actor": "bot",
            "message": {
                "text": "Hi Welcome"
            },
            "timestamp": "2021-11-15T08:36:11.991Z"
        },
        {
            "actor": "bot",
            "message": {
                "text": "Choose what you want to do?",
                "quick_replies": [
                    {
                        "title": "Do API FROM CODE",
                        "payload": "{\"title\":\"Do API FROM CODE\",\"caption\":\"Do API FROM CODE\",\"type\":\"quickreply\",\"parameters\":[],\"nextDialogstateId\":\"19f87132-e23c-4335-877d-6a36f511c2cc\",\"originalTitle\":\"Do API FROM CODE\"}",
                        "content_type": "text"
                    },
                    {
                        "title": "Api Plugin",
                        "payload": "{\"title\":\"Api Plugin\",\"caption\":\"Api Plugin\",\"type\":\"quickreply\",\"parameters\":[],\"nextDialogstateId\":\"e0b327e0-bfa0-42a7-9685-c68491625b6e\",\"originalTitle\":\"Api Plugin\"}",
                        "content_type": "text"
                    },
                    {
                        "title": "carousel",
                        "payload": "{\"title\":\"carousel\",\"caption\":\"carousel\",\"type\":\"quickreply\",\"parameters\":[],\"nextDialogstateId\":\"0844670c-ee9f-43eb-9102-f50321cb4921\",\"originalTitle\":\"carousel\"}",
                        "content_type": "text"
                    },
                    {
                        "title": "first options",
                        "payload": "{\"title\":\"first options\",\"caption\":\"first options\",\"type\":\"quickreply\",\"parameters\":[],\"nextDialogstateId\":\"13fc7f3e-80e5-45b8-862b-d2ff436eae0e\",\"originalTitle\":\"first options\"}",
                        "content_type": "text"
                    }
                ]
            },
            "timestamp": "2021-11-15T08:36:11.992Z"
        },
        {
            "actor": "user",
            "message": {
                "parameters": [],
                "text": "first options",
                "messageType": "postback",
                "title": "first options",
                "nextDialogstateId": "13fc7f3e-80e5-45b8-862b-d2ff436eae0e",
                "channelType": "emulator",
                "sender": {
                    "id": "emulator-714a7b79-d674-4a62-a9a9-49581d7451e5",
                    "botId": "ko3123ze"
                }
            },
            "timestamp": "2021-11-15T08:36:15.009Z"
        },
        {
            "actor": "bot",
            "message": {
                "attachment": {
                    "type": "template",
                    "payload": {
                        "template_type": "button",
                        "text": "What do you want to do?",
                        "buttons": [
                            {
                                "title": "Set Variables",
                                "type": "postback",
                                "payload": "{\"title\":\"Set Variables\",\"caption\":\"Set Variables\",\"type\":\"button\",\"originalTitle\":\"Set Variables\",\"nextDialogstateId\":\"071abbc7-1d6e-4689-adef-1ea825178a72\",\"parameters\":[]}"
                            },
                            {
                                "title": "offload",
                                "type": "postback",
                                "payload": "{\"title\":\"offload\",\"caption\":\"offload\",\"type\":\"button\",\"originalTitle\":\"offload\",\"nextDialogstateId\":\"408c102e-7215-48f8-a76c-5a45d70dcd9d\",\"parameters\":[]}"
                            }
                        ]
                    }
                }
            },
            "timestamp": "2021-11-15T08:36:15.010Z"
        }
    ]
}
```

## Receitas

### Transferência para humano solicitada pelo usuário

Use um bloco de Ação "Enviar para provedor de repasse" para acionar uma **repasse** chamada para sua API.

![](/files/82f185b59ecb1093c1029bf99c3686b150131ce0)

### Enviando mensagens como um agente

Use o [API de ações de conversa ](https://api.chatlayer.ai/v1/docs/#operation/executeConversationAction)para enviar mensagens como um agente.&#x20;

### Perguntas Frequentes sobre Webhook de Repasse

Aqui você pode encontrar perguntas frequentes sobre o repasse via Webhook

**Por que recebo solicitações no endpoint de repasse mesmo que o usuário ainda não tenha sido repassado?**

Enviamos os detalhes de todas as conversas que estão acontecendo entre usuário e o bot para o endpoint de repasse sob o **evento: "messages"** para que você possa assumir a conversa, se necessário. Isso também permitiria que os clientes acompanhassem todas as conversas, se necessário.


---

# 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://docs.chatlayer.ai/chatlayer-documentation-pt-br/integrateandcode/human-offloading-live-chat/offloading-webhook.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.
