# Webhook

A webhook listens for incoming events on a specified endpoint and triggers the next step in the workflow upon receiving relevant data.

Webhooks listen for events from third-party apps.

They are commonly used for tasks like payment collection, where the chatbot waits for a payment processor to notify it once the payment is received.

![](https://1047404187-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FeyvV4WfyYBGZdBoAuetg%2Fuploads%2FB0wksXB8dZoPqjzkc3gE%2FWebhook%201.png?alt=media\&token=57f1644f-825b-42a5-8f83-7bf32e336338)

### **Endpoint:**

Set this webhook endpoint in the application that will send the event.

When calling this endpoint, you must include the conversation\_key in the response payload. If it’s missing, the system will not consider the response successful.

You can extract the conversation\_key from the Conversation URL variable.

Before using the webhook block, add a JavaScript Action Block with the following code.

```json
const conversation_url = "Conversation URL";  
const conversation_url = "Conversation URL";
// Function to extract the conversation key from the URL
function getLastPartOfUrl(url) {
// Split the URL by slashes
const parts = url.split('/');
// Return the last part
return parts[parts.length - 1];
}
// Retrieve the conversation key from the URL
const conversation_key = getLastPartOfUrl(conversation_url);
// Sets the conversation key into a new variable
wn.setConversationVariable("conversation_key", conversation_key);
// This variable will be used to push the conversation_key to the third-party app.  
```

#### **Timeout:**

The chat flow will wait for the webhook call for a set duration.

If the webhook is not triggered within this timeframe, the chat flow will continue through the **FAILURE** path.

{% hint style="info" %}
**Set the duration between 1 and 300 seconds.**
{% endhint %}

#### **Response:**

When a webhook response is received, you can assign specific fields to variables for storage.

{% hint style="info" %}
&#x20;**You can map a maximum of 50 variables.**
{% endhint %}

<figure><img src="https://1047404187-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FeyvV4WfyYBGZdBoAuetg%2Fuploads%2FBVQq02fzicv8qN8vlAgo%2Fwebhook%202.png?alt=media&#x26;token=26e13f2f-c7f3-4141-b91b-9ddf019da97d" alt=""><figcaption></figcaption></figure>
