Skip to content

Actions

An action is something a caller can ask the assistant to do: book a time, move or cancel a booking, take a complaint, add a lead, check an order. The assistant collects the details, your rules check them, the caller confirms, and the steps run in your systems or in AirFone Books. The caller hears what really happened.

You can start from a ready-made action in the console (Channels, Actions, New action) and change it, or write one as JSON.

  1. The caller asks (“book me for 3 tomorrow”). The assistant picks the action from its triggers and what was said.
  2. It passes what it heard. AirFone checks each detail and answers what is missing or wrong, with choices to offer (“We open at 10. Did you mean 3 pm?”).
  3. Before anything changes, it reads the details back. Nothing runs until the caller says yes. In chat the confirmation is a message the customer replies to.
  4. The steps run. A quick action is answered in the same turn. A slow one is finished in the background and the caller gets a text with the real result.
  5. If it fails, the team gets a task with everything collected, and the caller is told so.

The same request twice (a retry, a dropped line) runs once.

{
"triggers": ["book", "appointment", "बुक"],
"inputs": [
{"key": "resource", "label": "With", "type": "text", "ask": "Who would you like to see?"},
{"key": "date", "label": "Day", "type": "date"},
{"key": "time", "label": "Time", "type": "time", "duration_minutes": 30},
{"key": "name", "label": "Name", "type": "text"},
{"key": "phone", "label": "Phone", "type": "phone", "default": "caller_phone"}
],
"rules": [
{"rule": "open_hours", "date": "date", "time": "time",
"hours": [{"days": ["sun","mon","tue","wed","thu","fri"], "opens": "10:00", "closes": "17:00"}],
"closed": ["2083-07-03"]},
{"rule": "lead_time", "date": "date", "time": "time", "minutes": 60},
{"rule": "per_caller", "max": 3, "hours": 24}
],
"read_back": "{{input.resource}} on {{input.date}} at {{input.time}} for {{input.name}}",
"replies": {"done": "You're booked for {{input.date_text}} at {{input.time_text}}."},
"steps": [ ... ]
}

Save it as a workflow (POST /api/workflows with name, description, definition). A definition without inputs or rules is a plain workflow.

FieldMeaning
keysnake_case; steps read it as {{input.<key>}}
label, label_newhat it is called, in English and Nepali
typetext, number, money, date, time, phone, email, choice, boolean, url
requireddefault true
askhow the assistant asks for it
optionsfor choice
defaultcaller_phone or today
duration_minutesfor a time: gives {{input.<key>_end_at}}

What callers say is understood in English and Nepali: “tomorrow”, “भोलि”, “Tuesday”, “२०८३-०६-२७” or “साउन १५” (BS), “3 pm”, “बिहान ९”, “राति ८”, Nepali digits, “रु. १,५००”.

After checking, steps also get:

  • {{input.<time>_at}}: the moment as RFC 3339 in Nepal time, when a date and a time are both known;
  • {{input.<key>_text}}: dates, times, money and yes/no as a person says them (“Tuesday 13 October (२७ असोज २०८३)”, “3 pm”).

A bare “3” is settled by your rules: at a clinic open 10 to 5 it is 3 pm. When the rules allow both, the assistant asks.

RuleChecks
open_hoursthe date and time fall inside the windows and not on a closed day; a window that closes before it opens runs past midnight
lead_timeat least minutes from now
horizonat most days ahead
not_pastnot already gone
per_callerat most max runs by one number in hours
per_caller_per_dayat most max runs by one number for the same date (no double booking of one person)
rangea number or amount between min and max
max_lengthtext at most max characters

For eligibility, add a number input (an age, an amount) with a range rule, or check it in a script step.

Rules run in code before anything happens, whatever the caller or the model says. A broken rule gives the caller a reason and, where it can, alternatives.

kindDoes
actionruns a connector action, or AirFone Books with the AirFone install id (books.booking_hold, books.booking_confirm, books.booking_cancel, books.booking_find, books.order_place)
scriptruns your JavaScript (below)
notifysends a message: customer (their channel; SMS on a call), sms, whatsapp, or push to the team
ask_customerasks and waits for the answer
staff_approvalwaits for the team to approve
wait_eventwaits for a named event from your system
branchjumps on a value
compensateundoes earlier steps that have an undo

Inputs to steps use {{input.x}} and {{steps.<key>.<field>}}. An action step with compensate is undone if a later step fails, so a held slot is released and an order cancelled.

A script step runs your own code in AirFone’s sandbox:

{"key": "status", "kind": "script", "hosts": ["api.yourshop.com"],
"input": {"order": "{{input.order}}"},
"source": "export default async (input, ctx) => {\n const r = await ctx.http.fetch(`https://api.yourshop.com/orders/${input.order}`);\n if (r.status >= 500) throw new Error('retry: busy');\n return await r.json();\n};"}
  • export default an async function of (input, ctx). What it returns is the step’s result.
  • ctx.http.fetch reaches only the hosts you list, over HTTPS, at public addresses, without following redirects, with a time and size limit.
  • Throw to fail the step. A failure from the system you called is retried; a mistake in the script is not.
  • Time and memory are limited. A script that loops forever is stopped.
  • In a test run, only GET requests go out.

Set "mode": "lookup" for actions that only read, such as an order’s status. They run without a read-back and the assistant tells the caller what came back.

Set "verified_caller": true when the action touches the caller’s own records, such as cancelling their booking. It runs only for a caller proven to be who the details say.

POST /api/actions/check with a definition and inputs shows what the assistant would ask or read back. POST /api/actions/{id}/test runs every step without writing anywhere and shows each step’s result and the reply. The console’s Try it panel does both.