Skip to content

Incoming Webhook

Receiving data from third-party services in bot using Incoming Webhook

Incoming webhook allows you to launch a bot scenario for a specific contact from an external service and pass parameters to it.

How to Create Incoming Webhook in Chat Bot

To create a webhook, you need to perform the following actions:

  1. Create a scenario in the "Scenarios" section that will be called using the webhook
  2. Create a webhook in the "Incoming Webhooks" section incoming webhook
  3. Select webhook type:

    1. Standard webhook — webhook for which mapping of received variables with bot variables is configured
    2. Javascript webhook — webhook in which the received request is parsed using custom javascript code.

    bot integrations

    Webhook type selection

    4. Specify an arbitrary name 5. Select the required scenario

Standard Webhook

To configure a standard webhook, you need to configure the mapping of variables passed in the request body with bot variables that will be written when the webhook is called. All variables in the webhook request body must be passed inside the variables variable. If the bot does not yet have a variable with the given name, it will be created.

Javascript Webhook

In the input field, paste the code to process the received request.

Received request fields:

var rawBody = response.body; // Raw request body
var data = response.data; // Object of all request variables, including query string, form, body, etc.

For correct script execution, you need to:

  1. Set the contact for which the JavaScript code will be executed
setContactByTelegramId(<telegram contact id>) //sets the current contact by id from telegram
setContactById(<Leadtex contact id>) – sets the current contact by Leadtex contact id

Learn more about API:

Important

In the incoming webhook javascript interpreter, the functions are not available: goToBlock() and disableContinue().

Webhook Call

  1. After creating the webhook, a unique URL will be generated to launch the previously selected scenario.
  2. To call the webhook, you can use both POST and GET requests, variables will be read regardless of how they were passed: in the address or in the request body.

When calling the webhook URL, you must meet the following conditions:

  1. Request header (HTTP Headers) Accept must have the value "application/json"
  2. The request variables must contain the contact search indicator variable contact_by with any value from the list below and the search variable with the value by which the contact needs to be found:

id - search for contact by its identifier in the Leadteh system,

phone - search by phone number,

email - search by E-mail,

telegram_name - search by Telegram account name,

telegram_id - search by numeric Telegram identifier,

whatsapp - search by Whatsapp number,

vk - search by Vk identifier,

amocrm_id - search by identifier in AmoCRM system,

bitrix24_id - search by identifier in Bitrix24 system

Examples

Example GET request with phone number search:

https://rb14.leadteh.ru/inner_webhook/948c9d06-454d-4952-bc78-2a94bc4ce25f?contact_by=phone&search=79001234567

Example GET request with contact id search:

https://rb14.leadteh.ru/inner_webhook/948c9d06-454d-4952-bc78-2a94bc4ce25f?contact_by=id&search=123456

Example POST request body with passed variables and contact id search:

{
    "contact_by": "id",
    "search": 123456789,
    "variables": {
        "first_var": "First variable value",
        "second_var": "Second variable value"
    }
}

Each call with passed parameters can be viewed on the "Call History" tab.

Call history storage period is 10 days.

🎁 Free course on developing chat bots and MiniApps for all users with an active PRO subscription is already on LEADTEX.

10 detailed lessons with immersion from A to Z.

Start learning right now - Start learning.