How to Become a Chatbot Ninja in 7 Days
Module 3: Lesson 3.1. Calculating with custom fields
Lesson 3.1. Calculating with custom fields
Custom fields will allow you to store different sorts of data. In this chapter we will use the number format. Numbers in custom fields will make it possible to store data, subtract, multiply, divide or add. This comes in handy if you are doing some sort of quiz, valuation or as I will show in this example, a BMI (body mass index) calculation.
The formula for BMI is as follows:
Kilograms and meters (or centimeters) => weight (kg) / [height (m)]^2
Or
Pounds and inches => weight (lb) / [height (in)]^2 x 703
Now that you know this formula, it is easy to help your user with the BMI calculation by just asking some questions and store this data is custom fields. You’ll need three custom field variables:
-
- Weight
- Height
- An actual BMI field to store the result in and report back in a message.
In ManyChat, a formula for this would look like this:
Set mb_BMICalc to {mb_Weight}/(({mb_Height}/100)*({mb_Height})/100)
where the Weight is in KGS and Height is in cm and the custom fields are named mb_BMICalc, mb_Weight & mb_Height.
Even though that might seem like a great solution, it not really is. At least not to me, since the result will display the BMI as a number with many digits behind the decimal seperator.
Like e.g. 21.236589216589.
Personally, I really dislike that and that is why we looked for another way. We have found a few other methods how this can be accomplished. One of those is by using dynamic responses combined with a PHP script which calculates it nicely. I'll handle that in a next lesson.
Here is an image of the flow as I decribed above:
There are some other methods as well (Zapier combined with Google Sheets, JS) to do this, but we stick with ManyChat and PHP (next lesson).
Downloads
- Flows (2) used in this lesson (3.1)
This file contains the 2 messenger flows as explained in this lesson.
Download file > Open > Click the Link and Import into your Account.