Browse Documentation

Writing JavaScript Calculations inside Chatbot

Calculate order totals, apply dynamic coupon codes, and format date objects inside visual flows.


Writing custom calculations in JS

Botalyzer executes sandboxed JavaScript code blocks to let you manipulate flow variables.

Script Example:

const subtotal = Number(variables.cart_total);
const isVip = variables.customer_level === 'VIP';
const discount = isVip ? subtotal * 0.15 : 0;
return {
discount_applied: discount,
total_price: subtotal - discount
};

All returned fields in the output object are saved as variables for succeeding nodes.