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:

Procedure

Defining the bot language

Start the digital assistant script development with the definition of the bot's language, also referred to as culture:

  1. Open a new blank script.
  2. Insert the Create a Language command in the script.
  3. Fill in the following parameters:
    1. In the Culture input parameter, select the option en-US.
    2. In the Culture output parameter, insert the value cultureEnUS.

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.

  1. Insert the Connect to Chatbot command in the script.
  2. Fill in the following parameters:
    1. In the Communication type input parameter, select the option Chat.
    2. In the Language input parameter, insert the ${cultureEnUS} output variable returned by the Create a Language command.
    3. In the Timeout input parameter, insert the value 00:05:00.

The Disconnect Chatbot command is automatically inserted after defining and saving the Connect to Chatbot command.

  1. 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:

  1. Insert the Bot Ask Name command inside the instruction block of the Connect to Chatbot and Disconnect Chatbot command.
    1. In the Text input parameter, insert the value Hello, my name is Sofia, and I will be your virtual assistant. What is your name?.
    2. In the Timeout input parameter, insert the value 00:02:00.
    3. In the First output parameter, insert the value userName.

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.

Note:If necessary, go to the resources section of this tutorial to view the card table structure and data.
  1. Insert the Open Excel File command in the script.
    1. In the File input parameter, search for the directory where the spreadsheet with the extension .xlsx is stored.
    2. In the File output parameter, insert the value excelInstance.
  2. Insert the Get Excel Table command in the script.
    1. In the File input parameter, insert the ${excelInstance} variable returned in the Open Excel File command.
    2. Enable the Use first spreadsheet input parameter.
    3. Enable the Get the entire table input parameter.
    4. Enable the Contains headers input parameter.
    5. In the Table output parameter, insert the value dataTable.

Mapping the data table to cards

After you get the data table, map your data to cards:

  1. Insert the Map Table to Cards command in the script.
    1. In the Table input parameter, insert the variable ${dataTable}, returned in the Get Excel Table command.
    2. In the Title column input parameter, insert the value 1.
    3. In the Subtitle column input parameter, insert the value 2.
    4. In the Text column input parameter, insert the value 3.
    5. In the Column URL input parameter, insert the value 4.
    6. In the Action column input parameter, insert the value 5.
    7. In the Action value column input parameter, insert the value 6.
    8. In the Cards output parameter, insert the value cards.
  2. Insert the Map Table to Card Buttons command in the script.
    1. In the Table input parameter, insert the ${dataTable} variable returned in the Get Excel Table command.
    2. In the Cards input parameter, insert the ${cards} variable returned in the Map Table to Cards command.
    3. In the Column with button action input parameter, insert the value 7.
    4. In the Column with button text input parameter, insert the value 8.
    5. In the Column with button value input parameter, insert the value 9.

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.

  1. On the Home page tab, click the New variable button to define a new variable.
    1. In the Name input parameter, insert the value endInteraction.
    2. In the Variable type input parameter, select the option Boolean.
  2. Insert the Set Variable command in the script.
    1. In the Variable input parameter, insert the variable ${endInteraction} declared in the previous step.
    2. In the Value input parameter, insert the value True.
  3. Insert the While command in the script.
    1. In the Left operator input parameter, insert the variable ${endInteraction}.
    2. In the Operator input parameter, select the option Is true.

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:

  1. Insert the Bot Ask Carousel command inside the instruction block of the While command.
    1. 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!.
    2. In the Cards input parameter, insert the $ {cards} variable.
    3. In the Timeout input parameter, insert the value 00:02:00.
    4. In the Value output parameter, insert the value userResponse.

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:

  1. Insert the Bot Ask Boolean command still inside the instruction block of the While command.
    1. In the Text input parameter, insert the value ${userName}, would you like to read about another subject?.
    2. In the Timeout input parameter, insert the value 00:02:00.
    3. In the Value output parameter, insert the variable ${endInteraction}.

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.

  1. Insert the Bot Says command after the End While command.
    1. In the Text input parameter, insert the value Thank you for contacting us, see you soon!.

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.

  1. Insert the Delay command in the script.
    1. In the Timeout input parameter, insert the value 00:00:05.

After performing all the steps in this tutorial, run the developed script.