Math Calculations Inside your Bot

Modified on Thu, 23 Nov, 2023 at 8:04 PM

Explore beyond fundamental operations such as addition, subtraction, multiplication, and division. Dive into the realm of intricate mathematical and scientific calculations using advanced functions (listed below).


Unlock the potential with practical examples that guide you through the process. Follow the step-by-step instructions to master the art of incorporating complex calculations seamlessly into your chatbot. Elevate your bot's capabilities and provide users with a sophisticated mathematical experience.


Step 1: Choose the Flow you want to include calculation operations.


Step 2: Select Action on the block builder and choose Set Custom Field.



Step 3:  Choose "Custom Field" in your flow. Then, select the custom field where your values are stored as numbers. Opt for a custom formula and define it in the Value field. This way, you can easily customize calculations to fit your specific needs within the chatbot flow.



Step 4: Then save, that’s it.


We know that it might confuse you a bit, let me explain this procedure with one simple example.


Example1: Performing (A+B)*(A-B) calculation

Get the values of A & B from user input as numbers,



Now set the calculation formula on the flow. For that, choose action on the basic builder and select the set custom field. Then, setup the wizard by choosing the custom field (number) in which you want to store the calculated values (here, we created that as “amount_paid”).


Now, the interesting part. Set the formula on the Value field (here we used the formula ( {{value a}} - {{value b}} ) * ( {{value a}} + {{value b}} ) to do the above said calculation.


That’s it, if you take A as 4 and B as 2, the result will be shown by a chatbot as 12 (as per the calculation).


Calculation on Web chatbot example.



Here are some basic math examples that you can do:


1+2*3-4

1 + 2 * 3 – 4

pi * 2

PI * 2

abs(1) + min(1,2) * max(1,2,3)

min(1+2, abs(-1))

1 + ((2 – 3) * (5 – 7))

2 * (-3)


Here is the example of formats with syntax:


1         // A term can consist of just a number

(1+((2))) // Usage of obsolete brackets is allowed

00001     // Prefixing a number with obsolete zero digits is possible

.1        // Omitting a zero digit before a period character is okay

Here are some awesome list to provide more value for this article:


Operators:

Addition (+)

Subtraction (-)

Multiplication (*) 

Division (/)


Functions:

abs

aCos

aCosH

aSin

aSinH

aTan

aTanH

aTanTwo

ceil

cos

cosH

degToRad

en

exp

expMOne

floor

fMod

hypot

log

logOneP

logTen

max

min

pow

radToDeg

round

sin

sinH

sqrt

tan

tanH


Constants:

e

euler

lnPi

lnTen

lnTwo

logTenE

logTwoE

onePi

pi

piFour

piTwo

sqrtOneTwo

sqrtPi

sqrtThree

sqrtTwo

twoPi

twoSqrtPi

Others:

( (right-faced brackets)

) (left-faced brackets)

, (comma)

. (dot)

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article