We provide a collection of builtin functions for doing stuff like sending notifications, emails or pausing a bot.

Pausing a bot

You can temporarily disable all automatic interaction for a number of minutes. The duration is configured within the brain settings Minutes to auto pause.

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

Handover

Notify that the conversation needs to be taken over by a human. This will send a web push notification and place the interaction within the_take over required_list. Depending on the connected integration a conversation is moved into a different state.

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

Resolve

Mark a conversation as resolved.

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

Send an email

With this toolbelt function, you can send an email notification. We support two types of email templates.

Takeover

This template sends an email with the last 20 messages from the conversation to a specified recipient.

async payload => {
  // Send an e-mail to notify a conversation needs to be taken over
  toolbelt.email({
    to: '[email protected]',
    template: 'takeover',
    hideButton: true //Optional
  })
}

Custom

This template allows you to customize an email.

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

Delay

Sometimes you need more control over the timing of an Action. For that, we provide a simple method that works similar to the native setTimeout JavaScript function.

📘

Max delay

The maximum delay is 10 seconds(10000)

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

  // Executes after the delay
  ...
}

Unassigned interactions

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

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

Interaction URL

Within the takeover email, you'll get a link to any conversation. You can also request this link using the toolbelt.getInteractionUrl().

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

  toolbelt.email({
    to: '[email protected]',
    subject: 'Check out the conversation',
    message: `This is the link ${url}`
  })
}

Tags

Tags are part of the user object within the payload (cross link). They can be set and removed using the flow designer, but it's possible to dynamically add and remove tags using code Actions.

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

Removing tags:

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