# Webhook

With the Webhook channel you can enrich the information sent via certain [channels](/channels/all-channels.md). For example, instead of using the [direct](/channels/all-channels.md#direct-channels) Facebook Messenger or Whatsapp channel, you can use Webhook to send messages to Messenger or Whatsapp.

<figure><img src="/files/cfhPtUCyE2nU8OonQawa" alt=""><figcaption><p>By using the Webhook channel, the channel of choice is indirectly connected to Chatlayer.</p></figcaption></figure>

{% hint style="warning" %}
The Webhook channel should not be confused with [Webhook offloading](https://docs.chatlayer.ai/integrations/human-offloading-live-chat/offloading-webhook), designed for offloading to human agents.
{% endhint %}

## Send and receive messages with Webhook

Chatlayer provides:

* a Webhook message API endpoint:  to send a user message to the bot
* a Webhook configuration: Enables notifications when the bot responds to user messages sent via the Webhook Message API, as detailed [here](#registering-a-webhook-api). This API operates in near real-time, allowing you to trigger event-based actions immediately upon receiving a bot response. This setup facilitates seamless integration of the bot's flow logic into your application or messaging platform.

The overall mechanism is loosely based on Pubsub protocol and relies on HTTP request containing the bot message response being sent to a consumer Endpoint URL. The customer webhook Endpoint URL can be configured on our platform as described in [this section](/channels/all-channels/webhook-api.md#registering-a-webhook-api).

## Register a Webhook API

To add a Webhook API to your bot:

{% stepper %}
{% step %}
[Add a **Webhook** channel](/channels/add-a-channel-to-your-bot.md) to your bot.

<figure><img src="/files/3Y9gPIxERmqrBcDDqg4O" alt="" width="375"><figcaption></figcaption></figure>
{% endstep %}

{% step %}
Configure the **Webhook URL** field.

**T**his URL must either be publicly available, or at least available from our platform's IP range. We strongly advise using HTTPS for this endpoint.
{% endstep %}

{% step %}
Optionally, configure the **Verify token** field.

This can be any arbitrary string, but we recommend you use the one provided, which was randomly generated.
{% endstep %}
{% endstepper %}

## Webhook messages

<mark style="color:green;">`POST`</mark> `customer webhook endpoint URL configured in Chatlayer.ai`

When a user message is sent to the Webhook message API, the bot response(s) will be sent to the customer Webhook endpoint URL.&#x20;

The bot response body payload object will include the bot message. This message can have a different object structure based on the message type.

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

```
  "recipient": {
    "id": "default-b94215f0-0c7e-11ea-9c43-7174cba76asdfoijadsfoiadsiojadfiojasodijfb12"
  },
  "verifyToken": "eenheeluniekeverifytoken",
  "message": {
    "text": "test tekst message"
  }
```

{% endtab %}
{% endtabs %}

## Message objects

A bot message sent to the customer Webhook endpoint URL and returned as response to a user messages can have different object structures, depending on the message type. Want to learn how to build these message objects? Read about it here:

{% content-ref url="/pages/-LjqDAiDoJuB5Sfvuyub" %}
[Chatlayer messages specifications](/integrateandcode/chat-message-structure-for-apis.md)
{% endcontent-ref %}


---

# 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/channels/all-channels/webhook-api.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.
