View Categories

Math Calculations Inside Your Chatbot

1 min read

ChitChatbot allows you to perform not just basic calculations like addition, subtraction, multiplication, and division, but also advanced mathematical and scientific calculations. Let’s walk through how to do this and what operators, functions, and constants you can use.


How to Perform Calculations

  1. Choose the Flow
    Select the flow where you want to include the calculation.
  2. Add an Action
    In the block builder, select ActionSet Custom Field.
  3. Set Up the Custom Field
    • Choose the existing custom field (where you want to store the result).
    • In the operation settings, choose Use custom formula.
    • In the Value field, enter your desired formula.
  4. Save
    Click Save to apply the changes.

Example: Calculating (A + B) * (A – B)

Suppose you want to calculate (A+B)×(A−B)(A + B) \times (A – B)(A+B)×(A−B), with A and B as custom fields filled from user input.

ab - ChitChatBot - AI Bot Building Platform
  • Step 1: Ensure A and B are already stored in custom fields (e.g., {{value a}} and {{value b}}).
  • Step 2: Create a new custom field (e.g., calculation_value) to store the result.
  • Step 3: In the Set Custom Field action, use this formula in the Value field: ({{value a}} + {{value b}}) * ({{value a}} - {{value b}})
  • Example Calculation:
    If A = 4 and B = 2:
    (4+2)×(4−2)=6×2=12(4 + 2) \times (4 – 2) = 6 \times 2 = 12(4+2)×(4−2)=6×2=12.
    The bot will show 12 as the result.
custom formula - ChitChatBot - AI Bot Building Platform

Examples of Basic and Complex Math Expressions

  • 1 + 2 * 3 - 4
  • pi * 2
  • abs(1) + min(1, 2) * max(1, 2, 3)
  • min(1 + 2, abs(-1))
  • 1 + ((2 - 3) * (5 - 7))
  • 2 * (-3)

Allowed Formats and Syntax

  • 1 → a simple number.
  • (1 + ((2))) → nested brackets are allowed.
  • 00001 → leading zeros are fine.
  • .1 → zero before the decimal point can be omitted.

Operators

OperatorDescription
+Addition
-Subtraction
*Multiplication
/Division

Functions

FunctionDescription
absAbsolute value
aCosArc cosine
aCosHHyperbolic arc cosine
aSinArc sine
aSinHHyperbolic arc sine
aTanArc tangent
aTanHHyperbolic arc tangent
aTanTwoArc tangent of two variables
ceilRounds up to the nearest integer
cosCosine
cosHHyperbolic cosine
degToRadDegrees to radians
expExponential
expMOneExponential minus one
floorRounds down to the nearest integer
fModFloating-point remainder of division
hypotHypotenuse
logNatural logarithm
logOnePNatural log of (1 + x)
logTenLogarithm base 10
maxMaximum value
minMinimum value
powPower function (x^y)
radToDegRadians to degrees
roundRounds to the nearest integer
sinSine
sinHHyperbolic sine
sqrtSquare root
tanTangent
tanHHyperbolic tangent

Constants

ConstantDescription
eEuler’s number (2.71828…)
eulerSame as e
lnPiNatural log of Pi
lnTenNatural log of 10
lnTwoNatural log of 2
logTenELog base 10 of e
logTwoELog base 2 of e
onePi1 divided by Pi
piPi constant (3.14159…)
piFourPi divided by 4
piTwoPi divided by 2
sqrtOneTwoSquare root of 1/2
sqrtPiSquare root of Pi
sqrtThreeSquare root of 3
sqrtTwoSquare root of 2
twoPi2 times Pi
twoSqrtPi2 times square root of Pi

Other Syntax

SymbolDescription
(, )Brackets (used to group expressions)
,Comma (used to separate arguments in functions)
.Dot (used for decimals and floating-point numbers)

Tips for Best Results

✅ Always store numerical inputs in custom fields as numbers (not text).
✅ Test your formula on small examples to ensure accuracy.
✅ For advanced calculations, break them into smaller formulas for better readability and maintainability.