This guide explains how to set up a logic hook in Botium to assign or update a scripting variable using a JSONPath expression extracted from the message content.
This logic hook sets or overwrites a variable from message content using a JSONPath
Expression. It can be used only as a Bot Step.
Warning: Use this logic hook with care. If placed before the bot message, it will cause an
error during testing.
Note:
- On the left navigation pane, head to
Botium Tools & Settings > Test Sets > Your Test Set > Test Cases
- Click the + NEW button to add a new Convo, or select a previously created test case from the list.
- Add a new + BOT STEP
- Click the Edit icon, or anywhere inside the step, and search the
list for the 'Assign Scripting Variable' logic hook.
-
Configure the Logic Hook:
- Variable Name: Specify the name of the variable. Usually, start the variable name without "$". Use "$" only if you need logic hook argument replacement.
-
JSONPath Expression: Enter the JSONPath expression to
extract the desired content from the message.
- Click the APPLY CHANGES button to complete the step entry.
Example Convo:
Note:
Example Botium Script:
Extract a variable from a card:
#me
get invoice details for customer number 435643
#bot
CARDS INVOICE NUMBER
ASSIGN_SCRIPTING_MEMORY invoiceNumber|$.cards[0].content
Use the extracted variable in the next conversation
step:
#me
get invoice due date for invoice number $invoiceNumber
#bot
invoice due date for invoice number $invoiceNumber is 02/12/2020
Explanation:
-
ASSIGN_SCRIPTING_MEMORY invoiceNumber|$.cards[0].content
assigns the value extracted by the JSONPath expression$.cards[0].content
to the variableinvoiceNumber
. - In the next step, the variable
$invoiceNumber
is used to request further information.