@replicer/sdk 0.1.1 → 0.2.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.
@@ -0,0 +1,932 @@
1
+ /**
2
+ * Request/response types of the Replicer API (`/v1`). Field names are the wire format (snake_case).
3
+ */
4
+ /** A whole number on the wire (`integer` in the OpenAPI schemas). Plain `number` in TypeScript. */
5
+ type Int = number;
6
+ interface PageParams {
7
+ /**
8
+ * 1-based page number (default 1).
9
+ * @minimum 1
10
+ * @default 1
11
+ */
12
+ page?: Int;
13
+ /**
14
+ * Page size, 1..100 (default 20). Out-of-range values fall back to the default.
15
+ * @minimum 1
16
+ * @maximum 100
17
+ * @default 20
18
+ */
19
+ limit?: Int;
20
+ }
21
+ interface Pagination {
22
+ page: Int;
23
+ limit: Int;
24
+ total: Int;
25
+ total_pages: Int;
26
+ }
27
+ /** Envelope returned by every list method. */
28
+ interface Page<T> {
29
+ data: T[];
30
+ pagination: Pagination;
31
+ }
32
+ interface OkResponse {
33
+ ok: boolean;
34
+ }
35
+ /**
36
+ * `code` values the API returns in its flat error body `{ error, code }`. Branch on `code`, never on
37
+ * the human-readable `error` text. New codes may be added; fall back to the HTTP status.
38
+ */
39
+ type ApiErrorCode = 'validation_error' | 'bad_request' | 'unauthorized' | 'forbidden' | 'insufficient_scope' | 'not_found' | 'method_not_allowed' | 'conflict' | 'idempotency_key_reuse' | 'webhook_endpoint_limit' | 'webhook_endpoint_key_revoked' | 'webhook_endpoint_admin_disabled' | 'redelivery_limit' | 'test_mode_unsupported' | 'payload_too_large' | 'rate_limited' | 'rate_limit_exceeded' | 'rate_limiter_unavailable' | 'insufficient_balance' | 'quota_exceeded' | 'channel_not_configured' | 'sender_not_supported' | 'media_not_supported' | 'email_provider_not_supported' | 'internal_error' | 'bad_gateway' | 'service_unavailable' | 'gateway_timeout' | 'upstream_timeout' | (string & {});
40
+ interface CreatePhoneCallInput {
41
+ /** Agent id; must belong to your organization. */
42
+ agent_id: string;
43
+ /**
44
+ * Phone number id (see `phoneNumber.list`). Selects the caller ID. Required unless the agent has a
45
+ * default phone number. A number of another organization → 404 `not_found`.
46
+ */
47
+ from_number_id?: string;
48
+ /** Informational only: it does not select the caller ID. Use `from_number_id`. */
49
+ from_number?: string;
50
+ to_number: string;
51
+ /** Sparse override merged on top of the stored agent. */
52
+ agent_override?: Record<string, unknown>;
53
+ /**
54
+ * `{{name}}` substitutions for the prompt, greeting and voicemail message. Up to 100 entries,
55
+ * names `[a-zA-Z_][a-zA-Z0-9_]{0,63}`, values up to 5,000 characters; `null` becomes an empty string.
56
+ * Wins over `agent_override.dynamicVariables`, which wins over the agent's own variables.
57
+ */
58
+ dynamic_variables?: Record<string, string | number | boolean | null>;
59
+ metadata?: Record<string, unknown>;
60
+ /**
61
+ * RFC 3339 date-time **with an offset** (`2026-05-01T09:30:00Z` or `+02:00`); the call is scheduled
62
+ * instead of dialed immediately. A past time dials immediately; an invalid one → 400.
63
+ */
64
+ scheduled_at?: string;
65
+ customer_name?: string;
66
+ /** 0..5 (default 0). Retries repeat the original call (same number, override and metadata). */
67
+ max_retries?: Int;
68
+ /** 5..1440 minutes. */
69
+ retry_delay_minutes?: Int;
70
+ /**
71
+ * A retry with the same key (per organization) returns the call already created and never dials
72
+ * again. A call that failed to enqueue stays failed: retry with a new key.
73
+ */
74
+ idempotency_key?: string;
75
+ }
76
+ interface CancelCallInput {
77
+ /** ID of a call that has not started yet. */
78
+ call_id: string;
79
+ }
80
+ interface CancelCampaignPendingInput {
81
+ campaign_id: string;
82
+ }
83
+ interface EnqueueCallResponse {
84
+ call_id: string;
85
+ /** `pending` or `scheduled` for a new call; a replay of an `idempotency_key` returns the call's current status. */
86
+ status: 'pending' | 'scheduled' | (string & {});
87
+ }
88
+ /** Call direction, from the caller's point of view. Input is case-insensitive; responses are lowercase. */
89
+ type CallDirection = 'inbound' | 'outbound';
90
+ /**
91
+ * `cancel-campaign-pending` first pauses the campaign (`running` / `scheduled` → `paused`), then cancels its
92
+ * pending and queued calls. Resume with `campaign.start`; contacts whose call was cancelled are not redialed.
93
+ */
94
+ interface CancelCampaignPendingResponse {
95
+ ok: boolean;
96
+ calls_cancelled: Int;
97
+ calls_marked: Int;
98
+ queue_removed: Int;
99
+ /** Campaign status after the call, e.g. `paused`. */
100
+ campaign_status: CampaignStatus | null;
101
+ }
102
+ /**
103
+ * Call statuses (lowercase snake_case; filters also accept any case and `in-progress`). Final states: `analyzed` (the normal end state once post-call analysis is done),
104
+ * `completed` (ended, analysis pending), `failed`, `cancelled`, `missed`, `error`.
105
+ */
106
+ type CallStatus = 'pending' | 'scheduled' | 'queued' | 'retry' | 'in_progress' | 'completed' | 'analyzed' | 'failed' | 'cancelled' | 'missed' | 'error';
107
+ /** Sentiment detected by the post-call analysis (lowercase). */
108
+ type CallSentiment = 'positive' | 'neutral' | 'negative' | 'unknown';
109
+ interface ListCallsParams extends PageParams {
110
+ status?: CallStatus;
111
+ direction?: CallDirection;
112
+ /** ISO 8601 lower bound on `started_at`. */
113
+ date_from?: string;
114
+ /** ISO 8601 upper bound on `started_at`. */
115
+ date_to?: string;
116
+ }
117
+ interface Call {
118
+ id: string;
119
+ customer_name: string | null;
120
+ customer_phone: string | null;
121
+ duration: Int | null;
122
+ status: CallStatus;
123
+ direction: CallDirection | null;
124
+ disconnection_reason: string | null;
125
+ sentiment: CallSentiment | null;
126
+ summary: string | null;
127
+ /** Only returned by `call.get`; list items omit it. */
128
+ transcript?: unknown;
129
+ recording: string | null;
130
+ call_successful: boolean | null;
131
+ /** Credits consumed; `0` for a call that cost nothing (e.g. never connected), `null` until it is billed. */
132
+ token_cost: number | null;
133
+ agent_id: string | null;
134
+ campaign_id: string | null;
135
+ started_at: string | null;
136
+ ended_at: string | null;
137
+ scheduled_at: string | null;
138
+ created_at: string | null;
139
+ /** false when created with a test (`rpl_test_`) key: a simulated call that is never billed. See Test mode. */
140
+ livemode: boolean;
141
+ /** The `metadata` object sent when the call was created, or `null`. */
142
+ metadata: Record<string, unknown> | null;
143
+ /** When the post-call analysis finished (`summary`, `sentiment`, `call_successful` are final), or `null`. */
144
+ analyzed_at: string | null;
145
+ }
146
+ interface CreateCampaignInput {
147
+ name: string;
148
+ description?: string;
149
+ user_agent_id: string;
150
+ /** Ignored for API keys (the campaign is attributed to your organization's owner). Only trusted internal callers need it. */
151
+ user_id?: string;
152
+ from_phone_number_id?: string;
153
+ from_number_attempts?: string[];
154
+ from_number_strategy?: 'rolling' | 'clamp' | 'custom';
155
+ contact_attempt_strategy?: 'rolling' | 'clamp' | 'custom';
156
+ /** Non-empty; every contact needs `phone_number`. Up to 100,000 (and the 10 MiB body limit). */
157
+ contacts: Record<string, unknown>[];
158
+ variable_mapping?: Record<string, string>;
159
+ /** RFC 3339 with an offset; invalid → 400. */
160
+ scheduled_at?: string;
161
+ /** 0..5 (default 0). */
162
+ max_retries?: Int;
163
+ /** 5..1440 (default 30). */
164
+ retry_delay_minutes?: Int;
165
+ /** Unique integers 0..6 (0 = Sunday); `[]` = every day. */
166
+ calling_days?: Int[];
167
+ /** `HH:MM`; set both or neither, start before end. */
168
+ calling_start_time?: string;
169
+ calling_end_time?: string;
170
+ /** IANA time zone (default `Europe/Rome`). */
171
+ timezone?: string;
172
+ /** 1..100 and at most your plan's concurrency. */
173
+ max_concurrency?: Int | null;
174
+ /** 0..50 and at most your plan's concurrency. */
175
+ keep_free_for_inbound?: Int;
176
+ /**
177
+ * A retry with the same key (per organization) and body returns the campaign already created
178
+ * instead of creating a second one. Same key, different body → 422 `idempotency_key_reuse`.
179
+ * Non-empty, at most 200 characters. The `Idempotency-Key` header works too.
180
+ */
181
+ idempotency_key?: string;
182
+ }
183
+ /** `POST /v1/campaigns` (201) returns the bare campaign, like `get-call`. */
184
+ type CreateCampaignResponse = Campaign;
185
+ /** `GET /v1/campaigns/:id` returns the bare campaign plus its contacts. */
186
+ interface GetCampaignResponse extends Campaign {
187
+ /** Up to 1,000 contacts, in campaign order. */
188
+ contacts: Record<string, unknown>[];
189
+ /** True when the campaign has more contacts than returned (`contact_count` > `contacts.length`). */
190
+ contacts_truncated: boolean;
191
+ }
192
+ /** Campaign statuses (lowercase). Filters accept any case. */
193
+ type CampaignStatus = 'draft' | 'scheduled' | 'running' | 'paused' | 'completed' | 'cancelled';
194
+ interface ListCampaignsParams extends PageParams {
195
+ /** `draft`, `scheduled`, `running`, `paused`, `completed` or `cancelled` (any case is accepted). */
196
+ status?: CampaignStatus;
197
+ }
198
+ /** Campaign as returned by create, get and list (the same field whitelist everywhere). */
199
+ interface Campaign {
200
+ id: string;
201
+ name: string;
202
+ description: string | null;
203
+ status: CampaignStatus;
204
+ agent_id: string;
205
+ from_phone_number_id: string | null;
206
+ /** E.164 caller ID (the campaign's number). */
207
+ from_number: string | null;
208
+ /** E.164 caller IDs, in order. */
209
+ from_number_attempts: string[] | null;
210
+ from_number_strategy: string | null;
211
+ contact_attempt_strategy: string | null;
212
+ total_contacts: Int;
213
+ contact_count: Int;
214
+ variable_mapping: Record<string, string> | null;
215
+ max_retries: Int;
216
+ retry_delay_minutes: Int;
217
+ max_concurrency: Int | null;
218
+ keep_free_for_inbound: Int;
219
+ calling_days: Int[] | null;
220
+ calling_start_time: string | null;
221
+ calling_end_time: string | null;
222
+ timezone: string;
223
+ calls_started: Int;
224
+ calls_completed: Int;
225
+ calls_failed: Int;
226
+ scheduled_at: string | null;
227
+ started_at: string | null;
228
+ completed_at: string | null;
229
+ created_at: string | null;
230
+ /** false when created with a test (`rpl_test_`) key: its calls are simulated. See Test mode. */
231
+ livemode: boolean;
232
+ updated_at: string | null;
233
+ }
234
+ /** @deprecated Use `Campaign`. */
235
+ type CampaignListItem = Campaign;
236
+ interface StartCampaignResponse {
237
+ id: string;
238
+ status: 'running';
239
+ }
240
+ interface ProvisionInboundInput {
241
+ /** Phone number id. */
242
+ id: string;
243
+ label?: string;
244
+ from_number: string;
245
+ }
246
+ interface ProvisionInboundResponse {
247
+ inbound_trunk_id: string;
248
+ inbound_dispatch_rule_id: string;
249
+ }
250
+ /** Phone number kinds (lowercase). */
251
+ type PhoneNumberType = 'local' | 'mobile' | 'toll_free';
252
+ interface PhoneNumber {
253
+ /** Pass as `from_number_id` to `call.createPhoneCall` and as `id` to the inbound routes. */
254
+ id: string;
255
+ /** E.164. */
256
+ phone_number: string;
257
+ label: string | null;
258
+ country: string | null;
259
+ /** `local`, `mobile` or `toll_free`. */
260
+ number_type: PhoneNumberType | null;
261
+ is_active: boolean;
262
+ inbound_agent_id: string | null;
263
+ inbound_enabled: boolean;
264
+ created_at: string;
265
+ }
266
+ /** Query parameters of `phoneNumber.deprovisionInbound`: the ids returned by `provisionInbound`. At least one is required. */
267
+ interface DeprovisionInboundParams {
268
+ trunk_id?: string;
269
+ rule_id?: string;
270
+ }
271
+ /** `remaining` in the 502 `bad_gateway` body when only part of an inbound deprovision succeeded. */
272
+ interface DeprovisionInboundRemaining {
273
+ trunk_id?: string;
274
+ rule_id?: string;
275
+ }
276
+ /** Up to 50 per request; `text` non-empty, at most 100 KB (1 MB total per request). */
277
+ interface KnowledgeBaseTextSource {
278
+ title?: string;
279
+ text: string;
280
+ }
281
+ /** A URL whose host did not resolve: skipped instead of failing the whole request. */
282
+ interface KnowledgeBaseRejectedUrl {
283
+ url: string;
284
+ reason: string;
285
+ }
286
+ interface KnowledgeBaseCreateInput {
287
+ knowledge_base_name?: string;
288
+ name?: string;
289
+ description?: string;
290
+ knowledge_base_urls?: string[];
291
+ knowledge_base_texts?: KnowledgeBaseTextSource[];
292
+ chunks_to_retrieve?: Int;
293
+ similarity_threshold?: number;
294
+ instruction?: string;
295
+ use_llm_extraction?: boolean;
296
+ }
297
+ interface KnowledgeBaseUpdateInput {
298
+ name?: string;
299
+ description?: string | null;
300
+ chunks_to_retrieve?: Int;
301
+ similarity_threshold?: number;
302
+ instruction?: string | null;
303
+ use_llm_extraction?: boolean;
304
+ }
305
+ interface KnowledgeBaseAddSourcesInput {
306
+ knowledge_base_urls?: string[];
307
+ knowledge_base_texts?: KnowledgeBaseTextSource[];
308
+ }
309
+ /** Query parameters of `knowledgeBase.deleteSource`. */
310
+ interface DeleteKnowledgeBaseSourceParams {
311
+ /** The knowledge base that owns the source. */
312
+ knowledge_base_id: string;
313
+ }
314
+ /** Knowledge base statuses (lowercase). */
315
+ type KnowledgeBaseStatus = 'processing' | 'ready' | 'error';
316
+ /** Knowledge source statuses (lowercase). */
317
+ type KnowledgeSourceStatus = 'pending' | 'queued' | 'processing' | 'ready' | 'error';
318
+ /** Knowledge source kinds (lowercase). */
319
+ type KnowledgeSourceType = 'url' | 'text' | 'file';
320
+ interface KnowledgeBaseSourceSummary {
321
+ source_id: string;
322
+ type: KnowledgeSourceType;
323
+ title: string;
324
+ url?: string | null;
325
+ status: KnowledgeSourceStatus;
326
+ error?: string | null;
327
+ chunk_count: Int;
328
+ filename?: string | null;
329
+ }
330
+ interface KnowledgeBaseResponse {
331
+ knowledge_base_id: string;
332
+ knowledge_base_name: string;
333
+ description?: string | null;
334
+ status: KnowledgeBaseStatus;
335
+ chunks_to_retrieve: Int;
336
+ similarity_threshold: number;
337
+ instruction?: string | null;
338
+ use_llm_extraction: boolean;
339
+ source_count: Int;
340
+ knowledge_base_sources: KnowledgeBaseSourceSummary[];
341
+ sources: KnowledgeBaseSourceSummary[];
342
+ created_at: string;
343
+ updated_at: string;
344
+ }
345
+ /** Returned by `knowledgeBase.create` and `knowledgeBase.addSources`. */
346
+ interface KnowledgeBaseSourcesResponse extends KnowledgeBaseResponse {
347
+ rejected_urls: KnowledgeBaseRejectedUrl[];
348
+ }
349
+ interface KnowledgeBaseListResponse {
350
+ knowledge_bases: KnowledgeBaseResponse[];
351
+ }
352
+ interface PresignFileInput {
353
+ filename: string;
354
+ mime_type: string;
355
+ /** Exact upload size in bytes: the presigned URL signs it, so the PUT body must match. */
356
+ size_bytes: Int;
357
+ title?: string;
358
+ }
359
+ interface PresignFileResponse {
360
+ source_id: string;
361
+ upload_url: string;
362
+ required_headers: Record<string, string>;
363
+ expires_in: Int;
364
+ storage_key: string;
365
+ }
366
+ interface FailFileInput {
367
+ error?: string;
368
+ }
369
+ interface UpdateSourceInput {
370
+ extracted_markdown?: string;
371
+ title?: string;
372
+ }
373
+ interface UpdateChunkInput {
374
+ enabled?: boolean;
375
+ relevance_weight?: number;
376
+ }
377
+ interface KnowledgeBaseChunk {
378
+ id: string;
379
+ chunk_index: Int;
380
+ content: string;
381
+ enabled: boolean;
382
+ relevance_weight: number;
383
+ }
384
+ interface KnowledgeBaseSourceDetail {
385
+ id: string;
386
+ knowledge_base_id: string;
387
+ type: KnowledgeSourceType;
388
+ title: string;
389
+ url: string | null;
390
+ filename: string | null;
391
+ mime_type: string | null;
392
+ size_bytes: Int | null;
393
+ raw_text: string | null;
394
+ extracted_markdown: string | null;
395
+ status: KnowledgeSourceStatus;
396
+ error: string | null;
397
+ chunk_count: Int;
398
+ chunks: KnowledgeBaseChunk[];
399
+ }
400
+ interface PresignFileDownloadResponse {
401
+ download_url: string;
402
+ expires_in: Int;
403
+ filename: string;
404
+ mime_type: string | null;
405
+ }
406
+ interface ListContactsParams extends PageParams {
407
+ /** Case-insensitive match on name, phone, email or company. */
408
+ search?: string;
409
+ }
410
+ interface Contact {
411
+ id: string;
412
+ first_name: string | null;
413
+ last_name: string | null;
414
+ company: string | null;
415
+ job_title: string | null;
416
+ phone_number: string | null;
417
+ email: string | null;
418
+ street: string | null;
419
+ city: string | null;
420
+ state: string | null;
421
+ postal_code: string | null;
422
+ country: string | null;
423
+ website: string | null;
424
+ birthday: string | null;
425
+ notes: string | null;
426
+ created_at: string;
427
+ updated_at: string;
428
+ }
429
+ /** At least one of `first_name` / `last_name` is required. */
430
+ interface CreateContactInput {
431
+ first_name?: string;
432
+ last_name?: string;
433
+ company?: string;
434
+ job_title?: string;
435
+ phone_number?: string;
436
+ email?: string;
437
+ street?: string;
438
+ city?: string;
439
+ state?: string;
440
+ postal_code?: string;
441
+ country?: string;
442
+ website?: string;
443
+ notes?: string;
444
+ }
445
+ /** Contact identity kinds (lowercase). */
446
+ type ContactIdentityType = 'phone' | 'email';
447
+ interface ContactIdentityConflict {
448
+ type: ContactIdentityType;
449
+ value: string;
450
+ /** The contact that already owns this address (it is not reassigned). */
451
+ owner_contact_id: string;
452
+ }
453
+ interface CreateContactResponse {
454
+ id: string;
455
+ first_name: string;
456
+ last_name: string;
457
+ /** Usually empty. */
458
+ identity_conflicts: ContactIdentityConflict[];
459
+ }
460
+ /** Agent kinds (lowercase). */
461
+ type AgentType = 'receptionist' | 'sales_qualifier' | 'callcenter_seller' | 'personal_secretary' | 'custom';
462
+ interface Agent {
463
+ id: string;
464
+ agent_name: string;
465
+ agent_type: AgentType;
466
+ call_direction: CallDirection;
467
+ voice_id: string | null;
468
+ language: string | null;
469
+ is_active: boolean;
470
+ /** The agent's default outbound phone number id, if any. */
471
+ phone_number_id: string | null;
472
+ created_at: string;
473
+ }
474
+ /** Calendar event statuses (lowercase snake_case). */
475
+ type CalendarEventStatus = 'confirmed' | 'cancelled' | 'completed' | 'no_show';
476
+ type CalendarType = 'location' | 'team_member' | 'resource';
477
+ interface EventType {
478
+ /** Pass as `event_type_id` to `calendar.createEvent`. */
479
+ id: string;
480
+ name: string;
481
+ description: string | null;
482
+ duration_minutes: Int;
483
+ buffer_minutes: Int;
484
+ }
485
+ /** An active calendar with its active event types. */
486
+ interface Calendar {
487
+ /** Pass as `calendar_id` to `calendar.createEvent` and `calendar.listEvents`. */
488
+ id: string;
489
+ name: string;
490
+ description: string | null;
491
+ type: CalendarType;
492
+ /** IANA time zone. */
493
+ timezone: string;
494
+ event_types: EventType[];
495
+ }
496
+ interface ListCalendarEventsParams extends PageParams {
497
+ calendar_id?: string;
498
+ /** Any case is accepted (`confirmed`, `NO_SHOW`, `no_show`). */
499
+ status?: CalendarEventStatus;
500
+ /** RFC 3339 with an offset, lower bound on `start_time`. A malformed value → 400 `validation_error`. */
501
+ date_from?: string;
502
+ /** RFC 3339 with an offset, upper bound on `start_time`. A malformed value → 400 `validation_error`. */
503
+ date_to?: string;
504
+ }
505
+ interface CalendarEvent {
506
+ id: string;
507
+ calendar_id: string;
508
+ event_type_id: string;
509
+ start_time: string;
510
+ end_time: string;
511
+ timezone: string;
512
+ customer_name: string;
513
+ customer_phone: string;
514
+ customer_email: string | null;
515
+ notes: string | null;
516
+ title: string | null;
517
+ location: string | null;
518
+ /** Free-form object stored with the event (see `metadata` on create/update), or `null`. */
519
+ metadata: Record<string, unknown> | null;
520
+ status: CalendarEventStatus;
521
+ booked_via: string | null;
522
+ created_at: string;
523
+ }
524
+ interface CreateCalendarEventInput {
525
+ calendar_id: string;
526
+ event_type_id: string;
527
+ /** RFC 3339 with an offset, e.g. `2026-04-05T14:00:00Z`. Impossible dates (Feb 30, `T24:00`) → 400. */
528
+ start_time: string;
529
+ customer_name: string;
530
+ customer_phone: string;
531
+ customer_email?: string;
532
+ notes?: string;
533
+ title?: string;
534
+ location?: string;
535
+ /** Free-form object, at most 10,000 characters once serialized. Returned as `metadata` on the event. */
536
+ metadata?: Record<string, unknown>;
537
+ }
538
+ /** At least one field is required. `null` clears `customer_email`, `notes`, `title`, `location` and `metadata`. */
539
+ interface UpdateCalendarEventInput {
540
+ /** RFC 3339 with an offset; moves the event (the end follows the event type's duration). Same conflict check as create, ignoring the event itself. */
541
+ start_time?: string;
542
+ customer_name?: string;
543
+ customer_phone?: string;
544
+ customer_email?: string | null;
545
+ notes?: string | null;
546
+ title?: string | null;
547
+ location?: string | null;
548
+ /** Free-form object, at most 10,000 characters once serialized. */
549
+ metadata?: Record<string, unknown> | null;
550
+ }
551
+ interface CreateCalendarEventResponse {
552
+ id: string;
553
+ start_time: string;
554
+ end_time: string;
555
+ status: 'confirmed';
556
+ }
557
+ type MessageChannel = 'sms' | 'whatsapp' | 'email';
558
+ /** Message direction (lowercase). */
559
+ type MessageDirection = 'outbound' | 'inbound';
560
+ /**
561
+ * Message delivery statuses (lowercase). A message only moves forward: `queued` → `sent` →
562
+ * `delivered` → `read`; `failed` (any channel) and `bounced` (email) are final.
563
+ */
564
+ type MessageStatus = 'queued' | 'sent' | 'delivered' | 'read' | 'failed' | 'bounced';
565
+ interface ListMessagesParams extends PageParams {
566
+ /** Any case is accepted. */
567
+ channel?: MessageChannel;
568
+ /** Any case is accepted. */
569
+ status?: MessageStatus;
570
+ /** Exact recipient (`to_address`): an E.164 number or an email address. */
571
+ to?: string;
572
+ /** RFC 3339 with an offset, lower bound (inclusive) on `created_at`. A malformed value → 400 `validation_error`. */
573
+ date_from?: string;
574
+ /** RFC 3339 with an offset, upper bound (inclusive) on `created_at`. A malformed value → 400 `validation_error`. */
575
+ date_to?: string;
576
+ }
577
+ interface Message {
578
+ id: string;
579
+ channel: MessageChannel;
580
+ direction: MessageDirection;
581
+ status: MessageStatus;
582
+ from_address: string;
583
+ to_address: string;
584
+ subject: string | null;
585
+ body: string;
586
+ /** Provider message id, once the message was handed to the carrier or mail server. */
587
+ external_id: string | null;
588
+ /** Short reason when `status` is `failed` or `bounced`, e.g. `provider rejected the message (error 21211)`; else `null`. */
589
+ error_message: string | null;
590
+ created_at: string;
591
+ /** false when sent with a test (`rpl_test_`) key: simulated, never delivered or billed. See Test mode. */
592
+ livemode: boolean;
593
+ }
594
+ interface SendSmsInput {
595
+ to: string;
596
+ body: string;
597
+ /**
598
+ * Optional. SMS always goes out from your organization's default approved Sender ID; `from` may only
599
+ * name that sender (a phone number or another sender → 422 `sender_not_supported`).
600
+ */
601
+ from?: string;
602
+ /** Makes the send safe to retry: same key + same body → the same message, never sent twice. Same key + different body → 422 `idempotency_key_reuse`; the `Idempotency-Key` header works too. */
603
+ idempotency_key?: string;
604
+ }
605
+ interface SendWhatsappInput {
606
+ to: string;
607
+ body: string;
608
+ from?: string;
609
+ /** Attachments are not supported: a non-empty array → 422 `media_not_supported`. */
610
+ media_url?: string[];
611
+ /** Makes the send safe to retry: same key + same body → the same message, never sent twice. Same key + different body → 422 `idempotency_key_reuse`; the `Idempotency-Key` header works too. */
612
+ idempotency_key?: string;
613
+ }
614
+ interface SendEmailInput {
615
+ to: string;
616
+ subject: string;
617
+ body: string;
618
+ /** Must be the sender address configured in your SMTP email settings, if given. */
619
+ from?: string;
620
+ /** Makes the send safe to retry: same key + same body → the same message, never sent twice. Same key + different body → 422 `idempotency_key_reuse`; the `Idempotency-Key` header works too. */
621
+ idempotency_key?: string;
622
+ }
623
+ /** Returned (HTTP 202) by every send method: the message is queued, not yet delivered. */
624
+ interface SendMessageResponse {
625
+ /** The message id: read it with `message.get`, find it in `message.list` and in `message.*` webhook events. */
626
+ id: string;
627
+ /** @deprecated Same value as `id`; kept for older integrations. */
628
+ task_id: string;
629
+ channel: MessageChannel;
630
+ /** `queued` for a new send; an idempotent replay returns the message's current status. */
631
+ status: MessageStatus;
632
+ }
633
+ interface CreateTtsInput {
634
+ /** Up to 10,000 characters (Unicode code points; an emoji counts as 1). */
635
+ text: string;
636
+ /** One of the 29 built-in voice names (case-insensitive) or a raw provider voice id. */
637
+ voice?: string;
638
+ language?: string;
639
+ speed?: number;
640
+ stability?: number;
641
+ similarity_boost?: number;
642
+ style?: number;
643
+ /**
644
+ * A retry with the same key (per organization) and body returns the generation already queued
645
+ * (and billed) instead of queueing a second one. Same key, different body → 422
646
+ * `idempotency_key_reuse`. Non-empty, at most 200 characters. The `Idempotency-Key` header works too.
647
+ */
648
+ idempotency_key?: string;
649
+ }
650
+ interface CreateTtsResponse {
651
+ id: string;
652
+ /** `queued` for a new generation; an idempotent replay returns the generation's current status. */
653
+ status: TtsStatus;
654
+ character_count: Int;
655
+ }
656
+ /** Text-to-speech generation statuses (lowercase). */
657
+ type TtsStatus = 'queued' | 'processing' | 'completed' | 'failed';
658
+ interface ListTtsParams extends PageParams {
659
+ /** Any case is accepted. */
660
+ status?: TtsStatus;
661
+ }
662
+ interface TtsGeneration {
663
+ id: string;
664
+ text: string;
665
+ character_count: Int;
666
+ voice: string;
667
+ language: string;
668
+ speed: number;
669
+ stability: number;
670
+ similarity_boost: number;
671
+ style: number;
672
+ source: string;
673
+ call_id: string | null;
674
+ status: TtsStatus;
675
+ audio_url: string | null;
676
+ audio_duration_seconds: number | null;
677
+ token_cost: number | null;
678
+ error_message: string | null;
679
+ created_at: string;
680
+ /** false when created with a test (`rpl_test_`) key: a silent sample clip, never billed. See Test mode. */
681
+ livemode: boolean;
682
+ completed_at: string | null;
683
+ }
684
+ /**
685
+ * Every event type an endpoint can subscribe to. An endpoint created with an API key receives only
686
+ * the types that key's scopes can read (`call.*` → `calls:read`; `message.*`, `conversation.*`,
687
+ * `contact.opted_out` → `messages:read`; `calendar_event.*` → `calendar:read`). `webhook.test` is
688
+ * sent only by `webhookEndpoint.test`.
689
+ */
690
+ type WebhookEventType = 'call.ended' | 'call.analyzed' | 'message.received' | 'message.updated' | 'conversation.created' | 'conversation.assigned' | 'conversation.closed' | 'conversation.reopened' | 'calendar_event.created' | 'calendar_event.updated' | 'calendar_event.cancelled' | 'contact.opted_out' | 'webhook.test';
691
+ /** Why an endpoint is disabled (`enabled: false`). */
692
+ type WebhookEndpointDisabledReason = 'manual' | 'consecutive_failures' | 'api_key_revoked' | 'admin';
693
+ /** Who created the endpoint: an API key (`id` = key id) or a dashboard user. */
694
+ interface WebhookEndpointCreatedBy {
695
+ type: 'api_key' | 'user';
696
+ id: string | null;
697
+ }
698
+ interface WebhookEndpoint {
699
+ id: string;
700
+ /** HTTPS URL on a public host. */
701
+ url: string;
702
+ description: string | null;
703
+ /** Subscribed event types, or `["*"]` for every type the creating key can read. */
704
+ events: Array<WebhookEventType | '*'>;
705
+ enabled: boolean;
706
+ /** Set while `enabled` is `false`. */
707
+ disabled_reason: WebhookEndpointDisabledReason | null;
708
+ disabled_at: string | null;
709
+ /** Start of the current failure streak; the endpoint is disabled after 3 days of failures. `null` once a delivery succeeds. */
710
+ failing_since: string | null;
711
+ last_success_at: string | null;
712
+ created_by: WebhookEndpointCreatedBy;
713
+ /** End of the 24-hour overlap during which the previous secret still signs deliveries, after `rotateSecret`. */
714
+ previous_secret_expires_at: string | null;
715
+ created_at: string;
716
+ /** false for an endpoint created with a test (`rpl_test_`) key: it receives only test-mode events; live endpoints receive only live events. */
717
+ livemode: boolean;
718
+ updated_at: string;
719
+ }
720
+ /** Returned by `create` and `rotateSecret` only: the signing secret is shown once. */
721
+ interface WebhookEndpointWithSecret extends WebhookEndpoint {
722
+ /** `whsec_…` signing secret. Store it now: it cannot be read again. */
723
+ secret: string;
724
+ }
725
+ interface CreateWebhookEndpointInput {
726
+ /** HTTPS URL on a public host (no private, loopback or link-local address). Redirects are not followed. */
727
+ url: string;
728
+ /** Non-empty list of event types the key's scopes can read, or `["*"]`. */
729
+ events: Array<WebhookEventType | '*'>;
730
+ description?: string;
731
+ /**
732
+ * A retry with the same key (per organization) and body returns the endpoint already created
733
+ * (with its secret) instead of creating a second one. Same key, different body → 422
734
+ * `idempotency_key_reuse`. The `Idempotency-Key` header works too.
735
+ */
736
+ idempotency_key?: string;
737
+ }
738
+ /** At least one field. `enabled: true` re-enables a disabled endpoint, except one disabled with `api_key_revoked` (409 `webhook_endpoint_key_revoked`: create a new endpoint) or `admin` (409 `webhook_endpoint_admin_disabled`: contact support). */
739
+ interface UpdateWebhookEndpointInput {
740
+ url?: string;
741
+ events?: Array<WebhookEventType | '*'>;
742
+ /** `null` clears it. */
743
+ description?: string | null;
744
+ enabled?: boolean;
745
+ }
746
+ interface TestWebhookEndpointInput {
747
+ /** Sends a sample event of this type (`livemode: false`). Omitted: a `webhook.test` event with `data: { "object": "test" }`. */
748
+ event_type?: WebhookEventType;
749
+ }
750
+ /** Delivery statuses (lowercase). */
751
+ type WebhookDeliveryStatus = 'pending' | 'succeeded' | 'failed' | 'abandoned';
752
+ /** Error classes of a failed attempt. */
753
+ type WebhookDeliveryErrorClass = 'timeout' | 'dns' | 'ssrf_blocked' | 'tls' | 'connect' | 'http_status' | 'redirect' | 'other';
754
+ /** Result of `webhookEndpoint.test`: the test delivery after its single attempt (`succeeded` or `failed`; a test is never retried), or still `pending` after 12 seconds. */
755
+ interface TestWebhookEndpointResponse {
756
+ delivery_id: string;
757
+ event_id: string;
758
+ status: WebhookDeliveryStatus;
759
+ /** HTTP status your endpoint answered, or `null` when no response was received. */
760
+ status_code: Int | null;
761
+ duration_ms: Int | null;
762
+ error_class: WebhookDeliveryErrorClass | null;
763
+ error: string | null;
764
+ /** Start of your endpoint's response body (at most 1 KB). */
765
+ response_excerpt: string | null;
766
+ }
767
+ /** One delivery of one event to one endpoint (retries are attempts of the same delivery; a redelivery is a new one). */
768
+ interface WebhookDelivery {
769
+ /** `whdl_…` id, also sent as the `Replicer-Delivery-Id` header. */
770
+ id: string;
771
+ event_id: string;
772
+ endpoint_id: string;
773
+ event_type: WebhookEventType;
774
+ /** 0 for the automatic delivery, then 1, 2, … for each manual redelivery. */
775
+ seq: Int;
776
+ /** `true` for a redelivery. */
777
+ manual: boolean;
778
+ status: WebhookDeliveryStatus;
779
+ /** Attempts made so far (at most 9). */
780
+ attempts: Int;
781
+ /** When the next attempt is due, while `status` is `pending`. */
782
+ next_attempt_at: string | null;
783
+ last_attempt_at: string | null;
784
+ last_status_code: Int | null;
785
+ last_error_class: WebhookDeliveryErrorClass | null;
786
+ last_error: string | null;
787
+ last_duration_ms: Int | null;
788
+ created_at: string;
789
+ }
790
+ interface ListWebhookDeliveriesParams extends PageParams {
791
+ /** Omit to list the deliveries of every endpoint of the organization. */
792
+ endpoint_id?: string;
793
+ event_id?: string;
794
+ status?: WebhookDeliveryStatus;
795
+ event_type?: WebhookEventType;
796
+ /** RFC 3339 with an offset, lower bound on `created_at`. A malformed value → 400 `validation_error`. */
797
+ created_after?: string;
798
+ /** RFC 3339 with an offset, upper bound on `created_at`. A malformed value → 400 `validation_error`. */
799
+ created_before?: string;
800
+ }
801
+ interface ListWebhookDeliveryAttemptsParams extends PageParams {
802
+ /** `whdl_…` id of the delivery. Required. */
803
+ delivery_id: string;
804
+ }
805
+ /** One HTTP attempt of a delivery (oldest first). */
806
+ interface WebhookDeliveryAttempt {
807
+ /** 1 for the first attempt, up to 9. */
808
+ attempt: Int;
809
+ delivered_at: string;
810
+ success: boolean;
811
+ /** HTTP status your endpoint answered, or `null` when no response was received. */
812
+ status_code: Int | null;
813
+ duration_ms: Int | null;
814
+ error_class: WebhookDeliveryErrorClass | null;
815
+ /** A fixed description of the failure (or `HTTP <status>`); never the raw network error. `null` on success. */
816
+ error: string | null;
817
+ /** Start of your endpoint's response body (at most 1 KB). */
818
+ response_excerpt: string | null;
819
+ }
820
+ interface ListEventsParams extends PageParams {
821
+ type?: WebhookEventType;
822
+ /** Events about one resource (a call, message, conversation, calendar event or opt-out id). */
823
+ resource_id?: string;
824
+ /** RFC 3339 with an offset, lower bound on `created_at`. A malformed value → 400 `validation_error`. */
825
+ created_after?: string;
826
+ /** RFC 3339 with an offset, upper bound on `created_at`. A malformed value → 400 `validation_error`. */
827
+ created_before?: string;
828
+ }
829
+ /**
830
+ * The event envelope: exactly what is POSTed to your endpoint and what `event.get` / `event.list`
831
+ * return. Every attempt and redelivery of an event sends the same bytes.
832
+ */
833
+ interface WebhookEvent<T = Record<string, unknown>> {
834
+ /** `evt_…` id, also sent as the `Replicer-Event-Id` header. De-duplicate on it. */
835
+ id: string;
836
+ object: 'event';
837
+ type: WebhookEventType;
838
+ /** Version of the payload format, e.g. `2026-11-30`. */
839
+ api_version: string;
840
+ /** When the change happened (not when it was delivered). */
841
+ created_at: string;
842
+ /**
843
+ * `false` for events of test mode (resources created with a `rpl_test_` key; sent only to endpoints
844
+ * created with a test key) and for test sends (`webhookEndpoint.test`).
845
+ */
846
+ livemode: boolean;
847
+ /** The resource as its `/v1` GET returns it, at the moment of the change. */
848
+ data: T;
849
+ }
850
+ /**
851
+ * `WebhookEvent` with an untyped `data`: the response of `event.get` / `event.list` and the
852
+ * `WebhookEventEnvelope` schema of the OpenAPI document (a generic type cannot be a named schema).
853
+ */
854
+ interface WebhookEventEnvelope extends WebhookEvent<Record<string, unknown>> {
855
+ }
856
+ /** `data` of an event whose resource was deleted before the event was rendered. */
857
+ interface DeletedResource {
858
+ id: string;
859
+ object: 'call' | 'message' | 'conversation' | 'calendar_event' | 'opt_out';
860
+ deleted: true;
861
+ }
862
+ /** Conversation channels (lowercase). */
863
+ type ConversationChannel = 'whatsapp' | 'sms' | 'email';
864
+ /** Conversation statuses (lowercase). */
865
+ type ConversationStatus = 'open' | 'closed';
866
+ /** `data` of `conversation.*` events: one inbox thread with a customer. */
867
+ interface Conversation {
868
+ id: string;
869
+ channel: ConversationChannel;
870
+ status: ConversationStatus;
871
+ /** Your side of the thread: the business number (WhatsApp/SMS) or the inbox email address. */
872
+ endpoint: string;
873
+ /** The customer's number or email address. */
874
+ contact_address: string;
875
+ /** The customer's display name (e.g. the WhatsApp profile name), or `null`. */
876
+ contact_name: string | null;
877
+ /** The matching contact, if any. */
878
+ contact_id: string | null;
879
+ /** Email subject (email threads only). */
880
+ subject: string | null;
881
+ /** Dashboard user the conversation is assigned to, or `null`. */
882
+ assigned_user_id: string | null;
883
+ /** Messages not yet read by your team. */
884
+ unread_count: number;
885
+ last_message_at: string | null;
886
+ last_inbound_at: string | null;
887
+ /** Direction of the last message, or `null` before the first one. */
888
+ last_message_direction: MessageDirection | null;
889
+ created_at: string;
890
+ updated_at: string;
891
+ }
892
+ /** How the contact opted out (lowercase). */
893
+ type OptOutSource = 'keyword' | 'button' | 'manual';
894
+ /** `data` of `contact.opted_out`: a number that will no longer receive WhatsApp messages from you. */
895
+ interface OptOut {
896
+ id: string;
897
+ /** E.164. */
898
+ phone: string;
899
+ source: OptOutSource;
900
+ created_at: string;
901
+ }
902
+ /** `data` of a `webhook.test` event sent without `event_type`. */
903
+ interface WebhookTestData {
904
+ object: 'test';
905
+ }
906
+ /** `data` type of each event type (a deleted resource arrives as `DeletedResource` instead). */
907
+ interface WebhookEventDataMap {
908
+ 'call.ended': Call;
909
+ 'call.analyzed': Call;
910
+ 'message.received': Message;
911
+ 'message.updated': Message;
912
+ 'conversation.created': Conversation;
913
+ 'conversation.assigned': Conversation;
914
+ 'conversation.closed': Conversation;
915
+ 'conversation.reopened': Conversation;
916
+ 'calendar_event.created': CalendarEvent;
917
+ 'calendar_event.updated': CalendarEvent;
918
+ 'calendar_event.cancelled': CalendarEvent;
919
+ 'contact.opted_out': OptOut;
920
+ 'webhook.test': WebhookTestData;
921
+ }
922
+ /**
923
+ * Discriminated union of every event: narrow on `type` to get a typed `data`, e.g.
924
+ * `const event = constructEvent(input) as AnyWebhookEvent`.
925
+ */
926
+ type AnyWebhookEvent = {
927
+ [K in WebhookEventType]: Omit<WebhookEvent<WebhookEventDataMap[K] | DeletedResource>, 'type'> & {
928
+ type: K;
929
+ };
930
+ }[WebhookEventType];
931
+
932
+ export type { UpdateWebhookEndpointInput as $, Agent as A, CreateCalendarEventInput as B, CreatePhoneCallInput as C, CreateCalendarEventResponse as D, EnqueueCallResponse as E, FailFileInput as F, GetCampaignResponse as G, UpdateCalendarEventInput as H, ListMessagesParams as I, SendSmsInput as J, KnowledgeBaseCreateInput as K, ListCallsParams as L, Message as M, SendMessageResponse as N, OkResponse as O, Page as P, SendWhatsappInput as Q, SendEmailInput as R, StartCampaignResponse as S, CreateTtsInput as T, UpdateSourceInput as U, CreateTtsResponse as V, ListTtsParams as W, TtsGeneration as X, CreateWebhookEndpointInput as Y, WebhookEndpointWithSecret as Z, WebhookEndpoint as _, CancelCampaignPendingResponse as a, TestWebhookEndpointInput as a0, TestWebhookEndpointResponse as a1, ListWebhookDeliveriesParams as a2, WebhookDelivery as a3, ListWebhookDeliveryAttemptsParams as a4, WebhookDeliveryAttempt as a5, ListEventsParams as a6, WebhookEvent as a7, AgentType as a8, AnyWebhookEvent as a9, KnowledgeBaseTextSource as aA, KnowledgeSourceStatus as aB, KnowledgeSourceType as aC, MessageChannel as aD, MessageDirection as aE, MessageStatus as aF, OptOut as aG, OptOutSource as aH, Pagination as aI, PhoneNumberType as aJ, TtsStatus as aK, WebhookDeliveryErrorClass as aL, WebhookDeliveryStatus as aM, WebhookEndpointCreatedBy as aN, WebhookEndpointDisabledReason as aO, WebhookEventDataMap as aP, WebhookEventEnvelope as aQ, WebhookEventType as aR, WebhookTestData as aS, ApiErrorCode as aa, CalendarEventStatus as ab, CalendarType as ac, CallDirection as ad, CallSentiment as ae, CallStatus as af, CampaignListItem as ag, CampaignStatus as ah, CancelCallInput as ai, CancelCampaignPendingInput as aj, ContactIdentityConflict as ak, ContactIdentityType as al, Conversation as am, ConversationChannel as an, ConversationStatus as ao, CreateCampaignResponse as ap, DeleteKnowledgeBaseSourceParams as aq, DeletedResource as ar, DeprovisionInboundParams as as, DeprovisionInboundRemaining as at, EventType as au, Int as av, KnowledgeBaseChunk as aw, KnowledgeBaseRejectedUrl as ax, KnowledgeBaseSourceSummary as ay, KnowledgeBaseStatus as az, Call as b, CreateCampaignInput as c, Campaign as d, ListCampaignsParams as e, PageParams as f, PhoneNumber as g, ProvisionInboundInput as h, ProvisionInboundResponse as i, KnowledgeBaseSourcesResponse as j, KnowledgeBaseResponse as k, KnowledgeBaseListResponse as l, KnowledgeBaseAddSourcesInput as m, KnowledgeBaseUpdateInput as n, PresignFileInput as o, PresignFileResponse as p, UpdateChunkInput as q, KnowledgeBaseSourceDetail as r, PresignFileDownloadResponse as s, ListContactsParams as t, Contact as u, CreateContactInput as v, CreateContactResponse as w, Calendar as x, ListCalendarEventsParams as y, CalendarEvent as z };