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.
How a call goes
Section titled “How a call goes”- The caller asks (“book me for 3 tomorrow”). The assistant picks the action from its triggers and what was said.
- 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?”).
- 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.
- 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.
- 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.
The shape
Section titled “The shape”{ "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.
Inputs
Section titled “Inputs”| Field | Meaning |
|---|---|
key | snake_case; steps read it as {{input.<key>}} |
label, label_ne | what it is called, in English and Nepali |
type | text, number, money, date, time, phone, email, choice, boolean, url |
required | default true |
ask | how the assistant asks for it |
options | for choice |
default | caller_phone or today |
duration_minutes | for 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.
| Rule | Checks |
|---|---|
open_hours | the date and time fall inside the windows and not on a closed day; a window that closes before it opens runs past midnight |
lead_time | at least minutes from now |
horizon | at most days ahead |
not_past | not already gone |
per_caller | at most max runs by one number in hours |
per_caller_per_day | at most max runs by one number for the same date (no double booking of one person) |
range | a number or amount between min and max |
max_length | text 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.
kind | Does |
|---|---|
action | runs 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) |
script | runs your JavaScript (below) |
notify | sends a message: customer (their channel; SMS on a call), sms, whatsapp, or push to the team |
ask_customer | asks and waits for the answer |
staff_approval | waits for the team to approve |
wait_event | waits for a named event from your system |
branch | jumps on a value |
compensate | undoes 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.
Scripts
Section titled “Scripts”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 defaultan async function of(input, ctx). What it returns is the step’s result.ctx.http.fetchreaches only thehostsyou 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
GETrequests go out.
Lookups
Section titled “Lookups”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.
Verified callers
Section titled “Verified callers”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.
Trying it
Section titled “Trying it”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.