Skip to main content

Combined JSON

Botium test cases can be composed in JSON format. However, they are not standalone. This means that they are not confined to one utterance, or one convo per file. One JSON can contain more convos/utterances, that is why they are 'combined'.

JSON Structure

JSON files use a key-value pair structure, where data is organized in objects ({}) and arrays ([]). Here, we will break down the components of a JSON file used for defining conversations in a bot.

Conversations

The convos array contains a list of conversations, each with a name, description, and steps detailing the interaction between the user (me) and the bot.
{
  "convos": [
    {
      "name": "goodbye",
      "description": "desc of convo goodbye",
      "steps": [
        {
          "begin": [
            { "logichook": "PAUSE", "args": "500" }
          ]
        },
        {
          "me": [
            "bye"
          ]
        },
        {
          "bot": [
            "goodbye!"
          ]
        }
      ]
    },
    {
      "name": "convo 1 name",
      "description": "desc of convo",
      "steps": [
        {
          "me": [
            "hi",
            "PAUSE 500"
          ]
        },
        {
          "bot": [
            { "asserter": "TEXT", "args": "hello", "not": true },
            { "asserter": "INTENT", "args": "intent_greeting" }
          ]
        },
        {
          "bot": [
            "what can i do for you?"
          ]
        },
        {
          "me": [
            "nothing"
          ]
        },
        {
          "bot": [
            "thanks"
          ]
        }
      ]
    }
  ]
}

Explanation:

  • convos: Array of conversations.
  • name: Unique identifier for the conversation.
  • description: Brief description of the conversation.
  • steps: Array of interactions within the conversation.
    • begin: Initial action, such as a pause.
    • me: User's input.
    • bot: Bot's response.

Utterances

The utterances object defines common phrases that the bot can recognize and respond to.
{
  "utterances": {
    "GREETING": [
      "hi",
      "hello!"
    ]
  }
}

Explanation:

  • utterances: Object containing keywords or phrases.
  • GREETING: Array of greetings that the bot can recognize.

Scripting Memory

The scriptingMemory array defines variables that can be used across different scenarios.
{
  "scriptingMemory": [
    {
      "header": {
        "name": "scenario1"
      },
      "values": {
        "$var1": "var1_1",
        "$var2": "var2_1"
      }
    },
    {
      "header": {
        "name": "scenario2"
      },
      "values": {
        "$var1": "var1_2",
        "$var2": "var2_2"
      }
    }
  ]
}

Explanation:

  • scriptingMemory: Array of memory headers and values.
  • header: Name of the scenario.
  • values: Object containing key-value pairs of variables.

Special Syntax

To denote specific types of content or assertions, JSON uses different notation methods:

  • Logical Hooks and Arguments: Represented as objects with logichook and args keys.
  • Asserter Objects: Include asserter, args, and an optional not key for negations.
    {
      "convos": [
        {
          "name": "quote",
          "steps": [
            {
              "me": [
                "Hello!"
              ]
            },
            {
              "bot": [
                { "asserter": "TEXT_CONTAINS_ANY", "args": "goodbye, bye", "not": true }
              ]
            }
          ]
        }
      ]
    }
    

Explanation:

  • Logical Hooks: "logichook": "PAUSE", "args": "500" indicates a pause of 500 milliseconds.
  • Asserter Objects: "asserter": "TEXT_CONTAINS_ANY", "args": "goodbye, bye", "not": true checks if the text does not contain any of the listed words.

Example Code

Here's a full example putting all the pieces together:
{
  "convos": [
    {
      "name": "goodbye",
      "description": "desc of convo goodbye",
      "steps": [
        {
          "begin": [
            { "logichook": "PAUSE", "args": "500" }
          ]
        },
        {
          "me": [
            "bye"
          ]
        },
        {
          "bot": [
            "goodbye!"
          ]
        }
      ]
    },
    {
      "name": "convo 1 name",
      "description": "desc of convo",
      "steps": [
        {
          "me": [
            "hi",
            "PAUSE 500"
          ]
        },
        {
          "bot": [
            { "asserter": "TEXT", "args": "hello", "not": true },
            { "asserter": "INTENT", "args": "intent_greeting" }
          ]
        },
        {
          "bot": [
            "what can i do for you?"
          ]
        },
        {
          "me": [
            "nothing"
          ]
        },
        {
          "bot": [
            "thanks"
          ]
        }
      ]
    }
  ],
  "utterances": {
    "GREETING": [
      "hi",
      "hello!"
    ]
  },
  "scriptingMemory": [
    {
      "header": {
        "name": "scenario1"
      },
      "values": {
        "$var1": "var1_1",
        "$var2": "var2_1"
      }
    },
    {
      "header": {
        "name": "scenario2"
      },
      "values": {
        "$var1": "var1_2",
        "$var2": "var2_2"
      }
    }
  ]
}

This example demonstrates how to structure a JSON file for bot conversations, including defining steps, utterances, and scripting memory with clear and easy-to-follow syntax.

Was this article helpful?

0 out of 0 found this helpful