Scripts
User can write custom code in JavaScript to fetch HTTP APIs, execute custom logic, return output data and outcome. Other nodes can access and make decisions on output/outcome.
Features
Access input: customer phone number, session vars.
Produce output
dataJSON andoutcomestring.Save
data(optional with JSON Path to access any fields) to session variables.Fetch HTTP API and parse its response.
Example script code:
UPPERCASE, userName are placeholders
// 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'];
}Parameter: input
UPPERCASE are placeholders
Parameter: config
UPPERCASE are placeholders
Return: [data, outcome]
must return in format
[data, outcome]other formats may be partially supported: only data, only outcome, etc.
outcome: must be a string
each possible outcome will be mapped to an edge
there is no default outcome nor fallback outcome for v1
output: must be a json object
no other requirement
Mapping data and outcome
data and outcomeUPPERCASE are placeholders
raw_param
session variable
outcome
β VARX
data
β VAR1
data.FOO.1
β VAR_FOO1
Last updated