# Webhook

### Why is it needed&#x20;

Example: a user got into an online school bot.&#x20;

The bot told about the courses, and the client went to the site. Bought one of the courses there. If you set up webhook integrations in the course learning platform, then the bot will write to the client itself.&#x20;

That is, with the help of a webhook, another service can launch the desired Smartbot Pro script chain.

### Creating and configuring a webhook

1. **We create a token**

You can create a new token and see a list of all project tokens in the Integrations section.&#x20;

To run the bot, you need to create a token with the right to execute blocks. Click "Generate Token" and select "Access Level - Block Execution".

![](/files/NapSqIsbcun2pWwJhb8z)

![](/files/J4mOmYDPoVIPFBox5HMG)

**2. Create a "Webhook" event in the script**

In the script to start the chain from another service, you need to set up a special Webhook event that will allow you to launch the bot via the API.&#x20;

Go to the desired scenario, select "Events" --> "Webhook" in the side menu.

![](/files/561LvTFthc1ghuUnfSVv)

**3. Specify the token**

In the Webhook block, select the created token or create a new one.

![](/files/OFnpa2PWkl0fPEA02GdZ)

**4. Choose a channel**&#x20;

Select a channel on the social network where the bot will work after you "pull" it with a webhook.&#x20;

If the bot works simultaneously in the LAN and in the conversation, you must also specify the desired chat:

![](/files/h9QwS5dNrMKIKKR5jzPA)

**5.** **Request parameters: URL and body.**

Copy the specified URL and send a POST request to it from your service.

![:](/files/uEoq2vnal9DiKI1sT7AU)

Copy the following JSON and paste it into the Request *Body*:

![](/files/xXPepfJijE3UCHhnbvuJ)

{% hint style="info" %}
peer\_id is the ID of the chat to which the message from the bot will be sent
{% endhint %}

* If the bot should work in a group chat, then the peer\_id will be set automatically
* If the bot should work in the LAN, then the peer\_id must be filled in independently in accordance with the prompt

![](/files/ZMsggI3n006iTDSSKFZn)

### Requirements for sending a message via Webhook

For a user to receive a message via a webhook, two conditions must be met:

* allowed to send messages to PM
* the user has already communicated with the bot (the bot cannot be the first to write to the user)

### Deleting a token

If the token is stolen by an attacker, it must be deleted in the Integrations section.

![](/files/4toacSxxCxxjEkTeAINF)


---

# 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.smartbotpro.io/scripts/script-events/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.
