Skip to content

Connectors reference

A version is a tar of:

manifest.json required
index.js optional, for JavaScript actions
ui/ optional settings or panel pages
FieldTypeNotes
idstringReverse DNS, for example np.example.clinic. Fixed for the connector’s life.
versionstringSemver. Each upload needs a new version.
namestringShown to organizations.
authobjecttype is none, api_key, bearer, basic or oauth. For api_key, header or query names where the key goes, and prefix is put before it. The organization enters the secrets when installing.
secretsarrayOptional secrets beyond the ones auth names, such as a signing key: { name, title?, description? }. Names use letters, digits and _. The organization enters them when installing.
configJSON SchemaSettings the organization fills in when installing. Rendered as a form. A property’s default is used when the organization leaves it empty.
permissionsobjecthosts the connector may call (api.example.com, *.example.com, or {{config.base_url}} for the host the organization enters), and the AirFone data it may use: records:read, records:write, contacts:read, messages:send, knowledge:write.
actionsarraySee below.
knowledgearrayOptional sources the assistant can search, each backed by an action.
triggersarrayOptional inbound webhooks from the other system, mapped to AirFone events.
FieldNotes
nameUnique in the connector. Lowercase words joined by dots, like order.create.
descriptionShown to the assistant. Say when to use it and what it needs.
input, outputJSON Schema. Input is validated before the action runs, output after.
riskread, change or money.
confirmnone, caller or staff.
httpA declarative HTTP action.
jsThe name of an export in index.js. Defaults to name.
fixturesOptional test calls: { input, config?, expect? }. Review runs each one, with no network, and expect must be a subset of the output.
cache_secondsOptional, read actions only, up to 300. A successful result answers the same input again for that long, so a busy hour of the same stock or price question does not call your API each time. Any change or money action on the same connection clears it. Leave it out for actions that write to ctx.store.

An action has either http or js.

Declarative HTTP. method, url (a template with {{config.x}} and {{input.x}}), optional query, headers and body templates, and map, a JSONPath expression per output field. Secrets go in headers or query as {{secrets.name}}, never in the URL or body. errors maps status codes to messages the assistant can say. These run in the AirFone server with no JavaScript, so they are the fastest kind.

Templates:

  • {{input.channel ?? config.channel}} uses the first value that is present and not empty.
  • Filters follow a |: base64, urlencode, sha256 (hex), hmac_sha256(name) (hex) and hmac_sha256_b64(name) (base64). The HMAC filters sign with the install secret name and work anywhere, including the body. They can be chained, like {{input.x | sha256 | base64}}.
  • A body string that is exactly one {{...}} keeps its JSON type. If that value is absent, the field is left out of the body.

fail_when fails a successful response that reports an error in its body. Each rule has a JSONPath path. With equals, the rule fails when the first match equals it; without, when the path finds any non-null value. The message is message, else the value at message_path, else a generic one:

"fail_when": [{ "path": "$.ok", "equals": false, "message_path": "$.error" }]

A response sent as a server-sent event stream is read as the last data: event that holds JSON.

JavaScript. An async function (input, ctx) => output exported from index.js as actions.<name>. Use it for logins, chained calls or reshaping data.

Both kinds look the same to the assistant and to workflows.

risk says what the action can do. confirm says who must agree before it runs.

  • none: the assistant runs it when needed. Allowed for read only.
  • caller: the assistant reads the details back and runs it only after the customer says yes. The minimum for money.
  • staff: the action waits in AirFone’s approvals until a staff member approves. The customer is told they will hear back.

Organizations can make a rule stricter per action, never looser.

One conversation runs at most five writes on its own (change or money, built-in or connector). After that, writes go to staff approval, even if the action does not normally need it.

What an action returns is read to the customer as data, never as instructions: markup in it is neutralised.

When an action does part of what was asked (two items ordered, one out of stock), say so in the output: a non-empty failed list, or "status": "partial". The assistant then tells the customer exactly what was done and what was not, and offers to pass the rest to the team.

{ "status": "partial", "done": ["Notebook x2"], "failed": [{ "item": "Pen x10", "reason": "out of stock" }] }
MemberWhat it does
ctx.configThe organization’s settings, read only. Secrets are not included.
ctx.http.fetch(url, { method, headers, query, json, body })HTTP to a declared host. Credentials from auth are added by AirFone, and an Authorization header you set is dropped. Returns { status, ok, headers, json, text }, where json is the parsed body or null.
ctx.store.get(key), ctx.store.set(key, value), ctx.store.delete(key)A small key-value store per install. Keys up to 200 characters, values up to 64 KB. A { ttl } option is accepted but not applied yet.
ctx.store.set(key, value, { ifEquals })Sets the value only if the stored one is still ifEquals (null means absent). Returns true if it did.
ctx.store.incr(key, by)Adds by (default 1) in one step and returns the new number.
ctx.crypto.hmac(alg, secretName, message, encoding)An HMAC keyed with the install secret secretName. Your code gets the result, never the key.
ctx.crypto.sha256(message, encoding), ctx.crypto.hash(alg, message, encoding)A digest.
ctx.records.upsert(records)Adds or updates records on contacts. One record or an array. Needs records:write.
ctx.knowledge.upsert(records)Adds or updates what the assistant knows: products, prices, policies (the knowledge sync record shape). Up to 500 per call; each gets written, unchanged, stale or error. Needs knowledge:write.
ctx.knowledge.delete(externalId)Removes one of this connection’s knowledge records. Needs knowledge:write.
`ctx.log.infowarn

For ctx.crypto, alg is sha256 or sha512 and encoding is hex (the default) or base64. A {{secrets.name}} in message is replaced by that install secret before hashing, for APIs that sign a string containing the secret.

Calls on ctx finish before they return, so await is optional. Nothing else is available: no global fetch, no timers, no file system. Code at the top of index.js runs once when the bundle loads, without ctx, and must not do I/O. For Google Sheets, use the Google Sheets connector.

Each action call gets 64 MB of memory, 2 seconds of CPU and 10 seconds of wall time. Time spent waiting for HTTP counts toward wall time, not CPU. Each HTTP request may take 10 seconds and return 4 MB. Past any limit the call is stopped and the assistant tells the customer it could not finish. The bundle may be up to 5 MB, and index.js up to 1 MB.

ctx.http.fetch reaches only permissions.hosts, and never private or local addresses, even through DNS. AirFone data needs the matching permission. Permissions are enforced by the runtime, not only by review.

Every bundle is signed with your Ed25519 key over its id, version and sha256. airfone connector keygen creates the key. Register its public key once in the console under Connectors, Signing keys. AirFone verifies your signature and adds its own after review. Servers refuse a bundle unless both signatures and the content hash match.

  1. Upload a version: airfone connector publish, or airfone connector pack and sign, then upload the .tar and signature in the console.
  2. Automated review runs.
  3. If it passes, the version is approved. New connectors start private: you install them in your own organizations, and a human reviews before public listing.
  • The manifest matches the schema.
  • Hosts are declared and public.
  • Permission changes from the previous version are listed. Any new permission needs a human review.
  • The bundle is within size.
  • The code uses no banned APIs and contains nothing that looks like a secret.
  • index.js loads, and every fixture in manifest.json passes in the sandbox with no network, within the limits. Output must match the action’s output schema.

During review every secret has the value review.

airfone connector test runs the same checks on your machine.

  • A new minor or patch version reaches installs automatically, in stages, and rolls back if its error rate rises.
  • A new major version, or any new permission, waits until each organization’s admin approves it.
  • A running workflow keeps the version it started on.
  • AirFone can disable a version everywhere within seconds if it misbehaves.