Build a calculator bot

Define the value of other variables

You can define or change the value of a variable with the Update Variables action. This action helps the value of a variable be updated automatically in the flow.

In order to define the value for a variable, firstly, you need to drag and drop an Update Variable action into the canvas at the desired position. Then, set up the value for that variable.

  • For the variable which has the "Text" data type, after all the sub-variables are updated, its value will be in the same structure that you defined before. For example, you set the content for the productOrder variable to include order information:

Let set up the value for productOrder as below:

Name: {response.Product}

Quantity: {response.Quantity}

Price: {product.Price} $

You can check the result of productOrder with Preview. After testing, we have:

The User Response {response.Product} is replaced by Apple

The User Response {response.Quantity} is replaced by 3

The value of cost is 87

  • For the variable which has "Date" data type, you can directly type in a value or assign other variables which are formatted as YYY/MM/DD. For example: 2019-01-01.
  • For the variable which has a “Number" data type, you can perform basic operations such as addition (+), subtraction (-), multiplication (*), or division (/).

For example, you assign an operation to cost like this: cost = {totalPrice} - {totalPrice} * {discount}

At the beginning:

  • totalPrice is 100
  • discount is 0.2
  • price is 0

After implementing the operation, the new value of cost is:

cost = 100 - 100 * 0.2 = 80

  • For the Variable which has a “List" data type, you can build its new value by assigning many sub-variables into it. When being displayed, these sub-variables will be separated automatically by commas.

Insert into the text

You can insert these data into the content of any blocks to send instructive messages to users.

In example 1 (the first picture), when a user asks for your store address, you can quickly answer with the predefined variable store_address (Bot Attribute). At the same time, you can insert the first_name of users into the message to personalize and make it more friendly. Click Insert Variables to open the list of variables and select.

In example 2 (the second picture), your need is to state the value of the bill. In order to do so, use predefined Flow Variables such as ordered, totalPrice and cost. Read about how to define the value of a variable.

Navigate users in the conversation flow

These types of data can also be utilized in connectors between any two blocks to send suitable messages to users. This helps bot serve a wide range of users wisely.

First case: Use User Responses to direct users in the flow.

For example Direct users to appropriate answers based on their shopping demand.

In Product block, turn on Capture User Response (Expect User Response) option to temporarily save the response of users. Let's assume that users know 2 types of products of the business are Set and Item.

On each connector initiating from Product block to Happy Set block and Happy Item block, set a condition with the following structure: User's response - contains - keyword of product. If the response of the user matches the predefined keywords, the user will be directed to the corresponding block.

Second case: Use Flow Variables to direct users in the flow. For example: Give discount vouchers to users based on the value of the order. If it's higher than $20, users get a 20% discount.

First of all, you need to create a totalPrice variable as in the section Variable in order to calculate the value of an order. Then, on the connector leading to Discount More block, create a condition like this: totalPrice - equal or greater than - a number. If the calculated result is higher than $20, the order will be discounted for 20%.

Third case: Use User Attributes to direct users in the flow. For example: Greet a user with an appropriate title based on Gender.

The Gender variable is available in the bot deployed on Facebook or deployed on a website with Facebook Messenger Chat Plugin. With conversation flow designed as in the picture, you just need to set up the filter condition: Gender - is/is not - Gender.

Fourth case: Use Bot Attributes to direct users in the flow. For example, the bot sends different content to users based on the time they interact with the bot.

First, you need to create a Variable for business hours and use it in the condition of connectors to send appropriate messages. For example, the office hours of your company are 8 AM-6 PM, if a customer sends queries outside this timeframe, the bot will suggest replying on the next working day.

Filter CMS Items

These types of data absolutely can be used to filter suitable items from an Entity, corresponding to the user's input.

If you have any concerns, please feel free to leave a comment below or contact us through support@botstar.com. For more details on how we have helped our customers grow their business, you can view our use cases, blogs or join our BotStar community to learn and share new things 😊


Did you find it helpful?   Yes   No