Choosing a contact
A request to the "Incoming webhook" block comes not from a person but from a third-party service. So the code itself says which contact the request belongs to — with one of the functions below. They exist only in this block; in the other blocks the contact is already known.
Common rules for all functions:
- The contact is searched for only among this bot's contacts. Deleted contacts are not found.
- Returns
trueif the contact is found, andfalseif not. - Only one function can be called per request, and only once. A second call — even of a different function — ends the code with an error, and the block responds with code
422. - At least one function must be written in the code. Without it, the block does not run the code and responds with
422. - Once the contact is found, the code can use the contact's built-in variables, variables and tags. Before that, the contact's variables are empty, and referring to
id,nameand other contact data stops the code with an error. - If the contact is not found or no function was called, the code runs but saves nothing: variables, tags and global variables are not written, messages are not sent, the jump and the "Continue" connection do not fire. The block responds with
200and the messageCode executed without setting contact.
setContactById
setContactById(id)
Finds the contact by their ID on the platform.
| Parameter | Type | What to pass |
|---|---|---|
id |
A number or a string of digits | The contact ID. In a scenario you can get it with the template {{ id }} |
if (setContactById(request.query.contact_id)) {
setContactVariable('payment', 'received');
sendMessage('Payment received, we are starting to put your bouquet together.');
}
For the third-party service to know the ID, pass it in advance — for example, in the payment link or with an "HTTP request" block.
setContactByTelegramId
setContactByTelegramId(id)
Finds the contact by the person's ID in Telegram.
| Parameter | Type | What to pass |
|---|---|---|
id |
A number or a string of digits | The Telegram user ID — the same as in the telegram_id variable |
var message = request.data.message;
if (message && message.from && setContactByTelegramId(message.from.id)) {
setContactTag('wrote_in_group');
}
setContactByMaxId
setContactByMaxId(id)
Finds the contact by the person's ID in MAX.
| Parameter | Type | What to pass |
|---|---|---|
id |
A number or a string of digits | The MAX user ID — the same as in the max_id variable |
if (setContactByMaxId(request.data.user_id)) {
sendMessage('The courier is on the way.');
}
setContactByVkId
setContactByVkId(id)
Finds the contact by the person's ID in VK.
| Parameter | Type | What to pass |
|---|---|---|
id |
A number or a string of digits | The VK user ID — a number without id at the start |
if (setContactByVkId(request.data.vk_user_id)) {
setContactTag('left_review');
}
setContactByViberId
setContactByViberId(id)
Finds the contact by the person's ID in Viber.
| Parameter | Type | What to pass |
|---|---|---|
id |
String | The Viber user ID — a string of letters, digits and symbols; do not turn it into a number |
if (setContactByViberId(request.data.viber_id)) {
sendMessage('Your order has been handed over for delivery.');
}