Toolbelt

Learn about the different helper functions.

A toolbelt refers to a collection of various helpful functions that a bot can perform.

Khoros Flow provides a collection of built-in functions such as:

Pausing a bot

You can temporarily disable all automatic interaction for a certain amount of time (in minutes). The duration is set in the brain settings under Minutes to auto pause.

The below example pauses the bot for five minutes.

async payload => {
  // Disable the bot for a number of minutes
  // Check the brain settings
  toolbelt.pauseBot(5)
}

Handover

This function notifies that the conversation needs to be taken over by a human (Agent). This function sends a web push notification and places the interaction within “the_takeover required_list”. Depending on the connected integration, a conversation can transition into a different state.

async payload => {
  // Move the thread into a hand over state
  toolbelt.handover()
}

Resolve

When this toolbelt function is triggered, the conversation is marked as resolved.

async payload => {
  // Marks the conversation as resolved and ends the chat.
  toolbelt.resolve()
}

Send an email

You can use this toolbelt function to send an email notification. Khoros Flow supports two types of email notification types:

  • Takeover
  • Custom

Takeover

Use this type to send an email with the last 20 messages from a conversation to a specified recipient.

async payload => {
  // Send an e-mail about the last 20 messages to a recipient
  toolbelt.email({
    to: 'name@company.com',
    template: 'takeover',
    hideButton: true //Optional
  })
}

Custom

Use this template to send a custom email with a CC to a recipient.

async payload => {
  // Send an e-mail to notify a conversation needs to be taken over
  toolbelt.email({
    to: 'name@company.com',
    cc: 'name@company.com', //Optional
    subject: 'Email subject',
    message: 'Email message'
  })
}

Delay

To control the timing of an action, you can use the delay toolbelt function. For this, Khoros Flow provides a simple method that works similarly to the native setTimeout Javascript function.

📘

Max delay

The maximum delay is 10 seconds(1 second=1000 milliseconds)

async payload => {
  // Delay the code by 2 secs
  toolbelt.delay(() => {
    // Executes after the delay
    ...
  }, 2000)
}

Delay inside an async function by 2 seconds (2000 milliseconds)

async payload => {
  // Or delay inside a async function by 2 secs
  await toolbelt.delay(2000)

  // Executes after the delay
  ...
}

Unassigned interactions

With the cloud code, you can build complex handover scenarios. By using toolbelt.getUnassignedCount() you can request the number of unassigned interactions within the chat application.

async payload => {
  const count = await toolbelt.getUnassignedCount()
  if(count > 10) {
    return new Message('Sorry, we are very busy at the moment..')
  }
  return new Message('Someone will be there shortly..')
}

Interaction URL

You can get a link to any conversation within the takeover email.
Use toolbelt.getInteractionUrl() to request the conversation URL.

async payload => {
  const url = await toolbelt.getInteractionUrl()

  toolbelt.email({
    to: 'name@domain.com',
    subject: 'Check out the conversation',
    message: `This is the link ${url}`
  })
}

Tags

Tags are part of the user object within the payload. They can be added and removed using the flow designer and dynamically managed with code actions.
To add the tags, use the code below:

async payload => {
  await toolbelt.addTags({
    tags: [
      { tagName: 'EXAMPLE_TAG_ONE', tagValue: 'value 1' },
      { tagName: 'EXAMPLE_TAG_TWO', tagValue: 'value 2' }
    ],
    payload
  })
}

To remove tags, use the code below:

async payload => {
  await toolbelt.removeTags({
    tags: [
      'EXAMPLE_TAG_ONE',
      'EXAMPLE_TAG_TWO'
    ],
    payload
  })
}