Skip to main content

Using the Scripting Memory

Scripting memory in Botium allows you to store and reuse variables and functions within conversations. This enables dynamic interactions and testing scenarios without hard coding values. Here, we will explore how to use scripting memory, set variables, and utilize built-in functions to enhance your chatbot testing.

Enabling Scripting Memory

To use scripting memory, ensure the SCRIPTING_ENABLE_MEMORY capability is set. This enables the bot to handle dynamic data like the current year or user names.

Steps:
  1. Navigate to Botium Tools & Settings > Test Sets > Configuration > Scripting
  2. Scroll down the page and toggle the Enable Scripting Memory switch


Scripting Memory Variables

You can store and reuse variables in Botium conversations. Here's a basic example:

Example: Store and Use Order Number
#bot
Your order number is $orderNum

#me
pls tell me the status for $orderNum

Variable Naming Rules

  • Variables start with a $.
  • Followed by a letter (lowercase or uppercase).
  • Can include any combination of letters and numbers.

Using Variables

Variables can be used in both user and bot messages. For instance, if a variable $username is set to "Joe":

Example: User Message
#me
my name is $username
Example: Bot Response Assertion
#bot
your name is $username

Setting Variables

You can set variables in the conversation script:

Example: Bot Response Setting a Variable
#me
what is your name?

#bot
my name is $botname.

#me
Hello $botname!

Using Variables from Files

Variables can be loaded from external files, allowing multiple conversation variations.

Example: Variables from File

$toEat $toDrink $costs
Two salami pizza Two cola 30
Cheeseburger nothing 8
Example: Using Variables in Conversation
#bot
Do you want to eat something?

#me
yes, $toEat please!

#bot
And some drink?

#me
$toDrink

#bot
It's $costs dollar.

Logic Hooks

Use logic hooks to set or clear variables dynamically.

Example: Setting Variables with Logic Hooks
#begin
SET_SCRIPTING_MEMORY name|joe

#bot
what is your name?

#me
$name

#bot
hello $name!
Example: Clearing Variables
#begin
CLEAR_SCRIPTING_MEMORY

Scripting Memory Functions

They are the pretty functions provided by botium, like current year ($year), or uniqid ($uniqid). Can be send to bot in #me sections, and can be used as asserters in #bot sections same way as variables.

Some of them can even used with parameters - for example $number(5) generates 5 digit long random number.

You can assert the response of the bot with functions:

Example: Current Year Function
#me
What is the current year?

#bot
$year
Or you can send them to bot:
#me
Current year is $year.
You can use parameters:
Example: Random Number Function
#me
Please call me $random(5).
You can use system environment variables:
#me
Please authenticate my token $env(MY_PERSONAL_TOKEN)
List of Functions
  • $env(MY_ENV_VAR): Reads sytem environment variables

  • $cap(MY_CAP): Reads Botium capabilities

  • $msg(JSONPATH): Reads something from the current Botium message with a JSONPath expression, for example: $msg($.messageText)

  • $projectname: Test Project Name

  • $testsessionname: Test Session Name

  • $testcasename: Test Case Name (Convo Name)

  • $date(<date pattern like hh:mm:ss or YYYY-MM-DD>): Pattern specific. You can use this to display date, and/or time.

  • $now: date and time. Local specific.

  • $now_ISO: date and time in ISO format. Example: “2019-04-13T19:27:31.882Z”

  • $now_EN: Example: “4/13/2019, 7:24:48 PM”

  • $now_DE: Example: “03.07.2019, 08:33:06”

  • $date: Locale specific.

  • $date_EN: Example: “4/13/2019”

  • $date_DE: Example: “03.07.2019”

  • $date_ISO: Example: “2019-4-13”

  • $time: Local specific.

  • $time_EN: Example: “7:44:11 PM”

  • $time_DE: Example: “08:33:06”

  • $time_ISO: Example: “19:45:12”

  • $time_HH_MM: Example: “19:45” or “01:01“

  • $time_HH: Example: “19” or “01“

  • $time_H_A: Example: “7 PM”

  • $timestamp: 13 digit long timestamp (in ms) like 1557386297267

  • $day_of_month: day of month. Example: “26” if the date is 2019-3-26

  • $day_of_week: day of week. Local specific. Example: “Monday”

  • $month: current month. Local specific. Example: “March”

  • $month_MM: current month. Local specific. Example: “03”

  • $year: Example: “2019”

  • $tomorrow(<date pattern like YYYY-MM-DD>): next day, formatted as given by the pattern (if omitted then locale specific)

  • $yesterday(<date pattern like YYYY-MM-DD>): next day, formatted as given by the pattern (if omitted then locale specific)

  • $date_add(amount, unit, pattern): adding to current date (see moment.js) and formatting. Example: $date_add(1, “day”, YYYY.MM.DD)

  • $date_subtract(amount, unit, pattern): subtracting from current date (see moment.js) and formatting. Example: $date_subtract(1, “month”, YYYY.MM.DD)

  • $random10: 10 digit long random number. Example: “6084037818”

  • $random(<length>): <length> digit long random number.

  • $uniqid: V1. Example: “2e65c580-4fb4-11e9-b543-bf076857f1d1”

Scripting Memory Files

You can reuse the same convo more times with Scripting Memory.

Example 1, 4 convos expanded, dynamic variations

Scripting memory for product:

        |$productName
product1|Bread
product2|Beer

Scripting memory for order number:

            |$orderNumber
orderNumber1|1
orderNumber2|100

Convo:

#me
Hi Bot, i want to order $orderNumber $productName
Example 2, 3 convos expanded, scripted variations

Scripting memory for order:

        |$productName|$orderNumber
order1  |Bread       |1
order1  |Beer        |1
order2  |Beer        |100

Convo:

#me
Hi Bot, i want to order $orderNumber $productName

Was this article helpful?

0 out of 0 found this helpful