Ask AI
English EN
Go to Watbot

Messages and jumps

These functions decide what the contact sees and where the scenario goes after the code. Messages and the jump are carried out once the code has finished without an error — in the order they were called.

sendMessage

sendMessage(text)

Sends a text message to the contact.

Parameter Type What to pass
text String The message text. A number is turned into a string

Returns nothing.

An empty string is not sent. The text goes out as is: templates {{ ... }} in it are not processed — insert the values you need into the string in code.

Up to 10 messages can be sent per run. The eleventh call already ends the code with an error, and not a single message is sent.

var bouquet = getContactVariable('bouquet');
var price = Number(getContactVariable('price') || 0);

sendMessage('Your order: ' + bouquet + '.');
sendMessage('To pay: $' + price + '.');

goToBlock

goToBlock(id)

Moves the contact to a scenario block: the bot runs that block just as if a connection led to it.

Parameter Type What to pass
id Number The ID of a block of the same bot. It is shown in the block settings

Returns nothing.

The function can be called once per run — a second call ends the code with an error. If the bot has no block with this ID, there is no jump, and no error appears in the log — check the ID.

goToBlock does not cancel the "Continue" connection: without disableContinue() the bot runs both the given block and the one connected to "Continue".

var sum = Number(getContactVariable('order_total') || 0);

if (sum >= 100) {
    goToBlock(12345);
    disableContinue();
}

Replace 12345 with the ID of the block you need.

disableContinue

disableContinue()

Disables the block's "Continue" connection for this run: the scenario does not move on along it. Next time the connection works again, unless the code calls disableContinue() again.

No parameters.

Returns nothing.

This way the code itself decides whether the scenario moves on: for example, it stops until the contact has filled in an address.

var address = getContactVariable('delivery_address');

if (!address) {
    sendMessage('Send us the delivery address, and we will continue with your order.');
    disableContinue();
}