Webhook and Custom Code steps for developers

What a Ladoo workflow's Webhook step sends to your server during a call and what it expects back, and how Custom Code steps run, with their limits and how to test both.

By the Ladoo team · Updated

Two workflow steps run your logic while the caller is on the line. A Webhook step calls your own server, and a Custom code step runs a short JavaScript function inside Ladoo. This page is the technical detail behind them. For setting them up in the editor, see Webhook step and Custom code step.

Both run during a live call, so keep them fast. A caller hears silence, or the step's Say while waiting line, until they finish.

Webhook steps

What Ladoo sends

When a call reaches a Webhook step, Ladoo fills in the step's placeholders and sends one request:

POST /jobs/lookup HTTP/1.1
Host: api.riveraplumbing.test
User-Agent: Ladoo-Workflows/1.0
Accept: application/json
Content-Type: application/json
Ladoo-Call-Id: c2a1e9b8-4f3d-4a2c-9b1e-8d7c6b5a4f3e
Authorization: Bearer your-key

{"phone": "+15555550142", "address": "2210 Kelly Ln, Pflugerville, TX 78660"}
  • Method: GET, POST, PUT or PATCH. GET sends no body.
  • Address: https:// only, on port 443, to a public address. Ladoo refuses private and local network addresses, and checks the address again when it connects. Placeholders can go in the path and query, and their values are URL-encoded.
  • Headers: the ones you add to the step, plus User-Agent, Accept and Ladoo-Call-Id, the id of the call (the same id as GET /v1/calls/{id} and webhook events). Content-Type is application/json unless you set your own.
  • Body: the step's JSON template with its placeholders filled in. A string that's exactly one placeholder, like "{{fields.guests}}", takes the value's own type, so a number stays a number. Placeholders with no value become empty.

Webhook steps aren't signed. To be sure a request is from your workflow, add a header with a secret only you and the step know, like Authorization: Bearer …, and check it on your server. Header values are hidden in the editor once saved and are left out when the workflow is exported. To use one key in many steps, store it as a workspace secret and write Bearer {{secrets.NAME}}.

Placeholders

PlaceholderFilled in with
{{fields.<key>}}A detail collected on this call, like {{fields.service_address}}.
{{variables.<name>}}, or {{<name>}}A business setting, or a value an earlier step saved.
{caller_name}, {caller_first_name}, {caller_phone}The caller, when Ladoo knows them. The phone is in E.164, like +15555550142.

What your server answers

  • Answer within 8 seconds, with a body of at most 256 KB. Slower or larger counts as a failure.
  • Any 2xx status is a success. Anything else, a timeout, a refused connection or a redirect (Ladoo doesn't follow them) is a failure, and the call goes to the step's If it fails branch. Ladoo doesn't retry: the caller is waiting.
  • To use values from the reply, answer with JSON and list them under Save from the reply. Each has a name and a dot path, like job.technician.first_name. Use a number for a list item: jobs.0.status.
  • Strings, numbers and true/false are saved as they are. Objects and lists are saved as JSON text. Text is cut at 500 characters. A path that isn't in the reply, or is null, saves nothing.
  • Saved values are available to later steps as {{variables.<name>}}, and a Condition can check them. They can't reuse a business setting's name, or names starting with caller_.

A server for the example

A Webhook step that looks up a caller's next appointment, with the reply it expects:

import http from "node:http";

http
  .createServer(async (req, res) => {
    if (req.headers.authorization !== `Bearer ${process.env.STEP_SECRET}`) {
      res.writeHead(401).end();
      return;
    }
    const chunks = [];
    for await (const chunk of req) chunks.push(chunk);
    const { phone } = JSON.parse(Buffer.concat(chunks).toString("utf8"));
    const job = await findNextJob(phone); // your own lookup
    res.writeHead(200, { "Content-Type": "application/json" });
    res.end(
      JSON.stringify({
        job: job
          ? { status: job.status, window: job.window, technician: { first_name: job.tech } }
          : null,
      }),
    );
  })
  .listen(3000);

Save job.status, job.window and job.technician.first_name. When there's no job, nothing is saved, and a Condition can check whether job_status exists.

Custom Code steps

A Custom code step runs the body of this function, which you write:

function run({ fields, variables, caller, now }) {
  // your code
  return { trip_fee: 49 };
}
NameWhat it is
fieldsThe details collected so far, by key.
variablesThe business settings, plus values earlier steps saved.
callerphone, name, first_name and email, or null when Ladoo doesn't know the caller.
nowThe time of the call, as an ISO 8601 string in UTC.

It must return an object. List each key you want to keep under Values it returns (the step's outputs); later steps use them as {{variables.<name>}}. Other keys are dropped. Each value must be a string, number, true, false or null.

Where it runs

The code runs in a sandbox: a JavaScript engine compiled to WebAssembly, with a fresh copy for every run. It has the language's built-ins, like Math, JSON, Date and RegExp, and nothing else: no network, no files, no timers and no console. To reach another system, use a Webhook step.

LimitValue
Code size16 KB
Time for one run200 ms
Memory16 MB
What it's given64 KB
What it returns8 KB
Values it returns20

If the code throws, runs too long, uses too much memory or returns something that isn't an object, the call goes to the step's If the code fails branch.

Test it

POST /v1/agents/{id}/workflow/code/test runs code in the same sandbox a call uses, with sample answers and the agent's business settings, and saves nothing. It needs agents:write and can be called 30 times a minute.

curl https://api.tryladoo.com/v1/agents/AGENT_ID/workflow/code/test \
  -H "Authorization: Bearer $LADOO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "code": "const zip = String(fields.service_address || \"\").match(/\\b\\d{5}\\b/)?.[0];\nreturn { trip_fee: zip === \"78701\" ? 0 : 49 };",
    "outputs": ["trip_fee"],
    "input": { "fields": { "service_address": "2210 Kelly Ln, Pflugerville, TX 78660" } }
  }'
{ "ok": true, "outputs": { "trip_fee": 49 }, "ignored": [], "ms": 4 }

When it fails, ok is false, reason says why (syntax, timeout, memory, error, not_object, bad_value and so on) and error explains it.

Related guides: Pre-call webhook: look up the caller before the agent answers, Agencies: client workspaces through the API and MCP servers: connect a server's tools to your agent.

Still stuck?

Ask our support agent (it runs on Ladoo), or email the team.

Email support

Choose which cookies Ladoo can use on tryladoo.com and the dashboard. You can change this any time from the footer.

Essential

Keep you signed in, protect sign-in and save this choice. The site can’t work without them.

Always on
Read the cookie policy