Using cards in chatbot
This tutorial teaches you how to use a card carousel to interact with the user.
About this task
In this tutorial, you will:
- Set the bot language
- Start the bot execution context
- Send text messages
- Map the cards data table
- Send a carousel of cards
Before you begin
To develop the script, you need:
- Use the Designer tab in IBM RPA Studio
Get the resources:
- The complete script for this tutorial in Script for the "Using Cards in chatbot" tutorial
- The cards data table in Data table for the "Using Cards in chatbot" tutorial
Procedure
Defining the bot language
Start the digital assistant script development with the definition of the bot's language, also referred to as culture:
- Open a new blank script.
- Insert the Create a Language command in the script.
- Fill in the following parameters:
- In the Culture input parameter, select the option
en-US
. - In the Culture output parameter, insert the value
cultureEnUS
.
- In the Culture input parameter, select the option
Starting the bot execution context
The Connect to Chatbot and Disconnect Chatbot commands start and end, respectively, the context of the execution of the digital assistant.
- Insert the Connect to Chatbot command in the script.
- Fill in the following parameters:
- In the Communication type input parameter, select the option
Chat
. - In the Language input parameter, insert the
${cultureEnUS}
output variable returned by the Create a Language command. - In the Timeout input parameter, insert the value
00:05:00
.
- In the Communication type input parameter, select the option
The Disconnect Chatbot command is automatically inserted after defining and saving the Connect to Chatbot command.
- Save the Disconnect Chatbot command as soon as its window show on the screen.
Starting the interaction
Start the bot interaction by asking for the user's name:
- Insert the Bot Ask Name command inside the instruction block of the Connect to Chatbot and Disconnect Chatbot command.
- In the Text input parameter, insert the value
Hello, my name is Sofia, and I will be your virtual assistant. What is your name?
. - In the Timeout input parameter, insert the value
00:02:00
. - In the First output parameter, insert the value
userName
.
- In the Text input parameter, insert the value
Getting the cards data table
In this script, the cards show the user some examples of documentation about IBM Robotic Process Automation. The table contains the information that is mapped and disclosed by the Web Chat cards.
- Insert the Open Excel File command in the script.
- In the File input parameter, search for the directory where the spreadsheet with the extension
.xlsx
is stored. - In the File output parameter, insert the value
excelInstance
.
- In the File input parameter, search for the directory where the spreadsheet with the extension
- Insert the Get Excel Table command in the script.
- In the File input parameter, insert the
${excelInstance}
variable returned in the Open Excel File command. - Enable the Use first spreadsheet input parameter.
- Enable the Get the entire table input parameter.
- Enable the Contains headers input parameter.
- In the Table output parameter, insert the value
dataTable
.
- In the File input parameter, insert the
Mapping the data table to cards
After you get the data table, map your data to cards:
- Insert the Map Table to Cards command in the script.
- In the Table input parameter, insert the variable
${dataTable}
, returned in the Get Excel Table command. - In the Title column input parameter, insert the value
1
. - In the Subtitle column input parameter, insert the value
2
. - In the Text column input parameter, insert the value
3
. - In the Column URL input parameter, insert the value
4
. - In the Action column input parameter, insert the value
5
. - In the Action value column input parameter, insert the value
6
. - In the Cards output parameter, insert the value
cards
.
- In the Table input parameter, insert the variable
- Insert the Map Table to Card Buttons command in the script.
- In the Table input parameter, insert the
${dataTable}
variable returned in the Get Excel Table command. - In the Cards input parameter, insert the
${cards}
variable returned in the Map Table to Cards command. - In the Column with button action input parameter, insert the value
7
. - In the Column with button text input parameter, insert the value
8
. - In the Column with button value input parameter, insert the value
9
.
- In the Table input parameter, insert the
Building the script sequence
You need to develop an instruction block, which the user can select between viewing the other options of the card carousel or not.
- On the Home page tab, click the New variable button to define a new variable.
- In the Name input parameter, insert the value
endInteraction
. - In the Variable type input parameter, select the option
Boolean
.
- In the Name input parameter, insert the value
- Insert the Set Variable command in the script.
- In the Variable input parameter, insert the variable
${endInteraction}
declared in the previous step. - In the Value input parameter, insert the value
True
.
- In the Variable input parameter, insert the variable
- Insert the While command in the script.
- In the Left operator input parameter, insert the variable
${endInteraction}
. - In the Operator input parameter, select the option
Is true
.
- In the Left operator input parameter, insert the variable
The End While command closes that block of instructions. It is automatically inserted into the script when saving the While command.
Showing the cards on the web chat
After mapping the cards and your buttons, you need to show them in a cards carousel in the webchat:
- Insert the Bot Ask Carousel command inside the instruction block of the While command.
- In the Text input parameter, insert the value
${userName}, here I will give you some documentation options about IBM RPA. You can click "Read now" to know more!
. - In the Cards input parameter, insert the
$ {cards}
variable. - In the Timeout input parameter, insert the value
00:02:00
. - In the Value output parameter, insert the value
userResponse
.
- In the Text input parameter, insert the value
Ending the interaction
To finish the interaction, you need to develop an instruction block to identify if the user needs to end the interaction or not:
- Insert the Bot Ask Boolean command still inside the instruction block of the While command.
- In the Text input parameter, insert the value
${userName}, would you like to read about another subject?
. - In the Timeout input parameter, insert the value
00:02:00
. - In the Value output parameter, insert the variable
${endInteraction}
.
- In the Text input parameter, insert the value
After the End While command ends the instruction block of the While command, the bot sends the user a farewell message using the Bot Says command.
- Insert the Bot Says command after the End While command.
- In the Text input parameter, insert the value
Thank you for contacting us, see you soon!
.
- In the Text input parameter, insert the value
The Delay command is inserted in the script so that the Web Chat is open for a few seconds, during the execution of the script in debug mode, after the last interaction of the bot using the Bot Says command.
- Insert the Delay command in the script.
- In the Timeout input parameter, insert the value
00:00:05
.
- In the Timeout input parameter, insert the value
After performing all the steps in this tutorial, run the developed script.