nixflex 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +80 -0
- package/dist/index.cjs +516 -0
- package/dist/index.d.cts +704 -0
- package/dist/index.d.ts +704 -0
- package/dist/index.js +481 -0
- package/package.json +32 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,704 @@
|
|
|
1
|
+
interface NixflexClientOptions {
|
|
2
|
+
/** Your full API key: "nxf_xxx:nxfs_xxx" (key_id:key_secret). */
|
|
3
|
+
apiKey: string;
|
|
4
|
+
/** Override the API base URL (testing/staging). Default: https://api.nixflex.com */
|
|
5
|
+
baseUrl?: string;
|
|
6
|
+
/** Per-request timeout in milliseconds. Default 30000. */
|
|
7
|
+
timeoutMs?: number;
|
|
8
|
+
/** Max automatic retries for retryable failures. Default 1. Set 0 to disable. */
|
|
9
|
+
maxRetries?: number;
|
|
10
|
+
}
|
|
11
|
+
interface RequestOptions {
|
|
12
|
+
/** Override the client timeout for this one request. */
|
|
13
|
+
timeoutMs?: number;
|
|
14
|
+
/** AbortSignal to cancel the request from outside. */
|
|
15
|
+
signal?: AbortSignal;
|
|
16
|
+
}
|
|
17
|
+
declare class HttpClient {
|
|
18
|
+
private readonly apiKey;
|
|
19
|
+
private readonly baseUrl;
|
|
20
|
+
private readonly timeoutMs;
|
|
21
|
+
private readonly maxRetries;
|
|
22
|
+
constructor(opts: NixflexClientOptions);
|
|
23
|
+
request<T>(method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE', path: string, body?: unknown, query?: Record<string, string | number | boolean | undefined>, reqOpts?: RequestOptions): Promise<T>;
|
|
24
|
+
private fetchWithTimeout;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
type ResponseLength = 'short' | 'medium' | 'long';
|
|
28
|
+
type TransferType = 'cold' | 'warm';
|
|
29
|
+
/** Parameters for creating an agent. Every field is optional - the API has
|
|
30
|
+
* sensible defaults for all of them. `name` is the only one recommended. */
|
|
31
|
+
interface AgentCreateParams {
|
|
32
|
+
/** Display name (max 100 chars). Default "Untitled Agent". */
|
|
33
|
+
name?: string;
|
|
34
|
+
/** The AI's instructions (max 16000 chars ~ 4000 tokens). Over-limit is rejected with `prompt_too_long`. */
|
|
35
|
+
system_prompt?: string;
|
|
36
|
+
/** First line spoken on inbound calls. */
|
|
37
|
+
welcome_message?: string;
|
|
38
|
+
/** Voice name (browse in the dashboard). Default "Ashley". */
|
|
39
|
+
voice_id?: string;
|
|
40
|
+
/** Language code, or "multi" (follows the caller across 10 languages). Arabic, Hebrew, Korean, Chinese and Polish need their own code. */
|
|
41
|
+
language?: string;
|
|
42
|
+
/** Set false to disable without deleting. */
|
|
43
|
+
is_active?: boolean;
|
|
44
|
+
/** AI temperature 0-1. Default 0.3. */
|
|
45
|
+
temperature?: number;
|
|
46
|
+
response_length?: ResponseLength;
|
|
47
|
+
/** Agent greets the caller immediately. Default true. */
|
|
48
|
+
ai_speaks_first?: boolean;
|
|
49
|
+
/** AI improvises the greeting per call instead of the static welcome. */
|
|
50
|
+
dynamic_greeting?: boolean;
|
|
51
|
+
/** 0-100. Lower = harder to interrupt. Default 50. */
|
|
52
|
+
interruption_sensitivity?: number;
|
|
53
|
+
/** Milliseconds the agent waits after the caller stops speaking, 0-1000. Default 200. */
|
|
54
|
+
response_eagerness?: number;
|
|
55
|
+
/** Comma-separated words STT might mishear (staff names, treatments). Keep under 50 - too many are rejected at transcription time. */
|
|
56
|
+
boosted_keywords?: string;
|
|
57
|
+
/** Seconds the agent waits after pickup before speaking, 5-30. Default 10. */
|
|
58
|
+
pickup_delay?: number;
|
|
59
|
+
/** Hard cap on call length, 60-1800 seconds. Default 600. */
|
|
60
|
+
max_call_duration_seconds?: number;
|
|
61
|
+
/** Hang up if the caller is silent this long, 5-45 seconds. Default 30. */
|
|
62
|
+
silence_hangup_seconds?: number;
|
|
63
|
+
/** Save call audio. Recordings delete after 90 days. Default true. */
|
|
64
|
+
record_call?: boolean;
|
|
65
|
+
/** Carrier answering-machine detection: fast hangup ~4s in, NO voicemail message, extra carrier cost. OFF lets the agent detect voicemail itself and leave a message. Default false. */
|
|
66
|
+
amd_enabled?: boolean;
|
|
67
|
+
/** Keypad digits instead of speech. Three-state: true/false explicit, null = not set (a number's own setting decides). */
|
|
68
|
+
dtmf_enabled?: boolean | null;
|
|
69
|
+
/** Where to POST post-call data. */
|
|
70
|
+
webhook_url?: string | null;
|
|
71
|
+
/** Agent can end the call cleanly. Default true. */
|
|
72
|
+
func_end_call?: boolean;
|
|
73
|
+
/** Warm-transfer briefing text. Empty = AI auto-generates from the conversation. */
|
|
74
|
+
transfer_whisper?: string | null;
|
|
75
|
+
/** NOT ENFORCED - accepted and returned, but the engine does not read it. Control texting in your prompt. */
|
|
76
|
+
func_send_sms?: boolean;
|
|
77
|
+
/** NOT ENFORCED - same as func_send_sms. Transfers are controlled by your prompt and transfer_number. */
|
|
78
|
+
func_cold_transfer?: boolean;
|
|
79
|
+
transfer_type?: TransferType;
|
|
80
|
+
/** Default destination for transfers. */
|
|
81
|
+
transfer_number?: string | null;
|
|
82
|
+
/** IGNORED (legacy) - accepted for backwards compatibility, nothing reads it. Use speaking_rate. */
|
|
83
|
+
voice_speed?: number;
|
|
84
|
+
/** Speaking speed: 1 normal, 0.5 half, 1.5 fast. Clamped, not rejected. null = normal (NOT the same as 1). */
|
|
85
|
+
speaking_rate?: number | null;
|
|
86
|
+
/** Greet recognised returning callers by name. Default true. */
|
|
87
|
+
greet_by_name?: boolean;
|
|
88
|
+
/** Said when transcription fails. */
|
|
89
|
+
fallback_message?: string;
|
|
90
|
+
}
|
|
91
|
+
/** Update accepts any create field; omitted fields keep their values.
|
|
92
|
+
* Unrecognised field names return 200 and change NOTHING - check spelling
|
|
93
|
+
* against the docs if a setting is not taking effect. */
|
|
94
|
+
type AgentUpdateParams = AgentCreateParams;
|
|
95
|
+
/** The agent object as the API returns it. */
|
|
96
|
+
interface Agent {
|
|
97
|
+
agent_id: string;
|
|
98
|
+
name: string;
|
|
99
|
+
system_prompt: string;
|
|
100
|
+
welcome_message: string;
|
|
101
|
+
voice_id: string;
|
|
102
|
+
language: string;
|
|
103
|
+
temperature: number;
|
|
104
|
+
response_length?: ResponseLength;
|
|
105
|
+
ai_speaks_first?: boolean;
|
|
106
|
+
dynamic_greeting?: boolean;
|
|
107
|
+
interruption_sensitivity?: number;
|
|
108
|
+
pickup_delay?: number;
|
|
109
|
+
max_call_duration_seconds: number;
|
|
110
|
+
silence_hangup_seconds: number;
|
|
111
|
+
record_call: boolean;
|
|
112
|
+
func_end_call?: boolean;
|
|
113
|
+
transfer_whisper?: string | null;
|
|
114
|
+
func_send_sms?: boolean;
|
|
115
|
+
func_cold_transfer?: boolean;
|
|
116
|
+
transfer_type?: TransferType;
|
|
117
|
+
transfer_number: string | null;
|
|
118
|
+
webhook_url: string | null;
|
|
119
|
+
voice_speed?: number;
|
|
120
|
+
speaking_rate?: number | null;
|
|
121
|
+
dtmf_enabled?: boolean | null;
|
|
122
|
+
amd_enabled?: boolean;
|
|
123
|
+
greet_by_name?: boolean;
|
|
124
|
+
fallback_message: string;
|
|
125
|
+
post_call_sms_enabled?: boolean;
|
|
126
|
+
post_call_sms_template?: string | null;
|
|
127
|
+
data_extraction_fields?: unknown[];
|
|
128
|
+
is_active: boolean;
|
|
129
|
+
created_at: string;
|
|
130
|
+
updated_at: string;
|
|
131
|
+
}
|
|
132
|
+
interface AgentDeleteResponse {
|
|
133
|
+
agent_id: string;
|
|
134
|
+
deleted: boolean;
|
|
135
|
+
}
|
|
136
|
+
interface ListParams {
|
|
137
|
+
/** Hard-capped at 200 per request (higher values are reduced, not rejected). */
|
|
138
|
+
limit?: number;
|
|
139
|
+
offset?: number;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
declare class Agents {
|
|
143
|
+
private readonly http;
|
|
144
|
+
constructor(http: HttpClient);
|
|
145
|
+
/** Create an agent. Every field has a sensible default - `{ name }` alone works.
|
|
146
|
+
* The agent is immediately usable for numbers and outbound calls. */
|
|
147
|
+
create(params?: AgentCreateParams, opts?: RequestOptions): Promise<Agent>;
|
|
148
|
+
/** List active agents, newest first. Default 100, hard cap 200 per page. */
|
|
149
|
+
list(params?: ListParams, opts?: RequestOptions): Promise<Agent[]>;
|
|
150
|
+
/** Iterate ALL agents across pages: `for await (const a of client.agents.iter()) { ... }` */
|
|
151
|
+
iter(pageSize?: number, opts?: RequestOptions): AsyncGenerator<Agent>;
|
|
152
|
+
/** Fetch one agent with full configuration. Throws NixflexNotFoundError if the ID is not yours. */
|
|
153
|
+
get(agentId: string, opts?: RequestOptions): Promise<Agent>;
|
|
154
|
+
/** Update an agent. Send ONLY the fields you want to change - omitted fields
|
|
155
|
+
* keep their values. Active calls are unaffected; new calls use the new config.
|
|
156
|
+
* Unknown field names return 200 and change nothing - check spelling. */
|
|
157
|
+
update(agentId: string, params: AgentUpdateParams, opts?: RequestOptions): Promise<Agent>;
|
|
158
|
+
/** PERMANENTLY delete an agent. Attached numbers detach and stop routing;
|
|
159
|
+
* historical calls stay accessible. To disable without losing setup, use
|
|
160
|
+
* update(agentId, { is_active: false }) instead. */
|
|
161
|
+
delete(agentId: string, opts?: RequestOptions): Promise<AgentDeleteResponse>;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
type CallDirection = 'inbound' | 'outbound';
|
|
165
|
+
type CallerSentiment = 'happy' | 'neutral' | 'frustrated';
|
|
166
|
+
/** A call record. Both GET /calls and GET /calls/:id return this exact shape. */
|
|
167
|
+
interface Call {
|
|
168
|
+
call_id: string;
|
|
169
|
+
agent_id: string;
|
|
170
|
+
call_direction: CallDirection;
|
|
171
|
+
/** Same meaning as call_direction; both are returned. */
|
|
172
|
+
call_type?: CallDirection;
|
|
173
|
+
/** Caller's number, E.164. */
|
|
174
|
+
from_number: string;
|
|
175
|
+
/** Number that was called, E.164. */
|
|
176
|
+
to_number: string;
|
|
177
|
+
call_status: string;
|
|
178
|
+
/** Epoch MILLISECONDS. On outbound this is when dialling began - BEFORE ringing. */
|
|
179
|
+
start_timestamp: number;
|
|
180
|
+
/** Epoch MILLISECONDS. */
|
|
181
|
+
end_timestamp: number;
|
|
182
|
+
/** Epoch milliseconds when ANSWERED, or null (inbound / older calls). Ring time = answered_at - start_timestamp. */
|
|
183
|
+
answered_at: number | null;
|
|
184
|
+
/** TIME CONNECTED in ms (answer to hangup) - the number you are billed on. Ring time excluded, so on outbound this is NOT end_timestamp - start_timestamp. */
|
|
185
|
+
duration_ms: number;
|
|
186
|
+
ended_reason: string;
|
|
187
|
+
/** A single string, one turn per line - not an array of turn objects. */
|
|
188
|
+
transcript: string;
|
|
189
|
+
call_summary: string;
|
|
190
|
+
caller_sentiment: CallerSentiment;
|
|
191
|
+
call_successful: boolean;
|
|
192
|
+
/** Fields pulled from the call, per the agent's extraction settings. */
|
|
193
|
+
extracted_data: Record<string, unknown>;
|
|
194
|
+
/** Appointments booked during the call. */
|
|
195
|
+
bookings: unknown[];
|
|
196
|
+
/** MP3 link, or null if recording was off. This is the ONLY copy - the carrier's copy is deleted. */
|
|
197
|
+
recording_url: string | null;
|
|
198
|
+
recording_duration_s?: number;
|
|
199
|
+
voicemail_detected: boolean;
|
|
200
|
+
voicemail_detection_method?: string | null;
|
|
201
|
+
/** Carrier machine-detection verdict (e.g. 'human', 'machine_start'). Only when AMD is enabled. */
|
|
202
|
+
amd_result?: string | null;
|
|
203
|
+
call_reason?: string | null;
|
|
204
|
+
caller_name?: string | null;
|
|
205
|
+
/** Outbound campaign this call belongs to, or null. */
|
|
206
|
+
campaign_id?: string | null;
|
|
207
|
+
avg_latency_ms?: number;
|
|
208
|
+
/** ISO 8601 (the only non-epoch timestamp on this object). */
|
|
209
|
+
created_at: string;
|
|
210
|
+
}
|
|
211
|
+
/** Parameters for POST /v1/calls/outbound. */
|
|
212
|
+
interface OutboundCallParams {
|
|
213
|
+
/** The agent that handles the call. Must belong to your API key. */
|
|
214
|
+
agent_id: string;
|
|
215
|
+
/** Who to call, E.164 ("+447386172392", not "07386172392"). NOTE: the field is to_number, not `to` - `to` is the SMS endpoints' field. */
|
|
216
|
+
to_number: string;
|
|
217
|
+
/** The call purpose - what to say and why. Sent fresh per call, stored nowhere. Must not be empty. */
|
|
218
|
+
prompt: string;
|
|
219
|
+
/** Key-values interpolated into the prompt as {key}. Unmatched references stay literal - check your keys. */
|
|
220
|
+
dynamic_vars?: Record<string, string>;
|
|
221
|
+
/** Which of your numbers to dial from. Must be outbound-enabled on this agent. Omit = the agent's first outbound-enabled number. */
|
|
222
|
+
from_number?: string;
|
|
223
|
+
/** Link this call to a batch campaign for reporting. */
|
|
224
|
+
campaign_id?: string;
|
|
225
|
+
}
|
|
226
|
+
/** Fire-and-forget: returns immediately; ringing/conversation/ending happen
|
|
227
|
+
* async. Set a webhook_url to receive call.completed when it ends. */
|
|
228
|
+
interface OutboundCallResponse {
|
|
229
|
+
call_id: string;
|
|
230
|
+
status: string;
|
|
231
|
+
to: string;
|
|
232
|
+
from: string;
|
|
233
|
+
}
|
|
234
|
+
interface BatchRecipient {
|
|
235
|
+
phone: string;
|
|
236
|
+
/** Injected as context automatically - no {{placeholders}} needed in the prompt. */
|
|
237
|
+
variables?: Record<string, string>;
|
|
238
|
+
/** Replaces the campaign prompt for this recipient only. */
|
|
239
|
+
prompt_override?: string;
|
|
240
|
+
}
|
|
241
|
+
type Weekday = 'mon' | 'tue' | 'wed' | 'thu' | 'fri' | 'sat' | 'sun';
|
|
242
|
+
/** Parameters for POST /v1/calls/batch. */
|
|
243
|
+
interface BatchCampaignParams {
|
|
244
|
+
agent_id: string;
|
|
245
|
+
/** The call purpose for every call. Required. */
|
|
246
|
+
prompt: string;
|
|
247
|
+
/** The number to dial from - imported and attached to this agent. Twilio and Telnyx both work. */
|
|
248
|
+
from_number: string;
|
|
249
|
+
recipients: BatchRecipient[];
|
|
250
|
+
/** Display name for the campaign. */
|
|
251
|
+
name?: string;
|
|
252
|
+
/** false (default): reject the whole request on any invalid phone. true: dial valid ones, list invalid in the response. */
|
|
253
|
+
skip_invalid?: boolean;
|
|
254
|
+
/** 'now' (default, launches immediately) or 'schedule'. */
|
|
255
|
+
schedule_type?: 'now' | 'schedule';
|
|
256
|
+
/** YYYY-MM-DD. Required when schedule_type is 'schedule'. */
|
|
257
|
+
scheduled_date?: string;
|
|
258
|
+
/** Calling window start, minutes since midnight (540 = 9:00am). */
|
|
259
|
+
window_start_minutes?: number;
|
|
260
|
+
/** Calling window end, minutes since midnight (1080 = 6:00pm). Overnight windows (start > end) are supported. */
|
|
261
|
+
window_end_minutes?: number;
|
|
262
|
+
window_days?: Weekday[];
|
|
263
|
+
/** IANA timezone the window runs in (e.g. "Europe/London"). Priority: this > the agent's timezone > Europe/London. One campaign = one timezone - split multi-country lists into separate campaigns. */
|
|
264
|
+
timezone?: string;
|
|
265
|
+
}
|
|
266
|
+
interface BatchInvalidEntry {
|
|
267
|
+
phone: string;
|
|
268
|
+
reason: string;
|
|
269
|
+
row_index: number;
|
|
270
|
+
}
|
|
271
|
+
interface BatchCreateResponse {
|
|
272
|
+
campaign_id: string;
|
|
273
|
+
status: string;
|
|
274
|
+
valid_count: number;
|
|
275
|
+
invalid_count: number;
|
|
276
|
+
invalid: BatchInvalidEntry[];
|
|
277
|
+
}
|
|
278
|
+
interface BatchLaunchResponse {
|
|
279
|
+
campaign_id: string;
|
|
280
|
+
status: string;
|
|
281
|
+
recipients_count: number;
|
|
282
|
+
queued_count: number;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
declare class Calls {
|
|
286
|
+
private readonly http;
|
|
287
|
+
constructor(http: HttpClient);
|
|
288
|
+
/** Trigger an outbound AI call. FIRE-AND-FORGET: returns immediately with a
|
|
289
|
+
* call_id; ringing, conversation and ending happen asynchronously. Set a
|
|
290
|
+
* webhook_url on the agent or number to receive call.completed when it ends.
|
|
291
|
+
* The dialling number must be OUTBOUND-ENABLED (inbound working does not
|
|
292
|
+
* mean outbound works - separate switches). */
|
|
293
|
+
create(params: OutboundCallParams, opts?: RequestOptions): Promise<OutboundCallResponse>;
|
|
294
|
+
/** List calls, newest first. Default 50, hard cap 200. The response is a
|
|
295
|
+
* bare array with no total - page until you get fewer rows than you asked
|
|
296
|
+
* for (or use iter()). Call data is retained 90 days. */
|
|
297
|
+
list(params?: ListParams, opts?: RequestOptions): Promise<Call[]>;
|
|
298
|
+
/** Iterate ALL calls across pages: `for await (const c of client.calls.iter()) { ... }` */
|
|
299
|
+
iter(pageSize?: number, opts?: RequestOptions): AsyncGenerator<Call>;
|
|
300
|
+
/** Fetch one call: transcript, recording URL, post-call analysis. Note:
|
|
301
|
+
* duration_ms is time CONNECTED (what you are billed on) - ring time is
|
|
302
|
+
* excluded, so it will not equal end_timestamp - start_timestamp on
|
|
303
|
+
* outbound calls. */
|
|
304
|
+
get(callId: string, opts?: RequestOptions): Promise<Call>;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
declare class Campaigns {
|
|
308
|
+
private readonly http;
|
|
309
|
+
constructor(http: HttpClient);
|
|
310
|
+
/** Create a batch campaign - many outbound calls under one campaign_id.
|
|
311
|
+
* schedule_type 'now' launches immediately; 'schedule' waits for
|
|
312
|
+
* scheduled_date and fires INSIDE the calling window in the campaign's
|
|
313
|
+
* timezone (yours > the agent's > Europe/London). Overnight windows
|
|
314
|
+
* supported. One campaign = one timezone - split multi-country lists. */
|
|
315
|
+
create(params: BatchCampaignParams, opts?: RequestOptions): Promise<BatchCreateResponse>;
|
|
316
|
+
/** Launch a scheduled campaign immediately, overriding its schedule.
|
|
317
|
+
* Already running = no-op returning current status. */
|
|
318
|
+
launch(campaignId: string, opts?: RequestOptions): Promise<BatchLaunchResponse>;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/** Import params - the carrier is INFERRED from which credentials you send.
|
|
322
|
+
* Twilio: twilio_sid + twilio_token. Telnyx: telnyx_api_key + telnyx_connection_id
|
|
323
|
+
* (the ID of a TeXML Application you created in your Telnyx portal, voice webhook
|
|
324
|
+
* https://api.nixflex.com/telnyx-voice, POST, API v2, G711U on / HD Voice off). */
|
|
325
|
+
interface PhoneNumberImportParams {
|
|
326
|
+
/** E.164. Must already exist in your carrier account. */
|
|
327
|
+
phone_number: string;
|
|
328
|
+
/** The agent this number answers with. Must be yours. */
|
|
329
|
+
agent_id: string;
|
|
330
|
+
/** Twilio Account SID (AC + 32 hex). Twilio import. */
|
|
331
|
+
twilio_sid?: string;
|
|
332
|
+
/** Twilio Auth Token. Twilio import. WARNING: importing REPLACES the number's existing webhooks. */
|
|
333
|
+
twilio_token?: string;
|
|
334
|
+
/** Telnyx API key with access to the number. Telnyx import. */
|
|
335
|
+
telnyx_api_key?: string;
|
|
336
|
+
/** Your TeXML Application ID. Telnyx import. */
|
|
337
|
+
telnyx_connection_id?: string;
|
|
338
|
+
/** Per-number prompt override, max 8000 chars. */
|
|
339
|
+
custom_prompt?: string;
|
|
340
|
+
}
|
|
341
|
+
interface PhoneNumber {
|
|
342
|
+
phone_number: string;
|
|
343
|
+
agent_id: string;
|
|
344
|
+
/** 'twilio' or 'telnyx'. */
|
|
345
|
+
provider: string;
|
|
346
|
+
/** Twilio numbers only; null on other carriers. */
|
|
347
|
+
twilio_number_sid?: string | null;
|
|
348
|
+
telnyx_number_id?: string | null;
|
|
349
|
+
inbound_enabled: boolean;
|
|
350
|
+
outbound_enabled: boolean;
|
|
351
|
+
custom_prompt?: string | null;
|
|
352
|
+
voice_id?: string | null;
|
|
353
|
+
sms_reply_enabled?: boolean;
|
|
354
|
+
sms_prompt?: string | null;
|
|
355
|
+
web_prompt?: string | null;
|
|
356
|
+
speaking_rate?: number | null;
|
|
357
|
+
dtmf_enabled?: boolean | null;
|
|
358
|
+
record_call?: boolean | null;
|
|
359
|
+
created_at?: string;
|
|
360
|
+
}
|
|
361
|
+
/** Every field optional - send only what changes; omitted fields are untouched.
|
|
362
|
+
* An EMPTY body is rejected. null clears a field (falls back to the agent). */
|
|
363
|
+
interface PhoneNumberUpdateParams {
|
|
364
|
+
/** Business profile layered on the agent prompt for CALLS only. Max 8000. null clears. */
|
|
365
|
+
custom_prompt?: string | null;
|
|
366
|
+
/** Voice override for this number. null falls back to the agent's voice. */
|
|
367
|
+
voice_id?: string | null;
|
|
368
|
+
/** SMS agent auto-reply on/off. Default false. */
|
|
369
|
+
sms_reply_enabled?: boolean;
|
|
370
|
+
/** SMS agent instructions (independent channel). Max 20000. null clears. */
|
|
371
|
+
sms_prompt?: string | null;
|
|
372
|
+
/** Web agent instructions (independent channel). Max 20000. null clears. */
|
|
373
|
+
web_prompt?: string | null;
|
|
374
|
+
/** Speed override: 1 normal, clamped to range. null = INHERIT the agent's speed (send 1, not null, to force normal). */
|
|
375
|
+
speaking_rate?: number | null;
|
|
376
|
+
/** Keypad input: true/false explicit, null = inherit the agent's setting. */
|
|
377
|
+
dtmf_enabled?: boolean | null;
|
|
378
|
+
/** Recording: null = inherit; false stops recording this number while the agent keeps recording. */
|
|
379
|
+
record_call?: boolean | null;
|
|
380
|
+
}
|
|
381
|
+
interface PhoneNumberListResponse {
|
|
382
|
+
phone_numbers: PhoneNumber[];
|
|
383
|
+
count: number;
|
|
384
|
+
}
|
|
385
|
+
interface PhoneNumberDeleteResponse {
|
|
386
|
+
phone_number: {
|
|
387
|
+
phone_number: string;
|
|
388
|
+
deleted: boolean;
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
interface MonitorToggleResponse {
|
|
392
|
+
ok?: boolean;
|
|
393
|
+
phone_number: string;
|
|
394
|
+
monitor_enabled: boolean;
|
|
395
|
+
}
|
|
396
|
+
interface WebCallsToggleResponse {
|
|
397
|
+
ok?: boolean;
|
|
398
|
+
phone_number: string;
|
|
399
|
+
web_calls_enabled: boolean;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/** NOTE: this endpoint uses `to` (NOT to_number - that is the outbound-call
|
|
403
|
+
* field). Sending to_number here fails with a missing-field error. */
|
|
404
|
+
interface SmsSendParams {
|
|
405
|
+
/** Agent that owns this SMS - its prompt handles any replies. */
|
|
406
|
+
agent_id: string;
|
|
407
|
+
/** Recipient, E.164. This endpoint uses `to`, not `to_number`. */
|
|
408
|
+
to: string;
|
|
409
|
+
/** Message text. 600 chars recommended for reliable delivery (carrier hard caps ~1600). */
|
|
410
|
+
message: string;
|
|
411
|
+
/** Which imported number to send from (either carrier). Omit = the agent's own number. */
|
|
412
|
+
from_number?: string;
|
|
413
|
+
/** Optional reply context: { reply_context: "..." } gives the agent background for replies to this message. */
|
|
414
|
+
context?: {
|
|
415
|
+
reply_context?: string;
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
interface SmsSendResponse {
|
|
419
|
+
status: string;
|
|
420
|
+
to: string;
|
|
421
|
+
from: string;
|
|
422
|
+
}
|
|
423
|
+
interface SmsCampaignRecipient {
|
|
424
|
+
phone: string;
|
|
425
|
+
/** Fills {{placeholders}} in the template. Missing variables render as empty strings. */
|
|
426
|
+
variables?: Record<string, string>;
|
|
427
|
+
}
|
|
428
|
+
/** SMS campaigns currently require a TWILIO from_number - Telnyx numbers are
|
|
429
|
+
* rejected at create (single sends via sms.send work on both carriers). */
|
|
430
|
+
interface SmsCampaignCreateParams {
|
|
431
|
+
agent_id: string;
|
|
432
|
+
/** Your imported TWILIO number. */
|
|
433
|
+
from_number: string;
|
|
434
|
+
/** Display name in the dashboard. */
|
|
435
|
+
name: string;
|
|
436
|
+
/** Message text with {{variable}} placeholders. */
|
|
437
|
+
message_template: string;
|
|
438
|
+
/** Up to 10,000. */
|
|
439
|
+
recipients: SmsCampaignRecipient[];
|
|
440
|
+
schedule_type: 'now' | 'schedule';
|
|
441
|
+
/** ISO date - required when schedule_type is 'schedule'. */
|
|
442
|
+
scheduled_at?: string;
|
|
443
|
+
}
|
|
444
|
+
type SmsCampaignStatus = 'draft' | 'scheduled' | 'running' | 'done' | 'failed';
|
|
445
|
+
interface SmsCampaign {
|
|
446
|
+
campaign_id: string;
|
|
447
|
+
agent_id: string;
|
|
448
|
+
name: string;
|
|
449
|
+
from_number?: string;
|
|
450
|
+
message_template?: string;
|
|
451
|
+
status: SmsCampaignStatus;
|
|
452
|
+
total_count: number;
|
|
453
|
+
/** Carrier-confirmed handset delivery. Note: Twilio 'sent' (handed to carrier,
|
|
454
|
+
* never confirmed) is counted as FAILED, not delivered. */
|
|
455
|
+
delivered_count: number;
|
|
456
|
+
failed_count: number;
|
|
457
|
+
pending_count: number;
|
|
458
|
+
source?: string;
|
|
459
|
+
scheduled_at?: string | null;
|
|
460
|
+
created_at: string;
|
|
461
|
+
recipients?: Array<{
|
|
462
|
+
phone: string;
|
|
463
|
+
variables?: Record<string, string>;
|
|
464
|
+
status: 'pending' | 'queued' | 'sent' | 'delivered' | 'undelivered' | 'failed';
|
|
465
|
+
twilio_sid?: string;
|
|
466
|
+
rendered_message?: string;
|
|
467
|
+
error_message?: string;
|
|
468
|
+
sent_at?: string;
|
|
469
|
+
}>;
|
|
470
|
+
}
|
|
471
|
+
interface SmsCampaignListResponse {
|
|
472
|
+
campaigns: SmsCampaign[];
|
|
473
|
+
}
|
|
474
|
+
interface SmsCampaignLaunchResponse {
|
|
475
|
+
campaign_id: string;
|
|
476
|
+
status: string;
|
|
477
|
+
total_count: number;
|
|
478
|
+
pending_count: number;
|
|
479
|
+
delivered_count: number;
|
|
480
|
+
failed_count: number;
|
|
481
|
+
}
|
|
482
|
+
interface SmsCampaignDeleteResponse {
|
|
483
|
+
campaign_id: string;
|
|
484
|
+
deleted: boolean;
|
|
485
|
+
/** Pending recipients that will NOT be messaged. Already-sent messages cannot be recalled. */
|
|
486
|
+
cancelled_count: number;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
interface KeyRotateResponse {
|
|
490
|
+
message: string;
|
|
491
|
+
/** Stays the same - only the secret rotates (Stripe model). */
|
|
492
|
+
key_id: string;
|
|
493
|
+
/** Shown ONCE. The old secret stops working the instant this returns. */
|
|
494
|
+
key_secret: string;
|
|
495
|
+
}
|
|
496
|
+
interface KeyCreateResponse {
|
|
497
|
+
message: string;
|
|
498
|
+
key_id: string;
|
|
499
|
+
/** Shown ONCE - store it immediately. */
|
|
500
|
+
key_secret: string;
|
|
501
|
+
}
|
|
502
|
+
/** The REAL /v1/usage response (verified live Aug 2026 - the docs page
|
|
503
|
+
* described a different shape and is being corrected). All-time totals
|
|
504
|
+
* plus the account limits and this months concurrency peak. */
|
|
505
|
+
interface Usage {
|
|
506
|
+
plan: string;
|
|
507
|
+
total_calls: number;
|
|
508
|
+
/** Fractional minutes, e.g. 551.54. */
|
|
509
|
+
total_minutes: number;
|
|
510
|
+
/** Nixflex charges only - carrier costs are billed to you by Twilio/Telnyx. */
|
|
511
|
+
total_cost: number;
|
|
512
|
+
rate_limit_per_minute: number;
|
|
513
|
+
max_concurrent: number;
|
|
514
|
+
peak_concurrent_this_month: number;
|
|
515
|
+
rejected_at_cap_this_month: number;
|
|
516
|
+
}
|
|
517
|
+
interface WebhookConfigResponse {
|
|
518
|
+
ok?: boolean;
|
|
519
|
+
phone_number?: string;
|
|
520
|
+
url?: string | null;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
declare class PhoneNumbers {
|
|
524
|
+
private readonly http;
|
|
525
|
+
constructor(http: HttpClient);
|
|
526
|
+
/** Attach a number you already own. Carrier inferred from credentials
|
|
527
|
+
* (twilio_sid+twilio_token OR telnyx_api_key+telnyx_connection_id).
|
|
528
|
+
* WARNING: Twilio import REPLACES the number's existing webhooks - another
|
|
529
|
+
* system using this number stops receiving calls and SMS. */
|
|
530
|
+
import(params: PhoneNumberImportParams, opts?: RequestOptions): Promise<{
|
|
531
|
+
phone_number: PhoneNumber;
|
|
532
|
+
}>;
|
|
533
|
+
/** All numbers on your account (optionally one agent's), newest first.
|
|
534
|
+
* Not paginated - returns up to 1,000; filter by agent_id above that. */
|
|
535
|
+
list(params?: {
|
|
536
|
+
agent_id?: string;
|
|
537
|
+
}, opts?: RequestOptions): Promise<PhoneNumberListResponse>;
|
|
538
|
+
/** Update per-number settings. Send ONLY what changes (empty body is
|
|
539
|
+
* rejected). null clears/inherits - see each field's JSDoc; speaking_rate
|
|
540
|
+
* null INHERITS the agent's speed (send 1, not null, to force normal). */
|
|
541
|
+
update(phoneNumber: string, params: PhoneNumberUpdateParams, opts?: RequestOptions): Promise<{
|
|
542
|
+
phone_number: PhoneNumber;
|
|
543
|
+
}>;
|
|
544
|
+
/** Disconnect from Nixflex (clears carrier webhooks + our record). Does NOT
|
|
545
|
+
* release the number from your carrier - carrier billing continues until
|
|
546
|
+
* you release it in Twilio/Telnyx yourself. Reversible by re-importing. */
|
|
547
|
+
delete(phoneNumber: string, opts?: RequestOptions): Promise<PhoneNumberDeleteResponse>;
|
|
548
|
+
/** Turn live call monitoring on/off for a number (off by default).
|
|
549
|
+
* NOTE: enabling bills that number's inbound calls at $0.09/min. */
|
|
550
|
+
setMonitor(phoneNumber: string, enabled: boolean, opts?: RequestOptions): Promise<MonitorToggleResponse>;
|
|
551
|
+
/** Current monitoring state for a number. */
|
|
552
|
+
getMonitor(phoneNumber: string, opts?: RequestOptions): Promise<MonitorToggleResponse>;
|
|
553
|
+
/** Enable/disable browser (web) calls for a number (off by default).
|
|
554
|
+
* NOTE: enabling bills that number's calls at $0.09/min (same rule as
|
|
555
|
+
* Live Monitor - either on means 0.09, both on is still 0.09). */
|
|
556
|
+
setWebCalls(phoneNumber: string, enabled: boolean, opts?: RequestOptions): Promise<WebCallsToggleResponse>;
|
|
557
|
+
/** Current web-calls state for a number. */
|
|
558
|
+
getWebCalls(phoneNumber: string, opts?: RequestOptions): Promise<WebCallsToggleResponse>;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
declare class SmsCampaigns {
|
|
562
|
+
private readonly http;
|
|
563
|
+
constructor(http: HttpClient);
|
|
564
|
+
/** Create a one-time SMS broadcast ({{variable}} templating per recipient,
|
|
565
|
+
* up to 10,000 recipients). Requires a TWILIO from_number - Telnyx numbers
|
|
566
|
+
* are rejected at create (single sends support both carriers). */
|
|
567
|
+
create(params: SmsCampaignCreateParams, opts?: RequestOptions): Promise<SmsCampaign>;
|
|
568
|
+
/** Launch a draft/scheduled campaign immediately. */
|
|
569
|
+
launch(campaignId: string, opts?: RequestOptions): Promise<SmsCampaignLaunchResponse>;
|
|
570
|
+
/** All campaigns, newest first, with live-computed delivery counts. */
|
|
571
|
+
list(params?: {
|
|
572
|
+
status?: SmsCampaignStatus;
|
|
573
|
+
limit?: number;
|
|
574
|
+
}, opts?: RequestOptions): Promise<SmsCampaignListResponse>;
|
|
575
|
+
/** One campaign with per-recipient statuses. Twilio 'sent' (handed to
|
|
576
|
+
* carrier, never confirmed on the handset) counts as FAILED, not delivered. */
|
|
577
|
+
get(campaignId: string, opts?: RequestOptions): Promise<SmsCampaign>;
|
|
578
|
+
/** Cancel a scheduled/running campaign. Already-sent messages cannot be
|
|
579
|
+
* recalled; cancelled_count = pending recipients that will not be messaged. */
|
|
580
|
+
delete(campaignId: string, opts?: RequestOptions): Promise<SmsCampaignDeleteResponse>;
|
|
581
|
+
}
|
|
582
|
+
declare class Sms {
|
|
583
|
+
private readonly http;
|
|
584
|
+
/** SMS campaigns - one-time bulk broadcasts. */
|
|
585
|
+
readonly campaigns: SmsCampaigns;
|
|
586
|
+
constructor(http: HttpClient);
|
|
587
|
+
/** Send a single SMS from one of your numbers (both carriers). NOTE: this
|
|
588
|
+
* endpoint uses `to` - NOT to_number (that is the outbound-call field).
|
|
589
|
+
* Replies are answered automatically by the agent's prompt. */
|
|
590
|
+
send(params: SmsSendParams, opts?: RequestOptions): Promise<SmsSendResponse>;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
declare class Keys {
|
|
594
|
+
private readonly http;
|
|
595
|
+
constructor(http: HttpClient);
|
|
596
|
+
/** Rotate the key SECRET (key_id stays stable - the Stripe model). The old
|
|
597
|
+
* secret stops working THE INSTANT this returns; the new one is shown ONCE.
|
|
598
|
+
* Update every deployed app before rotating in production. */
|
|
599
|
+
rotate(opts?: RequestOptions): Promise<KeyRotateResponse>;
|
|
600
|
+
}
|
|
601
|
+
declare class UsageResource {
|
|
602
|
+
private readonly http;
|
|
603
|
+
constructor(http: HttpClient);
|
|
604
|
+
/** Usage + balance: calls, minutes, SMS, credit. minutes is fractional;
|
|
605
|
+
* cost_usd excludes carrier charges (Twilio/Telnyx bill you directly). */
|
|
606
|
+
get(opts?: RequestOptions): Promise<Usage>;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
declare class Webhooks {
|
|
610
|
+
private readonly http;
|
|
611
|
+
constructor(http: HttpClient);
|
|
612
|
+
/** Point a number's post-call events at your HTTPS endpoint.
|
|
613
|
+
* slot 2 = the second destination (webhook2). */
|
|
614
|
+
set(phoneNumber: string, url: string, slot?: 1 | 2, opts?: RequestOptions): Promise<WebhookConfigResponse>;
|
|
615
|
+
/** Read the webhook configured on a number. */
|
|
616
|
+
get(phoneNumber: string, slot?: 1 | 2, opts?: RequestOptions): Promise<WebhookConfigResponse>;
|
|
617
|
+
/** Remove the webhook from a number. */
|
|
618
|
+
delete(phoneNumber: string, slot?: 1 | 2, opts?: RequestOptions): Promise<WebhookConfigResponse>;
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
interface NixflexAPIErrorBody {
|
|
622
|
+
error: {
|
|
623
|
+
type: string;
|
|
624
|
+
code: string;
|
|
625
|
+
message: string;
|
|
626
|
+
doc_url?: string;
|
|
627
|
+
details?: Record<string, unknown>;
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
declare class NixflexError extends Error {
|
|
631
|
+
/** HTTP status of the failed response (0 for network/timeout failures). */
|
|
632
|
+
readonly status: number;
|
|
633
|
+
/** Machine-readable error code, e.g. 'invalid_json', 'rate_limit_exceeded'. */
|
|
634
|
+
readonly code: string;
|
|
635
|
+
/** Error category from the API, e.g. 'invalid_request', 'rate_limit'. */
|
|
636
|
+
readonly type: string;
|
|
637
|
+
/** Link to the error's documentation page. */
|
|
638
|
+
readonly docUrl?: string;
|
|
639
|
+
/** Structured extra info the API attached to this error. */
|
|
640
|
+
readonly details: Record<string, unknown>;
|
|
641
|
+
/** The x-railway-request-id (or similar) header when present - quote it to support. */
|
|
642
|
+
readonly requestId?: string;
|
|
643
|
+
constructor(status: number, body: NixflexAPIErrorBody | null, requestId?: string, fallbackMessage?: string);
|
|
644
|
+
}
|
|
645
|
+
/** 401 - missing or invalid API key. */
|
|
646
|
+
declare class NixflexAuthenticationError extends NixflexError {
|
|
647
|
+
constructor(...args: ConstructorParameters<typeof NixflexError>);
|
|
648
|
+
}
|
|
649
|
+
/** 402 - balance or credit exhausted. */
|
|
650
|
+
declare class NixflexPaymentRequiredError extends NixflexError {
|
|
651
|
+
constructor(...args: ConstructorParameters<typeof NixflexError>);
|
|
652
|
+
}
|
|
653
|
+
/** 404 - the resource does not exist (or is not yours). */
|
|
654
|
+
declare class NixflexNotFoundError extends NixflexError {
|
|
655
|
+
constructor(...args: ConstructorParameters<typeof NixflexError>);
|
|
656
|
+
}
|
|
657
|
+
/** 429 - rate limit hit. `retryAfterSeconds` says when to try again. */
|
|
658
|
+
declare class NixflexRateLimitError extends NixflexError {
|
|
659
|
+
readonly retryAfterSeconds: number;
|
|
660
|
+
constructor(status: number, body: NixflexAPIErrorBody | null, requestId: string | undefined, retryAfterSeconds: number);
|
|
661
|
+
}
|
|
662
|
+
/** 400/422 - the request itself is malformed or invalid. */
|
|
663
|
+
declare class NixflexInvalidRequestError extends NixflexError {
|
|
664
|
+
constructor(...args: ConstructorParameters<typeof NixflexError>);
|
|
665
|
+
}
|
|
666
|
+
/** 5xx - something failed on Nixflex's side. Retried automatically once. */
|
|
667
|
+
declare class NixflexServerError extends NixflexError {
|
|
668
|
+
constructor(...args: ConstructorParameters<typeof NixflexError>);
|
|
669
|
+
}
|
|
670
|
+
/** Network failure / timeout - the request never got an HTTP response. */
|
|
671
|
+
declare class NixflexConnectionError extends NixflexError {
|
|
672
|
+
constructor(message: string);
|
|
673
|
+
}
|
|
674
|
+
/** Map a status + body to the right error class. */
|
|
675
|
+
declare function errorFromResponse(status: number, body: NixflexAPIErrorBody | null, requestId: string | undefined, retryAfterSeconds: number): NixflexError;
|
|
676
|
+
|
|
677
|
+
declare class Nixflex {
|
|
678
|
+
/** AI agents - create, list, get, update, delete. */
|
|
679
|
+
readonly agents: Agents;
|
|
680
|
+
/** Calls - trigger outbound, list history, fetch transcripts + analysis. */
|
|
681
|
+
readonly calls: Calls;
|
|
682
|
+
/** Voice batch campaigns - many calls under one campaign, scheduling windows. */
|
|
683
|
+
readonly campaigns: Campaigns;
|
|
684
|
+
/** Phone numbers - import (Twilio/Telnyx), settings, monitor + web-calls toggles. */
|
|
685
|
+
readonly phoneNumbers: PhoneNumbers;
|
|
686
|
+
/** SMS - single sends + bulk campaigns. */
|
|
687
|
+
readonly sms: Sms;
|
|
688
|
+
/** API key management - rotate the secret. */
|
|
689
|
+
readonly keys: Keys;
|
|
690
|
+
/** Usage + balance. */
|
|
691
|
+
readonly usage: UsageResource;
|
|
692
|
+
/** Per-number post-call webhook configuration. */
|
|
693
|
+
readonly webhooks: Webhooks;
|
|
694
|
+
constructor(options: NixflexClientOptions);
|
|
695
|
+
/** Create a brand-new API key (unauthenticated signup endpoint - most
|
|
696
|
+
* developers use the dashboard instead). The key_secret is shown ONCE.
|
|
697
|
+
* Rate-limited per IP to prevent abuse. */
|
|
698
|
+
static createKey(params?: {
|
|
699
|
+
name?: string;
|
|
700
|
+
email?: string;
|
|
701
|
+
}, baseUrl?: string): Promise<KeyCreateResponse>;
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
export { type Agent, type AgentCreateParams, type AgentDeleteResponse, type AgentUpdateParams, type BatchCampaignParams, type BatchCreateResponse, type BatchInvalidEntry, type BatchLaunchResponse, type BatchRecipient, type Call, type CallDirection, type CallerSentiment, type KeyCreateResponse, type KeyRotateResponse, type ListParams, type MonitorToggleResponse, Nixflex, type NixflexAPIErrorBody, NixflexAuthenticationError, type NixflexClientOptions, NixflexConnectionError, NixflexError, NixflexInvalidRequestError, NixflexNotFoundError, NixflexPaymentRequiredError, NixflexRateLimitError, NixflexServerError, type OutboundCallParams, type OutboundCallResponse, type PhoneNumber, type PhoneNumberDeleteResponse, type PhoneNumberImportParams, type PhoneNumberListResponse, type PhoneNumberUpdateParams, type RequestOptions, type ResponseLength, type SmsCampaign, type SmsCampaignCreateParams, type SmsCampaignDeleteResponse, type SmsCampaignLaunchResponse, type SmsCampaignListResponse, type SmsCampaignRecipient, type SmsCampaignStatus, type SmsSendParams, type SmsSendResponse, type TransferType, type Usage, type WebCallsToggleResponse, type WebhookConfigResponse, type Weekday, Nixflex as default, errorFromResponse };
|