Skip to main content
The Scripts feature lets you embed custom JavaScript directly into your campaign flows in the Campaign Builder. Use scripts to call external HTTP APIs, apply business logic, and write data back to session variables that other nodes in the flow can consume.

What scripts can do

  • Access the current customer’s phone number and session variables as input
  • Fetch any external HTTP API and parse the response
  • Return structured output data and an outcome string
  • Map output fields to session variables for use in downstream nodes

Script structure

Every script exports a single onExecute function:
// name=SCRIPT_NODE1
export async function onExecute(input, config) {
  console.log('hello from script node!');

  const resp = await fetch('https://jsonplaceholder.typicode.com/users/1');
  const body = await resp.json();

  // return [data, outcome]
  return [{ FIELD1: 'one', FIELD2: 42, userName: body.name }, 'OUTCOME2'];
}

Parameters

input

Contains the current session context and output from previous script nodes:
{
  "sessionContext": {
    "business": { "id": "..." },
    "customer": { "phoneNumber": "..." },
    "variables": { "VAR1": "1" }
  },
  "SCRIPT_NODE1": {
    "outcome": "...",
    "data": { "FIELD1": "one" }
  }
}
FieldDescription
sessionContext.business.idYour Connectly business ID.
sessionContext.customer.phoneNumberThe current customer’s phone number.
sessionContext.variablesAll session variables set so far in the flow.
SCRIPT_NODE1.outcomeThe outcome returned by a previous script node named SCRIPT_NODE1.
SCRIPT_NODE1.dataThe data object returned by a previous script node.

config

Contains secrets configured for the script node:
{
  "secrets": { "SECRET1": "value" }
}

Return value

Scripts must return a tuple [data, outcome]:
return [{ FIELD1: 'one', FIELD2: 42 }, 'OUTCOME2']
Return valueTypeDescription
dataobjectJSON object β€” any fields you want to save to session variables.
outcomestringA string that maps to an outgoing edge in the flow. Each possible outcome must be configured as an edge in the Campaign Builder. There is no default or fallback outcome.

Mapping output to session variables

After a script node runs, you can map its output fields to session variables for use by downstream nodes:
Raw paramMaps to session variable
outcomeAny variable you configure (e.g. VARX)
dataAny variable (receives the whole data object)
data.FOO.1A specific nested field (e.g. VAR_FOO1)