Toolbelt

We provide a collection of builtin functions for doing stuff like sending notifications, emails or pauzing 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.

(function() {
  // Disable the bot for a number of minutes
  // Check the brain settings
  toolbelt.pauseBot()
})

Takeover

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.

Optionally you can specify a custom message to be send with the notification.

(function() {
  // Notify dashboard users to take over the conversation
  toolbelt.takeover()
})

Send an email

With this toolbelt function you can sent an email notification. We support 2 types of email templates.

Takeover

This templates sends you an email with the last 20 messages from the conversation.

(function() {
  // Send an e-mail to notify a conversation needs to be taken over
  toolbelt.email({
    to: '[email protected]',
    template: 'takeover'
  })
})

Custom

This templates allows you to customise an email.

(function() {
  // 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 of timing in Cloud code. 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)

(function() {
  // Delay the code by 2 secs
  toolbelt.delay(() => {
    // Executes after the delay
    ...
  }, 2000)
})
(async () {
  // 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 alo request this link using 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}`
  })
})