pollax 1.0.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 +234 -0
- package/dist/index.d.mts +795 -0
- package/dist/index.d.ts +795 -0
- package/dist/index.js +907 -0
- package/dist/index.mjs +856 -0
- package/package.json +60 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,856 @@
|
|
|
1
|
+
// src/client.ts
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
|
|
4
|
+
// src/resources/agents.ts
|
|
5
|
+
var Agents = class {
|
|
6
|
+
constructor(request) {
|
|
7
|
+
this.request = request;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Create a new AI agent
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const agent = await pollax.agents.create({
|
|
14
|
+
* name: 'Customer Support Agent',
|
|
15
|
+
* system_prompt: 'You are a helpful customer support agent.',
|
|
16
|
+
* voice_id: 'alloy',
|
|
17
|
+
* model: 'gpt-4',
|
|
18
|
+
* });
|
|
19
|
+
*/
|
|
20
|
+
async create(params) {
|
|
21
|
+
return this.request({
|
|
22
|
+
method: "POST",
|
|
23
|
+
url: "/api/v1/agents",
|
|
24
|
+
data: params
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* List all agents
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* const agents = await pollax.agents.list({ is_active: true });
|
|
32
|
+
*/
|
|
33
|
+
async list(params) {
|
|
34
|
+
return this.request({
|
|
35
|
+
method: "GET",
|
|
36
|
+
url: "/api/v1/agents",
|
|
37
|
+
params
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Get a single agent by ID
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* const agent = await pollax.agents.retrieve('agent_123');
|
|
45
|
+
*/
|
|
46
|
+
async retrieve(agentId) {
|
|
47
|
+
return this.request({
|
|
48
|
+
method: "GET",
|
|
49
|
+
url: `/api/v1/agents/${agentId}`
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Update an agent
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* const agent = await pollax.agents.update('agent_123', {
|
|
57
|
+
* name: 'Updated Agent Name',
|
|
58
|
+
* is_active: false,
|
|
59
|
+
* });
|
|
60
|
+
*/
|
|
61
|
+
async update(agentId, params) {
|
|
62
|
+
return this.request({
|
|
63
|
+
method: "PUT",
|
|
64
|
+
url: `/api/v1/agents/${agentId}`,
|
|
65
|
+
data: params
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Delete an agent
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* await pollax.agents.delete('agent_123');
|
|
73
|
+
*/
|
|
74
|
+
async delete(agentId) {
|
|
75
|
+
return this.request({
|
|
76
|
+
method: "DELETE",
|
|
77
|
+
url: `/api/v1/agents/${agentId}`
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Test an agent with a sample prompt
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* const response = await pollax.agents.test('agent_123', {
|
|
85
|
+
* message: 'Hello, how can you help me?',
|
|
86
|
+
* });
|
|
87
|
+
*/
|
|
88
|
+
async test(agentId, params) {
|
|
89
|
+
return this.request({
|
|
90
|
+
method: "POST",
|
|
91
|
+
url: `/api/v1/agents/${agentId}/test`,
|
|
92
|
+
data: params
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// src/resources/calls.ts
|
|
98
|
+
var Calls = class {
|
|
99
|
+
constructor(request) {
|
|
100
|
+
this.request = request;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Create a new voice call
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* const call = await pollax.calls.create({
|
|
107
|
+
* agent_id: 'agent_123',
|
|
108
|
+
* to_number: '+1234567890',
|
|
109
|
+
* });
|
|
110
|
+
*/
|
|
111
|
+
async create(params) {
|
|
112
|
+
return this.request({
|
|
113
|
+
method: "POST",
|
|
114
|
+
url: "/api/v1/calls",
|
|
115
|
+
data: params
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* List all calls
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* const calls = await pollax.calls.list({
|
|
123
|
+
* agent_id: 'agent_123',
|
|
124
|
+
* status: 'completed',
|
|
125
|
+
* });
|
|
126
|
+
*/
|
|
127
|
+
async list(params) {
|
|
128
|
+
return this.request({
|
|
129
|
+
method: "GET",
|
|
130
|
+
url: "/api/v1/calls",
|
|
131
|
+
params
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Get a single call by SID
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* const call = await pollax.calls.retrieve('CA123456789');
|
|
139
|
+
*/
|
|
140
|
+
async retrieve(callSid) {
|
|
141
|
+
return this.request({
|
|
142
|
+
method: "GET",
|
|
143
|
+
url: `/api/v1/calls/${callSid}`
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* End an active call
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* await pollax.calls.end('CA123456789');
|
|
151
|
+
*/
|
|
152
|
+
async end(callSid) {
|
|
153
|
+
return this.request({
|
|
154
|
+
method: "POST",
|
|
155
|
+
url: `/api/v1/calls/${callSid}/end`
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Transfer a call to another number
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* await pollax.calls.transfer('CA123456789', {
|
|
163
|
+
* to_number: '+1234567890',
|
|
164
|
+
* });
|
|
165
|
+
*/
|
|
166
|
+
async transfer(callSid, params) {
|
|
167
|
+
return this.request({
|
|
168
|
+
method: "POST",
|
|
169
|
+
url: `/api/v1/calls/${callSid}/transfer`,
|
|
170
|
+
data: params
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Get call transcript
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* const transcript = await pollax.calls.getTranscript('CA123456789');
|
|
178
|
+
*/
|
|
179
|
+
async getTranscript(callSid) {
|
|
180
|
+
return this.request({
|
|
181
|
+
method: "GET",
|
|
182
|
+
url: `/api/v1/calls/${callSid}/transcript`
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Get call recording URL
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* const recording = await pollax.calls.getRecording('CA123456789');
|
|
190
|
+
*/
|
|
191
|
+
async getRecording(callSid) {
|
|
192
|
+
return this.request({
|
|
193
|
+
method: "GET",
|
|
194
|
+
url: `/api/v1/calls/${callSid}/recording`
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
// src/resources/campaigns.ts
|
|
200
|
+
var Campaigns = class {
|
|
201
|
+
constructor(request) {
|
|
202
|
+
this.request = request;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Create a new campaign
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* const campaign = await pollax.campaigns.create({
|
|
209
|
+
* name: 'Q1 Outreach Campaign',
|
|
210
|
+
* agent_id: 'agent_123',
|
|
211
|
+
* contacts: [
|
|
212
|
+
* { name: 'John Doe', phone: '+1234567890' },
|
|
213
|
+
* { name: 'Jane Smith', phone: '+0987654321' },
|
|
214
|
+
* ],
|
|
215
|
+
* });
|
|
216
|
+
*/
|
|
217
|
+
async create(params) {
|
|
218
|
+
return this.request({
|
|
219
|
+
method: "POST",
|
|
220
|
+
url: "/api/v1/campaigns",
|
|
221
|
+
data: params
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* List all campaigns
|
|
226
|
+
*
|
|
227
|
+
* @example
|
|
228
|
+
* const campaigns = await pollax.campaigns.list();
|
|
229
|
+
*/
|
|
230
|
+
async list() {
|
|
231
|
+
return this.request({
|
|
232
|
+
method: "GET",
|
|
233
|
+
url: "/api/v1/campaigns"
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Get a single campaign by ID
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* const campaign = await pollax.campaigns.retrieve('campaign_123');
|
|
241
|
+
*/
|
|
242
|
+
async retrieve(campaignId) {
|
|
243
|
+
return this.request({
|
|
244
|
+
method: "GET",
|
|
245
|
+
url: `/api/v1/campaigns/${campaignId}`
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Update a campaign
|
|
250
|
+
*
|
|
251
|
+
* @example
|
|
252
|
+
* const campaign = await pollax.campaigns.update('campaign_123', {
|
|
253
|
+
* status: 'paused',
|
|
254
|
+
* });
|
|
255
|
+
*/
|
|
256
|
+
async update(campaignId, params) {
|
|
257
|
+
return this.request({
|
|
258
|
+
method: "PUT",
|
|
259
|
+
url: `/api/v1/campaigns/${campaignId}`,
|
|
260
|
+
data: params
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Delete a campaign
|
|
265
|
+
*
|
|
266
|
+
* @example
|
|
267
|
+
* await pollax.campaigns.delete('campaign_123');
|
|
268
|
+
*/
|
|
269
|
+
async delete(campaignId) {
|
|
270
|
+
return this.request({
|
|
271
|
+
method: "DELETE",
|
|
272
|
+
url: `/api/v1/campaigns/${campaignId}`
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Start a campaign
|
|
277
|
+
*
|
|
278
|
+
* @example
|
|
279
|
+
* await pollax.campaigns.start('campaign_123');
|
|
280
|
+
*/
|
|
281
|
+
async start(campaignId) {
|
|
282
|
+
return this.request({
|
|
283
|
+
method: "POST",
|
|
284
|
+
url: `/api/v1/campaigns/${campaignId}/start`
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Pause a running campaign
|
|
289
|
+
*
|
|
290
|
+
* @example
|
|
291
|
+
* await pollax.campaigns.pause('campaign_123');
|
|
292
|
+
*/
|
|
293
|
+
async pause(campaignId) {
|
|
294
|
+
return this.request({
|
|
295
|
+
method: "POST",
|
|
296
|
+
url: `/api/v1/campaigns/${campaignId}/pause`
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Upload contacts to a campaign via CSV
|
|
301
|
+
*
|
|
302
|
+
* @example
|
|
303
|
+
* const campaign = await pollax.campaigns.uploadContacts('campaign_123', csvFile);
|
|
304
|
+
*/
|
|
305
|
+
async uploadContacts(campaignId, file) {
|
|
306
|
+
const formData = new FormData();
|
|
307
|
+
formData.append("file", file);
|
|
308
|
+
return this.request({
|
|
309
|
+
method: "POST",
|
|
310
|
+
url: `/api/v1/campaigns/${campaignId}/upload`,
|
|
311
|
+
data: formData,
|
|
312
|
+
headers: {
|
|
313
|
+
"Content-Type": "multipart/form-data"
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Get campaign statistics
|
|
319
|
+
*
|
|
320
|
+
* @example
|
|
321
|
+
* const stats = await pollax.campaigns.getStats('campaign_123');
|
|
322
|
+
*/
|
|
323
|
+
async getStats(campaignId) {
|
|
324
|
+
return this.request({
|
|
325
|
+
method: "GET",
|
|
326
|
+
url: `/api/v1/campaigns/${campaignId}/stats`
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
// src/resources/knowledge.ts
|
|
332
|
+
var Knowledge = class {
|
|
333
|
+
constructor(request) {
|
|
334
|
+
this.request = request;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Upload a document to the knowledge base
|
|
338
|
+
*
|
|
339
|
+
* @example
|
|
340
|
+
* const doc = await pollax.knowledge.upload({
|
|
341
|
+
* name: 'Product Manual',
|
|
342
|
+
* file: pdfFile,
|
|
343
|
+
* type: 'pdf',
|
|
344
|
+
* });
|
|
345
|
+
*/
|
|
346
|
+
async upload(params) {
|
|
347
|
+
const formData = new FormData();
|
|
348
|
+
formData.append("name", params.name);
|
|
349
|
+
if (params.file) {
|
|
350
|
+
formData.append("file", params.file);
|
|
351
|
+
}
|
|
352
|
+
if (params.content) {
|
|
353
|
+
formData.append("content", params.content);
|
|
354
|
+
}
|
|
355
|
+
if (params.url) {
|
|
356
|
+
formData.append("url", params.url);
|
|
357
|
+
}
|
|
358
|
+
if (params.type) {
|
|
359
|
+
formData.append("type", params.type);
|
|
360
|
+
}
|
|
361
|
+
return this.request({
|
|
362
|
+
method: "POST",
|
|
363
|
+
url: "/api/v1/knowledge",
|
|
364
|
+
data: formData,
|
|
365
|
+
headers: {
|
|
366
|
+
"Content-Type": "multipart/form-data"
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* List all knowledge documents
|
|
372
|
+
*
|
|
373
|
+
* @example
|
|
374
|
+
* const documents = await pollax.knowledge.list();
|
|
375
|
+
*/
|
|
376
|
+
async list() {
|
|
377
|
+
return this.request({
|
|
378
|
+
method: "GET",
|
|
379
|
+
url: "/api/v1/knowledge"
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Get a single document by ID
|
|
384
|
+
*
|
|
385
|
+
* @example
|
|
386
|
+
* const doc = await pollax.knowledge.retrieve('doc_123');
|
|
387
|
+
*/
|
|
388
|
+
async retrieve(documentId) {
|
|
389
|
+
return this.request({
|
|
390
|
+
method: "GET",
|
|
391
|
+
url: `/api/v1/knowledge/${documentId}`
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Delete a document
|
|
396
|
+
*
|
|
397
|
+
* @example
|
|
398
|
+
* await pollax.knowledge.delete('doc_123');
|
|
399
|
+
*/
|
|
400
|
+
async delete(documentId) {
|
|
401
|
+
return this.request({
|
|
402
|
+
method: "DELETE",
|
|
403
|
+
url: `/api/v1/knowledge/${documentId}`
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Search the knowledge base
|
|
408
|
+
*
|
|
409
|
+
* @example
|
|
410
|
+
* const results = await pollax.knowledge.search({
|
|
411
|
+
* query: 'How do I reset my password?',
|
|
412
|
+
* limit: 5,
|
|
413
|
+
* });
|
|
414
|
+
*/
|
|
415
|
+
async search(params) {
|
|
416
|
+
return this.request({
|
|
417
|
+
method: "POST",
|
|
418
|
+
url: "/api/v1/knowledge/search",
|
|
419
|
+
data: params
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
|
|
424
|
+
// src/resources/analytics.ts
|
|
425
|
+
var Analytics = class {
|
|
426
|
+
constructor(request) {
|
|
427
|
+
this.request = request;
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Get dashboard statistics
|
|
431
|
+
*
|
|
432
|
+
* @example
|
|
433
|
+
* const stats = await pollax.analytics.getStats();
|
|
434
|
+
*/
|
|
435
|
+
async getStats() {
|
|
436
|
+
return this.request({
|
|
437
|
+
method: "GET",
|
|
438
|
+
url: "/api/v1/analytics/stats"
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Get call volume over time
|
|
443
|
+
*
|
|
444
|
+
* @example
|
|
445
|
+
* const volume = await pollax.analytics.getCallVolume({ period: '7d' });
|
|
446
|
+
*/
|
|
447
|
+
async getCallVolume(params) {
|
|
448
|
+
return this.request({
|
|
449
|
+
method: "GET",
|
|
450
|
+
url: "/api/v1/analytics/call-volume",
|
|
451
|
+
params
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Get agent performance metrics
|
|
456
|
+
*
|
|
457
|
+
* @example
|
|
458
|
+
* const performance = await pollax.analytics.getAgentPerformance('agent_123');
|
|
459
|
+
*/
|
|
460
|
+
async getAgentPerformance(agentId) {
|
|
461
|
+
return this.request({
|
|
462
|
+
method: "GET",
|
|
463
|
+
url: `/api/v1/analytics/agents/${agentId}/performance`
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Export analytics data
|
|
468
|
+
*
|
|
469
|
+
* @example
|
|
470
|
+
* const csvData = await pollax.analytics.export({
|
|
471
|
+
* start_date: '2024-01-01',
|
|
472
|
+
* end_date: '2024-01-31',
|
|
473
|
+
* format: 'csv',
|
|
474
|
+
* });
|
|
475
|
+
*/
|
|
476
|
+
async export(params) {
|
|
477
|
+
return this.request({
|
|
478
|
+
method: "GET",
|
|
479
|
+
url: "/api/v1/analytics/export",
|
|
480
|
+
params
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
};
|
|
484
|
+
|
|
485
|
+
// src/resources/integrations.ts
|
|
486
|
+
var Integrations = class {
|
|
487
|
+
constructor(request) {
|
|
488
|
+
this.request = request;
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Create a new integration
|
|
492
|
+
*
|
|
493
|
+
* @example
|
|
494
|
+
* const integration = await pollax.integrations.create({
|
|
495
|
+
* name: 'Salesforce CRM',
|
|
496
|
+
* type: 'salesforce',
|
|
497
|
+
* config: {
|
|
498
|
+
* client_id: '...',
|
|
499
|
+
* client_secret: '...',
|
|
500
|
+
* },
|
|
501
|
+
* });
|
|
502
|
+
*/
|
|
503
|
+
async create(params) {
|
|
504
|
+
return this.request({
|
|
505
|
+
method: "POST",
|
|
506
|
+
url: "/api/v1/integrations",
|
|
507
|
+
data: params
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
* List all integrations
|
|
512
|
+
*
|
|
513
|
+
* @example
|
|
514
|
+
* const integrations = await pollax.integrations.list();
|
|
515
|
+
*/
|
|
516
|
+
async list() {
|
|
517
|
+
return this.request({
|
|
518
|
+
method: "GET",
|
|
519
|
+
url: "/api/v1/integrations"
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
/**
|
|
523
|
+
* Get a single integration by ID
|
|
524
|
+
*
|
|
525
|
+
* @example
|
|
526
|
+
* const integration = await pollax.integrations.retrieve('int_123');
|
|
527
|
+
*/
|
|
528
|
+
async retrieve(integrationId) {
|
|
529
|
+
return this.request({
|
|
530
|
+
method: "GET",
|
|
531
|
+
url: `/api/v1/integrations/${integrationId}`
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* Delete an integration
|
|
536
|
+
*
|
|
537
|
+
* @example
|
|
538
|
+
* await pollax.integrations.delete('int_123');
|
|
539
|
+
*/
|
|
540
|
+
async delete(integrationId) {
|
|
541
|
+
return this.request({
|
|
542
|
+
method: "DELETE",
|
|
543
|
+
url: `/api/v1/integrations/${integrationId}`
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
};
|
|
547
|
+
|
|
548
|
+
// src/resources/phone-numbers.ts
|
|
549
|
+
var PhoneNumbers = class {
|
|
550
|
+
constructor(request) {
|
|
551
|
+
this.request = request;
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* List all phone numbers
|
|
555
|
+
*
|
|
556
|
+
* @example
|
|
557
|
+
* const numbers = await pollax.phoneNumbers.list();
|
|
558
|
+
*/
|
|
559
|
+
async list() {
|
|
560
|
+
return this.request({
|
|
561
|
+
method: "GET",
|
|
562
|
+
url: "/api/v1/phone-numbers"
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
566
|
+
* Search available phone numbers
|
|
567
|
+
*
|
|
568
|
+
* @example
|
|
569
|
+
* const numbers = await pollax.phoneNumbers.search({
|
|
570
|
+
* country_code: 'US',
|
|
571
|
+
* area_code: '415',
|
|
572
|
+
* });
|
|
573
|
+
*/
|
|
574
|
+
async search(params) {
|
|
575
|
+
return this.request({
|
|
576
|
+
method: "GET",
|
|
577
|
+
url: "/api/v1/phone-numbers/search",
|
|
578
|
+
params
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
/**
|
|
582
|
+
* Purchase a phone number
|
|
583
|
+
*
|
|
584
|
+
* @example
|
|
585
|
+
* const number = await pollax.phoneNumbers.purchase('+14155551234');
|
|
586
|
+
*/
|
|
587
|
+
async purchase(phoneNumber) {
|
|
588
|
+
return this.request({
|
|
589
|
+
method: "POST",
|
|
590
|
+
url: "/api/v1/phone-numbers",
|
|
591
|
+
data: { phone_number: phoneNumber }
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
/**
|
|
595
|
+
* Release a phone number
|
|
596
|
+
*
|
|
597
|
+
* @example
|
|
598
|
+
* await pollax.phoneNumbers.release('num_123');
|
|
599
|
+
*/
|
|
600
|
+
async release(numberId) {
|
|
601
|
+
return this.request({
|
|
602
|
+
method: "DELETE",
|
|
603
|
+
url: `/api/v1/phone-numbers/${numberId}`
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
};
|
|
607
|
+
|
|
608
|
+
// src/resources/api-keys.ts
|
|
609
|
+
var ApiKeys = class {
|
|
610
|
+
constructor(request) {
|
|
611
|
+
this.request = request;
|
|
612
|
+
}
|
|
613
|
+
/**
|
|
614
|
+
* Create a new API key
|
|
615
|
+
*
|
|
616
|
+
* @example
|
|
617
|
+
* const apiKey = await pollax.apiKeys.create({
|
|
618
|
+
* name: 'Production Key',
|
|
619
|
+
* permissions: ['read', 'write'],
|
|
620
|
+
* });
|
|
621
|
+
*/
|
|
622
|
+
async create(params) {
|
|
623
|
+
return this.request({
|
|
624
|
+
method: "POST",
|
|
625
|
+
url: "/api/v1/api-keys",
|
|
626
|
+
data: params
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* List all API keys
|
|
631
|
+
*
|
|
632
|
+
* @example
|
|
633
|
+
* const keys = await pollax.apiKeys.list();
|
|
634
|
+
*/
|
|
635
|
+
async list() {
|
|
636
|
+
return this.request({
|
|
637
|
+
method: "GET",
|
|
638
|
+
url: "/api/v1/api-keys"
|
|
639
|
+
});
|
|
640
|
+
}
|
|
641
|
+
/**
|
|
642
|
+
* Revoke an API key
|
|
643
|
+
*
|
|
644
|
+
* @example
|
|
645
|
+
* await pollax.apiKeys.revoke('key_123');
|
|
646
|
+
*/
|
|
647
|
+
async revoke(keyId) {
|
|
648
|
+
return this.request({
|
|
649
|
+
method: "DELETE",
|
|
650
|
+
url: `/api/v1/api-keys/${keyId}`
|
|
651
|
+
});
|
|
652
|
+
}
|
|
653
|
+
};
|
|
654
|
+
|
|
655
|
+
// src/resources/voice-cloning.ts
|
|
656
|
+
var VoiceCloning = class {
|
|
657
|
+
constructor(request) {
|
|
658
|
+
this.request = request;
|
|
659
|
+
}
|
|
660
|
+
/**
|
|
661
|
+
* Create a new voice profile
|
|
662
|
+
*
|
|
663
|
+
* @example
|
|
664
|
+
* const voice = await pollax.voiceCloning.create({
|
|
665
|
+
* name: 'Custom Voice',
|
|
666
|
+
* description: 'My custom voice profile',
|
|
667
|
+
* audio_files: [audioFile1, audioFile2],
|
|
668
|
+
* });
|
|
669
|
+
*/
|
|
670
|
+
async create(params) {
|
|
671
|
+
const formData = new FormData();
|
|
672
|
+
formData.append("name", params.name);
|
|
673
|
+
if (params.description) {
|
|
674
|
+
formData.append("description", params.description);
|
|
675
|
+
}
|
|
676
|
+
if (params.provider) {
|
|
677
|
+
formData.append("provider", params.provider);
|
|
678
|
+
}
|
|
679
|
+
params.audio_files.forEach((file, index) => {
|
|
680
|
+
formData.append("audio_files", file, `audio_${index}.wav`);
|
|
681
|
+
});
|
|
682
|
+
return this.request({
|
|
683
|
+
method: "POST",
|
|
684
|
+
url: "/api/v1/voice-cloning",
|
|
685
|
+
data: formData,
|
|
686
|
+
headers: {
|
|
687
|
+
"Content-Type": "multipart/form-data"
|
|
688
|
+
}
|
|
689
|
+
});
|
|
690
|
+
}
|
|
691
|
+
/**
|
|
692
|
+
* List all voice profiles
|
|
693
|
+
*
|
|
694
|
+
* @example
|
|
695
|
+
* const voices = await pollax.voiceCloning.list();
|
|
696
|
+
*/
|
|
697
|
+
async list() {
|
|
698
|
+
return this.request({
|
|
699
|
+
method: "GET",
|
|
700
|
+
url: "/api/v1/voice-cloning"
|
|
701
|
+
});
|
|
702
|
+
}
|
|
703
|
+
/**
|
|
704
|
+
* Get a single voice profile by ID
|
|
705
|
+
*
|
|
706
|
+
* @example
|
|
707
|
+
* const voice = await pollax.voiceCloning.retrieve('voice_123');
|
|
708
|
+
*/
|
|
709
|
+
async retrieve(voiceId) {
|
|
710
|
+
return this.request({
|
|
711
|
+
method: "GET",
|
|
712
|
+
url: `/api/v1/voice-cloning/${voiceId}`
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
/**
|
|
716
|
+
* Delete a voice profile
|
|
717
|
+
*
|
|
718
|
+
* @example
|
|
719
|
+
* await pollax.voiceCloning.delete('voice_123');
|
|
720
|
+
*/
|
|
721
|
+
async delete(voiceId) {
|
|
722
|
+
return this.request({
|
|
723
|
+
method: "DELETE",
|
|
724
|
+
url: `/api/v1/voice-cloning/${voiceId}`
|
|
725
|
+
});
|
|
726
|
+
}
|
|
727
|
+
};
|
|
728
|
+
|
|
729
|
+
// src/errors.ts
|
|
730
|
+
var PollaxError = class _PollaxError extends Error {
|
|
731
|
+
constructor(message, statusCode = 0, response) {
|
|
732
|
+
super(message);
|
|
733
|
+
this.name = "PollaxError";
|
|
734
|
+
this.statusCode = statusCode;
|
|
735
|
+
this.response = response;
|
|
736
|
+
if (Error.captureStackTrace) {
|
|
737
|
+
Error.captureStackTrace(this, _PollaxError);
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
};
|
|
741
|
+
var AuthenticationError = class extends PollaxError {
|
|
742
|
+
constructor(message = "Authentication failed", response) {
|
|
743
|
+
super(message, 401, response);
|
|
744
|
+
this.name = "AuthenticationError";
|
|
745
|
+
}
|
|
746
|
+
};
|
|
747
|
+
var NotFoundError = class extends PollaxError {
|
|
748
|
+
constructor(message = "Resource not found", response) {
|
|
749
|
+
super(message, 404, response);
|
|
750
|
+
this.name = "NotFoundError";
|
|
751
|
+
}
|
|
752
|
+
};
|
|
753
|
+
var RateLimitError = class extends PollaxError {
|
|
754
|
+
constructor(message = "Rate limit exceeded", response) {
|
|
755
|
+
super(message, 429, response);
|
|
756
|
+
this.name = "RateLimitError";
|
|
757
|
+
}
|
|
758
|
+
};
|
|
759
|
+
var ValidationError = class extends PollaxError {
|
|
760
|
+
constructor(message = "Validation error", response) {
|
|
761
|
+
super(message, 400, response);
|
|
762
|
+
this.name = "ValidationError";
|
|
763
|
+
}
|
|
764
|
+
};
|
|
765
|
+
|
|
766
|
+
// src/client.ts
|
|
767
|
+
var Pollax = class {
|
|
768
|
+
constructor(config) {
|
|
769
|
+
if (!config.apiKey) {
|
|
770
|
+
throw new PollaxError("API key is required. Get one at https://pollax.ai/settings/api-keys");
|
|
771
|
+
}
|
|
772
|
+
this.maxRetries = config.maxRetries || 3;
|
|
773
|
+
const headers = {
|
|
774
|
+
"Authorization": `Bearer ${config.apiKey}`,
|
|
775
|
+
"Content-Type": "application/json",
|
|
776
|
+
"User-Agent": "Pollax-SDK-TypeScript/1.0.0"
|
|
777
|
+
};
|
|
778
|
+
if (config.tenantId) {
|
|
779
|
+
headers["X-Tenant-ID"] = config.tenantId;
|
|
780
|
+
}
|
|
781
|
+
this.client = axios.create({
|
|
782
|
+
baseURL: config.baseURL || "https://api.pollax.ai",
|
|
783
|
+
timeout: config.timeout || 3e4,
|
|
784
|
+
headers
|
|
785
|
+
});
|
|
786
|
+
this.client.interceptors.response.use(
|
|
787
|
+
(response) => response,
|
|
788
|
+
async (error) => {
|
|
789
|
+
if (error.response) {
|
|
790
|
+
const { status, data } = error.response;
|
|
791
|
+
if (status === 429 && this.maxRetries > 0) {
|
|
792
|
+
const retryAfter = parseInt(error.response.headers["retry-after"] || "1", 10);
|
|
793
|
+
await this.sleep(retryAfter * 1e3);
|
|
794
|
+
return this.client.request(error.config);
|
|
795
|
+
}
|
|
796
|
+
throw new PollaxError(
|
|
797
|
+
data.error || data.detail || "An error occurred",
|
|
798
|
+
status,
|
|
799
|
+
data
|
|
800
|
+
);
|
|
801
|
+
}
|
|
802
|
+
throw new PollaxError(
|
|
803
|
+
error.message || "Network error occurred",
|
|
804
|
+
0,
|
|
805
|
+
error
|
|
806
|
+
);
|
|
807
|
+
}
|
|
808
|
+
);
|
|
809
|
+
this.agents = new Agents(this.request.bind(this));
|
|
810
|
+
this.calls = new Calls(this.request.bind(this));
|
|
811
|
+
this.campaigns = new Campaigns(this.request.bind(this));
|
|
812
|
+
this.knowledge = new Knowledge(this.request.bind(this));
|
|
813
|
+
this.analytics = new Analytics(this.request.bind(this));
|
|
814
|
+
this.integrations = new Integrations(this.request.bind(this));
|
|
815
|
+
this.phoneNumbers = new PhoneNumbers(this.request.bind(this));
|
|
816
|
+
this.apiKeys = new ApiKeys(this.request.bind(this));
|
|
817
|
+
this.voiceCloning = new VoiceCloning(this.request.bind(this));
|
|
818
|
+
}
|
|
819
|
+
/**
|
|
820
|
+
* Make an HTTP request with automatic retries
|
|
821
|
+
*/
|
|
822
|
+
async request(config, retries = 0) {
|
|
823
|
+
try {
|
|
824
|
+
const response = await this.client.request(config);
|
|
825
|
+
return response.data;
|
|
826
|
+
} catch (error) {
|
|
827
|
+
if (retries < this.maxRetries && (error.code === "ECONNRESET" || error.code === "ETIMEDOUT" || error.response && error.response.status >= 500)) {
|
|
828
|
+
const delay = Math.pow(2, retries) * 1e3;
|
|
829
|
+
await this.sleep(delay);
|
|
830
|
+
return this.request(config, retries + 1);
|
|
831
|
+
}
|
|
832
|
+
throw error;
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
sleep(ms) {
|
|
836
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
837
|
+
}
|
|
838
|
+
};
|
|
839
|
+
export {
|
|
840
|
+
Agents,
|
|
841
|
+
Analytics,
|
|
842
|
+
ApiKeys,
|
|
843
|
+
AuthenticationError,
|
|
844
|
+
Calls,
|
|
845
|
+
Campaigns,
|
|
846
|
+
Integrations,
|
|
847
|
+
Knowledge,
|
|
848
|
+
NotFoundError,
|
|
849
|
+
PhoneNumbers,
|
|
850
|
+
Pollax,
|
|
851
|
+
PollaxError,
|
|
852
|
+
RateLimitError,
|
|
853
|
+
ValidationError,
|
|
854
|
+
VoiceCloning,
|
|
855
|
+
Pollax as default
|
|
856
|
+
};
|