Write Bot Conversations Using Variables and Entities

Create an Entity for Order Number

Now we can start writing message dialogs so customers can have a real conversation with the bot.

Earlier, we created empty placeholders for Order Related and Appointment Related dialogs to simply list them from the Main Menu dialog. We also created a welcome message to the customer, which is displayed from the welcome dialog.

In a minute, we’ll create a question. This is where you configure the bot to ask a question and then store the answer in a variable to use later. But first we need to set up an entity.

Entities are a type of data that you want to collect from a customer. For example, an entity can be an order number or email address.

Let’s assume all orders in Ursa Major Solar’s management system are in the format O-12345.

  1. Next to Dialogs, click the dropdown arrow and select Entities.
  2. Click New, and enter the details:
    • Label: OrderNumberString
    • Extraction Type: Pattern
    • Regex: ^O\-\d{5}$ (We use regex, a regular text expression that describes a search pattern, to ensure Salesforce stores order numbers in the proper format. The expression ^O\-\d{5}$ only allows strings that start with the letter “O-” followed by five numbers to be stored in any variable associated with this entity.)The New Entity dialog.
  3. Click Save.

Add a Question and Create a Variable

A variable is a container that stores a specific piece of data collected from the customer. Let's create the variable OrderNumber and associate it with the entity OrderNumberString as we add a question to the Bot Asks field.

  1. Next to Entities, click the dropdown arrow and select Dialogs.
  2. Click the Order Status dialog and select Question in the main body of the dialog.
  3. In Bot Asks, enter What's the order number? (Note: It usually starts with letter O followed by a dash and 5 numbers.)
  4. Set the Entity Name to attribute to the OrderNumberString (Text).
  5. Click in the Save Answer to Variable box, and Select + New Variable.
    • Label: OrderNumber
    • API Name: OrderNumber
    • Data Type: Text
  6. Click Save.
The Save Answer to Variable attribute on the Question section.

To verify we are capturing the customer entry, add a message. This way the variable gets merged back to a message so that we can verify the result.

  1. Click Plus icon below the Question section and select Message.
  2. In Bot Says, enter: Sure, let me look up this order {!OrderNumber} for you. The Message section of the page, with Bot Says highlighted.
  3. Click Save.

Let’s Test!

When a customer asks for an order status, we ask for the order number so we can look it up.

  1. Activate the bot.
  2. If the Preview panel is not open, click Preview.
  3. Next to Ursa Major Solar Chat Agents, click Submit.
  4. Click Chat with an Expert.
  5. Fill in every field in the pre-chat form and click Start Chatting.
  6. Click Order Related.
  7. You can click 1 New Message or scroll down the chat window and click Order Status.
  8. Enter O-12345 and press Enter.

Your conversation should look like this.

The Jana bot showing order status of O-12345.

Congratulations, you just had a conversation with a bot! More importantly, you just built a bot that can engage with Ursa Major Solar’s customers.

As an admin, you can show Juan Garcia how to set up Einstein Bots to make his dream of creating a customer support robot that handles repetitive tasks a reality. More importantly, Juan will have extra time to make customers happy. In addition, Juan’s most loyal customers will get their simple questions answered at robotic speed, and they’ll feel confident recommending Ursa Major Solar. Well done!

We won't check any of your setup. Click Verify Step to earn your badge.

Keep learning for
Sign up for an account to continue.
What’s in it for you?
  • Get personalized recommendations for your career goals
  • Practice your skills with hands-on challenges and quizzes
  • Track and share your progress with employers
  • Connect to mentorship and career opportunities