Bot Session State Snippet

This snippet is for use with actions that have the botSessionState property, such as Textbot Exchange and Voicebot Exchange (from here on, both actions are referred to simply as Exchange). The botSessionState property must be configured properly for your virtual agentsClosed A software application that handles customer interactions in place of a live human agent. to work as expected.

The virtual agent provider assigns a unique identifier to each conversation between a contact and a virtual agent. The identifier prevents a new session from being created for every turn in the conversation. The provider creates the identifier when the conversation begins and passes it to the script with the first response. The script stores the identifier in the variable named in the botSessionStateVarName (out) property of the Exchange action. It then passes the identifier to the botSessionState property.

Your script must be set up correctly to use the bot session state identifier. When you use an Exchange action, a minimum of two instances of the action are required in your script. The botSessionState property in the Exchange actions must be configured differently:

  • The first Exchange action is located right after the Begin action at the start of the script. In this instance of the action, the botSessionState property must be left empty. The botSessionStateVarName (out) property must be configured with the name of the variable where you want the script to store the identifier.
  • The second Exchange action is located later in the script. In this instance of the action, the botSessionState property must be configured with the variable used in botSessionState. The variable must hold the bot session state identifier in JSON format. The botSessionStateVarName (out) property must be configured with the name of the variable where you want the script to store the identifier. If your script has three or more Exchange actions, all but the first one should be configured this way.

This configuration is required for all virtual agents.

Convert Bot Session State Identifier to JSON

The contents of the variable used in the botSessionStateVarName (out) property must be converted into JSON and passed into the botSessionState property of the second Exchange action in your script. To do this, you can include code in a Snippet action or you can configure the property directly. Both approaches are acceptable. However, the benefit of creating a variable in a Snippet to hold the converted object is that it makes it easier to see where the conversion is happening.

Use a Snippet Action

  1. Configure the botSessionStateVarName (out) property of the Exchange action with the name of the variable to hold the session state identifier. For example, botSessionState.
  2. Add the following line to a Snippet located before the Exchange action in your script:

    ASSIGN botSessionStateOut = botSessionStateOut.asJSON()

    Use the name of the variable you use in your script.

  3. Configure the botSessionState property in the Exchange action with the name of the variable you used in the ASSIGN statement. For example, botSessionStateOut.

Convert in the Property

If you convert the variable in the botSessionState property, use the botSessionStateVarName (out) variable with the asJSON()function. For example:

  • botSessionStateVarName (out)botSessionState
  • botSessionState: botSessionState.asJSON()