Overview of Code Actions

Code actions, which are developed and implemented within the Flow platform, are essentially JavaScript code snippets that operate within a secure sandbox environment. This sandbox acts as a protective layer, ensuring that the code actions execute in isolation and cannot inadvertently affect the broader system or compromise data integrity.

The primary purpose of these code actions is to empower developers to customize and extend the functionalities of the Flow platform. By harnessing JavaScript's versatility, developers can craft code actions that precisely tailor Flow to their specific requirements and use cases. This flexibility unlocks a vast array of possibilities, enabling the creation of bespoke features, streamlined workflows, and enhanced user experiences.

For instance, a code action could be designed to automate repetitive tasks, integrate with external systems, or manipulate data in a unique way. The ability to create such targeted code actions significantly enhances the Flow platform's adaptability, making it a powerful tool for solving diverse business challenges and driving innovation.

📘

Limited execution time

Code execution or service calls in cloud code actions must be completed within 10 seconds.

Quick Examples of Code Actions

Khoros Flow provides some quick examples of code actions to perform the below task with the bot.

  • Sending text
  • Sending text with quick replies
  • Sending an email
  • Triggering a flow

Sending text

async payload => {
  const text = new Text(`This is a reply text from your bot.`)
  const message = new Message(`This is a reply text from your bot as a fallback text.`)

  message.addResponse(text)

  return message
}

Sending text with Quick replies

async payload => {
  const text = new Text(`This is a reply text from your bot.`)
  text.addQuickReply(new QuickReply({ label: 'Again', value: 'Get started' }))
  const message = new Message(`This is a reply text from your bot as a fallback text.`)

  message.addResponse(text)

  return message
}

Sending an email

async payload => {
  toolbelt.email({
    to: '[email protected]',
    subject: 'This is the subject of you email.',
    message: 'Compose the body of your email here.'
  })
}

Triggering a Flow

In Code, you can choose to respond directly with messages or initiate different flows.

async payload => {
  trigger('EVENT')
}