Set Up Script Actions

With script integrations, you can create custom script actions to use in bot responses in dialoguesClosed Bot stories and rules in CXone Bot Builder.. Creating script actions requires writing code in JavaScript. CXone Bot Builder scripts operate on the server, so there are some limitations to consider while building your scripts.

Create a Script Integration

A script integration holds one or more custom script actions. Each script action has its own script.

  1. In CXone, click the app selector and select Bot Builder.

  2. Click the bot you want to work with.
  3. Click Integrationsicon, which looks like a plug. in the left icon menu.
  4. Click the Scripts tab, then click New Integration.
  5. Click the title to rename the integration.
  6. Create script variables to use in this integration, if any are needed.
  7. Add one or more script actions to the integration. This is where you create your scripts. Any script action you create in this integration can reference the integration's script variables.
  8. When you're finished making changes, click Train and Stage to update your bot modelClosed Version of a bot that has been trained and staged to test this change.

Create a Script Action

Script actions can be added to bot responses in storiesClosed Used to train bot for interaction handling based on intent and context, rulesClosed Used to define bot's response to messages that don't change with context., and fallbackClosed A plain text alternative sent when the destination doesn't support rich media..

  1. In CXone, click the app selector and select Bot Builder.

  2. Click the bot you want to work with.
  3. Click Integrationsicon, which looks like a plug. in the left icon menu.
  4. On the Scripts tab, click the script integration you want to work with.
  5. Under Actions, click New Action.
  6. Enter a name for the action and press Enter.
  7. Click the new action to expand its properties.
  8. Click Open Editor to code your custom JavaScript:
    1. In the editor, replace the default Hello World code, but keep all new code within the main function. You can structure other functions within main if needed. Code outside of main will not be executed.
    2. Include script variables in your code as needed. Create the variables, if you haven't already done so.
    3. Click the execute script triangle A triangle arrow pointing to the right. in the toolbar at the top of the editor to see the output results of the script. The results appear in the Console pane on the right side of the editor.
  9. Click the open angle bracket An open angle bracket <. in the top left corner of the editor to return to the script integration page where the lists of actions and variables are.
  10. Click the action you're working with.
  11. In the Editable Variables drop-down, select any script variables that you referenced in your code.
  12. Enable your action when it's ready to test.
  13. Add your action to a story, rule, or fallback to test it.
  14. When you're finished making changes, click Train and Stage to update your bot modelClosed Version of a bot that has been trained and staged to test this change.

  15. Carry out the necessary testing. For example, you can chat with your bot. If necessary, make adjustments to your script ang, train and stage, and test again.

Create Script Variables

The variables you create can only be used in the script integration where you create them. They cannot be used in other script integrations, even in the same bot.

  1. In CXone, click the app selector and select Bot Builder.

  2. Click the bot you want to work with.
  3. Click Integrationsicon, which looks like a plug. in the left icon menu.
  4. On the Scripts tab, click the script integration you want to work with.
  5. Under Variables, click New Action.
  6. Enter a name and press Enter.
  7. Click the variable in the list to expand its properties.
  8. To create a single-value variable that can be made editable in a script action: 
    1. Click Text or Number.
    2. Enter the Default Value for this variable. If you don't want the variable to have a default value, leave this field empty. You can update the variable value when it's used in a script action.
    3. For number variables only, enter a Min Value and a Max Value to provider upper and lower limits on the values the variable can hold.
  9. To create a read-only, single-value variable:
    1. Click Secret.
    2. Enter the Value. Bot Builder masks all but the first five characters of the value you enter. The value is fully visible if you view the contents of a variable in the console.
  10. To create a list of possible values for this variable:
    1. Click Select.
    2. Enter the possible variable Values separated with a comma ( , ). For example, red,blue,green.
    3. Click Default Value and select the value you want to be the default.
    4. To remove the default value, hover the cursor over the field and click X.
  11. Use your variable in a custom script.
  12. When you're finished making changes, click Train and Stage to update your bot modelClosed Version of a bot that has been trained and staged to test this change.

Make Variables Editable

You can make a variable editable in a script if you want to be able to specify or select a value for that variable when you use that action in a bot response. If you use a variable in more than one action in a script integration, you must make it editable in each action. Additionally, the variable must be referenced in a script before you can make it editable in that script.

  1. In CXone, click the app selector and select Bot Builder.

  2. Click the bot you want to work with.
  3. Click Integrationsicon, which looks like a plug. in the left icon menu.
  4. On the Scripts tab, click the script integration you want to work with.
  5. Under Actions, click an action on the script integration page to expand its properties.
  6. Select one or more variables in the Editable Variables drop-down. Secret variables do not appear in this list. They cannot be made editable. Changes are saved automatically.
  7. Specify the value of the variable when you use the selected custom action in a story, rule, or fallback.
  8. When you're finished making changes, click Train and Stage to update your bot modelClosed Version of a bot that has been trained and staged to test this change.

Enable a Script Action

When a script action is ready to be used in a bot response, you must enable it. Actions that aren't enabled won't show up in the script actions list when you're working in a dialogueClosed Bot stories and rules in CXone Bot Builder..

  1. In CXone, click the app selector and select Bot Builder.

  2. Click the bot you want to work with.
  3. Click Integrationsicon, which looks like a plug. in the left icon menu.
  4. On the Scripts tab, click the script integration you want to work with.
  5. Under Actions, click an action on the script integration page to expand its properties.
  6. Click Disabled Icon of a toggle switch. to enable the action. Click it again to disable the action and remove it from the Scripts tab on the bot action menu.