Como usar webhooks?

Última atualização em Feb 21, 2025

Webhooks são callbacks HTTP que são configurados para cada conta. Eles são acionados quando ações como criar uma mensagem ocorrem no Chat. Vários webhooks podem ser criados para uma única conta.

Como adicionar um webhook? 

Etapa 1.  Vá para Configurações → Integrações → Webhooks . Clique no botão "Configurar".

Etapa 2. Clique no botão "Adicionar novo webhook". Um modal será aberto. Aqui, insira a URL para a qual a solicitação POST deve ser enviada. Em seguida, você precisa selecionar os eventos que deseja assinar. Esta opção permitirá que você ouça apenas os eventos relevantes no Chat.

O Chat enviará uma solicitação POST com o seguinte payload para as URLs configuradas para várias atualizações em sua conta.

Um exemplo de payload do webhook

{

  "event": "message_created", // The name of the event
  "id": "1", // Message ID
  "content": "Hi", // Content of the message
  "created_at": "2020-03-03 13:05:57 UTC", // Time at which the message was sent
  "message_type": "incoming", // This will have a type incoming, outgoing or template. The contact sends incoming messages, and the agent sends outgoing messages to the user.
  "content_type": "enum", // This is an enum, it can be input_select, cards, form or text. The message_type will be template if content_type is one og these. Default value is text
  "content_attributes": {} // This will an object, different values are defined below
  "source_id": "", // This would the external id if the inbox is a Twitter or Facebook integration.
  "sender": { // This would provide the details of the agent who sent this message
    "id": "1",
    "name": "Agent",
    "email": "agent@example.com"
  },
  "contact": { // This would provide the details of the user who sent this message
    "id": "1",
    "name": "contact-name"
  },
  "conversation": { // This would provide the details of the conversation
    "display_id": "1", // This is the ID of the conversation which you can see in the dashboard.
    "additional_attributes": {
      "browser": {
        "device_name": "Macbook",
        "browser_name": "Chrome",
        "platform_name": "Macintosh",
        "browser_version": "80.0.3987.122",
        "platform_version": "10.15.2"
      },
      "referer": "<http://www.approachti.com.br>",
      "initiated_at": "Tue Mar 03 2020 18:37:38 GMT-0300"
    }
  },
  "account": { // This would provide the details of the account
    "id": "1",
    "name": "Account",
  }
}

Eventos de webhook suportados no Chat

O Chat publica vários eventos nos endpoints de webhook configurados.

Cada evento tem sua estrutura de payload com base no tipo de modelo em que estão atuando. A seção a seguir descreve os principais objetos que usamos no Chat e seus atributos.

Objetos 

Um payload de evento pode incluir qualquer um dos seguintes objetos. Os vários tipos de objetos suportados pelo Chat estão listados abaixo.

Conta

{
  "id": "integer",
  "name": "string"
}

Caixa de entrada

{
"id": "integer",
"name": "string"
}

Contato

{
  "id": "integer",
  "name": "string",
  "avatar": "string",
  "type": "contact",
  "account": {
    // <...Account Object>
  }
}

Usuário

{
  "id": "integer",
  "name": "string",
  "email": "string",
  "type": "user"
}

Conversa

{
  "additional_attributes": {
    "browser": {
      "device_name": "string",
      "browser_name": "string",
      "platform_name": "string",
      "browser_version": "string",
      "platform_version": "string"
    },
    "referer": "string",
    "initiated_at": {
      "timestamp": "iso-datetime"
    }
  },
  "can_reply": "boolean",
  "channel": "string",
  "id": "integer",
  "inbox_id": "integer",
  "contact_inbox": {
    "id": "integer",
    "contact_id": "integer",
    "inbox_id": "integer",
    "source_id": "string",
    "created_at": "datetime",
    "updated_at": "datetime",
    "hmac_verified": "boolean"
  },
  "messages": ["Array of message objects"],
  "meta": {
    "sender": {
      // Contact Object
    },
    "assignee": {
      // User Object
    }
  },
  "status": "string",
  "unread_count": "integer",
  "agent_last_seen_at": "unix-timestamp",
  "contact_last_seen_at": "unix-timestamp",
  "timestamp": "unix-timestamp",
  "account_id": "integer"
}

Mensagem

{
  "id": "integer",
  "content": "string",
  "message_type": "integer",
  "created_at": "unix-timestamp",
  "private": "boolean",
  "source_id": "string / null",
  "content_type": "string",
  "content_attributes": "object",
  "sender": {
    "type": "string - contact/user"
    // User or Contact Object
  },
  "account": {
    // Account Object
  },
  "conversation": {
    // Conversation Object
  },
  "inbox": {
    // Inbox Object
  }
}

Um exemplo de carga útil do webhook

{
  "event": "event_name"
  // Attributes related to the event
}

Eventos de Webhook 

O Chat suporta os seguintes eventos de webhook. Você pode se inscrever neles enquanto configura um webhook no painel ou usa a API.

conversation_created

Este evento será disparado quando uma nova conversa for criada na conta. O payload para o evento é o seguinte.

{
  "event": "conversation_created"
  // <...Conversation Attributes>
}

conversation_updated

Este evento será acionado quando houver uma alteração em qualquer um dos atributos da conversa.

{
  "event": "conversation_updated",
  "changed_attributes": [
    {
      "<attribute_name>": {
        "current_value": "",
        "previous_value": ""
      }
    }
  ]
  // <...Conversation Attributes>
}

conversation_status_changed

Este evento será acionado quando o status da conversa for alterado.

Observação: se você estiver usando APIs de bot de agente em vez de webhooks, esse evento ainda não é compatível.

{
  "event": "conversation_status_changed"
  // <...Conversation Attributes>
}

message_created

Este evento será disparado quando uma mensagem for criada em uma conversa. O payload para o evento é o seguinte.

{
  "event": "message_created"
  // <...Message Attributes>
}

message_updated 

Este evento será disparado quando uma mensagem for atualizada em uma conversa. O payload para o evento é o seguinte.

{
  "event": "message_updated"
  // <...Message Attributes>
}

webwidget_triggered

Este evento será acionado quando o usuário final abrir o widget de chat ao vivo.

{
  "id": ,
  "contact": {
    // <...Contact Object>
  },
  "inbox": {
    // <...Inbox Object>
  },
  "account": {
    // <...Account Object>
  },
  "current_conversation": {
    // <...Conversation Object>
  },
  "source_id": "string",
  "event": "webwidget_triggered",
  "event_info": {
    "initiated_at": {
      "timestamp": "date-string"
    },
    "referer": "string",
    "widget_language": "string",
    "browser_language": "string",
    "browser": {
      "browser_name": "string",
      "browser_version": "string",
      "device_name": "string",
      "platform_name": "string",
      "platform_version": "string"
    }
  }
}