@fonoster/sdk manages a workspace from Node.js or the browser: applications, numbers, trunks,
SIP agents, calls, call records, webhooks, providers and keys. It wraps Fonoster’s
gRPC API. To answer calls with your own code, use the
Voice SDK instead.
Install
Create a client and sign in
Create a client with your workspace’s access key ID, then sign in with an API key:accessKeyId selects the workspace: every request goes to the workspace whose access
key ID starts with WO. The API key ID (AP…) and its secret prove who you are. See
API keys and access for where to find each value.
Client options (Node.js)
The workspace’s access key ID (
WO and 32 characters). Every request acts on
this workspace.The gRPC endpoint, as
host or host:port. Set it to your install’s address
when you self-host.A PEM file of certificate authorities to trust besides your system’s, such as
an install’s generated
config/tls/ca.pem. Used for gRPC and the HTTP routes.
Host names are still checked. A missing file fails when the client is created.Connect without TLS. Only for plain connections inside a private network, such
as one service calling another. To reach an install over HTTPS with its
generated certificate, use
caFile.The base URL of the HTTP routes (call records and regions). Default
https://
plus the endpoint’s host, without the port.WebClient options (browser)
The browser build exports WebClient instead of Client. It takes url (default
https://api.fonoster.ai) and accessKeyId, and has the same sign-in methods.
Sign-in and session methods
These are methods ofClient and WebClient. Each sign-in method stores the tokens on the client;
the client renews the access token before a request when it has expired.
Conventions
- Every method returns a promise. A rejected gRPC call rejects with the gRPC error.
- Refs are UUIDs, such as
3f8b2c71-9d4e-4a6b-8c25-7e1f0a9b4d62.create*,update*anddelete*methods resolve to{ ref }unless noted. - List methods take
{ pageSize, pageToken }and resolve to{ items, nextPageToken }. PassnextPageTokenback aspageTokento get the next page. - Dates are
Dateobjects unless noted. CallRecordsandRegionsuse HTTP. They reject withCallRecordsErrororRegionsError, which carrystatus(the HTTP status) andcode(the error code from the body).
Applications
An application is a stream (STREAM) or an Autopilot agent (AUTOPILOT).
new SDK.Applications(client).
Enum values such as ApplicationType, Privacy and Role are exported from @fonoster/sdk (for example
SDK.ApplicationType.AUTOPILOT); in TypeScript, use them instead of plain strings.
The request for
createApplication:
A stream runs your WebSocket server. An Autopilot agent runs on Fonoster.
The stream’s wire protocol: the session protocol or
Twilio Media Streams.
Listen-only WebSockets:
{ url, tracks: "inbound" | "outbound" | "both" }. Up to 4 are dialed.Records the application’s calls when
on. Empty is off. See Record calls.Answering-machine detection:
{ enabled, windowMs }. windowMs defaults to 4000 (500 to
15000). Off when unset. See Answering-machine detection.Autopilot agents:
{ config }, the agent’s configuration. See
Autopilot configuration.Application has the same fields, plus ref, signingSecretHint (the secret’s last
characters), createdAt and updatedAt.
Numbers
Phone numbers and where their calls go.new SDK.Numbers(client).
telUrl, city, country and countryIsoCode can’t change after creation.
The Twilio credentials and the Meta access token are used for this request and not stored. Without
a Meta token, Fonoster calls no Meta API: you register the returned SIP server in WhatsApp Manager,
set SRTP to SDES and paste the SIP password Meta issued.
Trunks
SIP connections to your carriers.new SDK.Trunks(client).
Each entry in
uris is the carrier’s address for outbound calls: { host, port, transport, user, weight, priority, enabled }. transport is one of UDP, TCP, TLS, SCTP, WS, WSS.
Domains
SIP domains that SIP agents register to.new SDK.Domains(client).
domainUri can’t change after creation. Names are one label under your install’s roots:
<label>.sip.<domain> for a domain and <label>.pstn.<domain> for a trunk’s inboundUri
(self-hosted installs can allow any host).
Agents (SIP agents)
SIP endpoints, such as softphones, that register to a domain. The class isAgents; the docs call
them SIP agents. new SDK.Agents(client).
Credentials
Usernames and passwords for SIP agents and trunks.new SDK.Credentials(client).
Acls
Access control lists of IP addresses and networks.new SDK.Acls(client).
Calls
Start outbound calls and read call history.new SDK.Calls(client).
statusStream is an async iterator of { status } while the call is dialed. status is one of
TRYING, PROGRESS, ANSWER, BUSY, CANCEL, FAILED or ERROR (no answer).
metadata reaches the application in session.start.
A CallDetailRecord has ref, accessKeyId, status, type (SIP_ORIGINATED,
API_ORIGINATED), from, to, duration, direction (FROM_PSTN, TO_PSTN,
INTRA_NETWORK), startedAt, endedAt and appRef (the app that handled the call; absent when
none did). When answering-machine detection ran, it also has
amdStatus, amdConfidence, amdDetector, amdLatencyMs and amdCause.
CallRecords
Signed call records (vCon) over HTTP.new SDK.CallRecords(client, { baseUrl?, fetch? });
baseUrl defaults to the client’s httpUrl. See Call records.
A record summary has
callRef, appRef, from, to, direction, status, endReason,
failureReason, sipStatus, startedAt, endedAt, durationSeconds, region, version,
size and parts.
Webhooks
Endpoints that receive workspace events.new SDK.Webhooks(client). See
Webhook events.
A
WebhookDelivery has ref, webhookRef, eventId, eventType, status (pending,
succeeded, failed), attempts, lastStatus (HTTP status of the last attempt, 0 for no
response), lastAttemptAt, nextAttemptAt, createdAt and event (the event Fonoster sent: id, type,
createdAt, workspaceRef, data; see Webhook events).
Providers
The catalog of speech and language providers, and your own vendor keys.new SDK.Providers(client).
See Providers and models.
A
CatalogItem has id (such as deepgram/nova-3), kind, state (active, deprecated),
providerId, and when they apply type, capabilities, languages, features, models,
gender, accent (voices, such as Mexican), replacement and retireOn.
Usage
What the workspace consumed, in quantities, never money.new SDK.Usage(client).
A
UsageRow has meter, unit and quantity, plus the dimensions you grouped by. Meters:
call.seconds (from answer to hangup), stt.seconds, tts.characters, llm.tokens.in,
llm.tokens.out, llm.tokens.cached, embedding.tokens, nc.seconds (noise cancelling),
amd.detections, amd.seconds, recording.seconds and storage.bytes (the peak in the range,
or the day’s reading when grouped by day). keySource says whether a vendor was called with your
own key (workspace) or the platform’s (platform); origin tells calls (call) from browser
tests (browser_test) and evals (eval). For tts.characters, model is the text-to-speech
model, such as deepgram/aura-2, not the voice.
Secrets
Named secret values stored in the workspace.new SDK.Secrets(client).
ApiKeys
API keys for the workspace.new SDK.ApiKeys(client). See API keys and access.
expiresAt, createdAt and updatedAt of a key are seconds since the epoch.
Workspaces
Workspaces you belong to, and their members.new SDK.Workspaces(client).
The workspace selected by the client’s
accessKeyId is the one these methods act on, except
createWorkspace and listWorkspaces. role is WORKSPACE_OWNER, WORKSPACE_ADMIN or
WORKSPACE_MEMBER; status is PENDING or ACTIVE.
Regions
The regions a new workspace can use, over HTTP.new SDK.Regions(client, { baseUrl?, fetch? }).
Pass a region’s
id to createWorkspace({ name, region }). Creating and enrolling private
regions is covered under Private regions.