@sendly/node 3.5.3 → 3.5.4
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 +249 -0
- package/dist/index.js +6 -3
- package/dist/index.mjs +6 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -122,6 +122,54 @@ console.log(`Status: ${message.status}`);
|
|
|
122
122
|
console.log(`Delivered: ${message.deliveredAt}`);
|
|
123
123
|
```
|
|
124
124
|
|
|
125
|
+
### Scheduling Messages
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
// Schedule a message for future delivery
|
|
129
|
+
const scheduled = await sendly.messages.schedule({
|
|
130
|
+
to: '+15551234567',
|
|
131
|
+
text: 'Your appointment is tomorrow!',
|
|
132
|
+
scheduledAt: '2025-01-15T10:00:00Z'
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
console.log(`Scheduled: ${scheduled.id}`);
|
|
136
|
+
console.log(`Will send at: ${scheduled.scheduledAt}`);
|
|
137
|
+
|
|
138
|
+
// List scheduled messages
|
|
139
|
+
const { data: scheduledMessages } = await sendly.messages.listScheduled();
|
|
140
|
+
|
|
141
|
+
// Get a specific scheduled message
|
|
142
|
+
const msg = await sendly.messages.getScheduled('sched_xxx');
|
|
143
|
+
|
|
144
|
+
// Cancel a scheduled message (refunds credits)
|
|
145
|
+
const result = await sendly.messages.cancelScheduled('sched_xxx');
|
|
146
|
+
console.log(`Refunded: ${result.creditsRefunded} credits`);
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Batch Messages
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
// Send multiple messages in one API call (up to 1000)
|
|
153
|
+
const batch = await sendly.messages.sendBatch({
|
|
154
|
+
messages: [
|
|
155
|
+
{ to: '+15551234567', text: 'Hello User 1!' },
|
|
156
|
+
{ to: '+15559876543', text: 'Hello User 2!' },
|
|
157
|
+
{ to: '+15551112222', text: 'Hello User 3!' }
|
|
158
|
+
]
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
console.log(`Batch ID: ${batch.batchId}`);
|
|
162
|
+
console.log(`Queued: ${batch.queued}`);
|
|
163
|
+
console.log(`Failed: ${batch.failed}`);
|
|
164
|
+
console.log(`Credits used: ${batch.creditsUsed}`);
|
|
165
|
+
|
|
166
|
+
// Get batch status
|
|
167
|
+
const status = await sendly.messages.getBatch('batch_xxx');
|
|
168
|
+
|
|
169
|
+
// List all batches
|
|
170
|
+
const { data: batches } = await sendly.messages.listBatches();
|
|
171
|
+
```
|
|
172
|
+
|
|
125
173
|
### Rate Limit Information
|
|
126
174
|
|
|
127
175
|
```typescript
|
|
@@ -154,6 +202,113 @@ const sendly = new Sendly({
|
|
|
154
202
|
});
|
|
155
203
|
```
|
|
156
204
|
|
|
205
|
+
## Webhooks
|
|
206
|
+
|
|
207
|
+
Manage webhook endpoints to receive real-time delivery status updates.
|
|
208
|
+
|
|
209
|
+
```typescript
|
|
210
|
+
// Create a webhook endpoint
|
|
211
|
+
const webhook = await sendly.webhooks.create({
|
|
212
|
+
url: 'https://example.com/webhooks/sendly',
|
|
213
|
+
events: ['message.delivered', 'message.failed']
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
console.log(`Webhook ID: ${webhook.id}`);
|
|
217
|
+
console.log(`Secret: ${webhook.secret}`); // Store this securely!
|
|
218
|
+
|
|
219
|
+
// List all webhooks
|
|
220
|
+
const webhooks = await sendly.webhooks.list();
|
|
221
|
+
|
|
222
|
+
// Get a specific webhook
|
|
223
|
+
const wh = await sendly.webhooks.get('whk_xxx');
|
|
224
|
+
|
|
225
|
+
// Update a webhook
|
|
226
|
+
await sendly.webhooks.update('whk_xxx', {
|
|
227
|
+
url: 'https://new-endpoint.example.com/webhook',
|
|
228
|
+
events: ['message.delivered', 'message.failed', 'message.sent']
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
// Test a webhook (sends a test event)
|
|
232
|
+
const testResult = await sendly.webhooks.test('whk_xxx');
|
|
233
|
+
console.log(`Test ${testResult.success ? 'passed' : 'failed'}`);
|
|
234
|
+
|
|
235
|
+
// Rotate webhook secret
|
|
236
|
+
const rotation = await sendly.webhooks.rotateSecret('whk_xxx');
|
|
237
|
+
console.log(`New secret: ${rotation.secret}`);
|
|
238
|
+
|
|
239
|
+
// View delivery history
|
|
240
|
+
const deliveries = await sendly.webhooks.getDeliveries('whk_xxx');
|
|
241
|
+
|
|
242
|
+
// Retry a failed delivery
|
|
243
|
+
await sendly.webhooks.retryDelivery('whk_xxx', 'del_yyy');
|
|
244
|
+
|
|
245
|
+
// Delete a webhook
|
|
246
|
+
await sendly.webhooks.delete('whk_xxx');
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### Verifying Webhook Signatures
|
|
250
|
+
|
|
251
|
+
```typescript
|
|
252
|
+
import { Webhooks } from '@sendly/node';
|
|
253
|
+
|
|
254
|
+
const webhooks = new Webhooks('your_webhook_secret');
|
|
255
|
+
|
|
256
|
+
// In your webhook handler
|
|
257
|
+
app.post('/webhooks/sendly', (req, res) => {
|
|
258
|
+
const signature = req.headers['x-sendly-signature'];
|
|
259
|
+
const payload = req.body;
|
|
260
|
+
|
|
261
|
+
try {
|
|
262
|
+
const event = webhooks.verifyAndParse(payload, signature);
|
|
263
|
+
|
|
264
|
+
switch (event.type) {
|
|
265
|
+
case 'message.delivered':
|
|
266
|
+
console.log(`Message ${event.data.id} delivered`);
|
|
267
|
+
break;
|
|
268
|
+
case 'message.failed':
|
|
269
|
+
console.log(`Message ${event.data.id} failed: ${event.data.errorCode}`);
|
|
270
|
+
break;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
res.status(200).send('OK');
|
|
274
|
+
} catch (error) {
|
|
275
|
+
console.error('Invalid signature');
|
|
276
|
+
res.status(400).send('Invalid signature');
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
## Account & Credits
|
|
282
|
+
|
|
283
|
+
```typescript
|
|
284
|
+
// Get account information
|
|
285
|
+
const account = await sendly.account.get();
|
|
286
|
+
console.log(`Email: ${account.email}`);
|
|
287
|
+
|
|
288
|
+
// Check credit balance
|
|
289
|
+
const credits = await sendly.account.getCredits();
|
|
290
|
+
console.log(`Available: ${credits.availableBalance} credits`);
|
|
291
|
+
console.log(`Reserved (scheduled): ${credits.reservedBalance} credits`);
|
|
292
|
+
console.log(`Total: ${credits.balance} credits`);
|
|
293
|
+
|
|
294
|
+
// View credit transaction history
|
|
295
|
+
const { data: transactions } = await sendly.account.getCreditTransactions();
|
|
296
|
+
for (const tx of transactions) {
|
|
297
|
+
console.log(`${tx.type}: ${tx.amount} credits - ${tx.description}`);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// List API keys
|
|
301
|
+
const { data: keys } = await sendly.account.listApiKeys();
|
|
302
|
+
for (const key of keys) {
|
|
303
|
+
console.log(`${key.name}: ${key.prefix}*** (${key.type})`);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// Get API key usage stats
|
|
307
|
+
const usage = await sendly.account.getApiKeyUsage('key_xxx');
|
|
308
|
+
console.log(`Messages sent: ${usage.messagesSent}`);
|
|
309
|
+
console.log(`Credits used: ${usage.creditsUsed}`);
|
|
310
|
+
```
|
|
311
|
+
|
|
157
312
|
## Error Handling
|
|
158
313
|
|
|
159
314
|
The SDK provides typed error classes for different error scenarios:
|
|
@@ -305,6 +460,8 @@ new Sendly(config: SendlyConfig)
|
|
|
305
460
|
#### Properties
|
|
306
461
|
|
|
307
462
|
- `messages` - Messages resource
|
|
463
|
+
- `webhooks` - Webhooks resource
|
|
464
|
+
- `account` - Account resource
|
|
308
465
|
|
|
309
466
|
#### Methods
|
|
310
467
|
|
|
@@ -326,6 +483,98 @@ List sent messages.
|
|
|
326
483
|
|
|
327
484
|
Get a specific message by ID.
|
|
328
485
|
|
|
486
|
+
#### `schedule(request: ScheduleMessageRequest): Promise<ScheduledMessage>`
|
|
487
|
+
|
|
488
|
+
Schedule a message for future delivery.
|
|
489
|
+
|
|
490
|
+
#### `listScheduled(options?: ListScheduledMessagesOptions): Promise<ScheduledMessageListResponse>`
|
|
491
|
+
|
|
492
|
+
List scheduled messages.
|
|
493
|
+
|
|
494
|
+
#### `getScheduled(id: string): Promise<ScheduledMessage>`
|
|
495
|
+
|
|
496
|
+
Get a scheduled message by ID.
|
|
497
|
+
|
|
498
|
+
#### `cancelScheduled(id: string): Promise<CancelScheduledMessageResponse>`
|
|
499
|
+
|
|
500
|
+
Cancel a scheduled message and refund credits.
|
|
501
|
+
|
|
502
|
+
#### `sendBatch(request: SendBatchRequest): Promise<BatchMessageResponse>`
|
|
503
|
+
|
|
504
|
+
Send multiple messages in one API call.
|
|
505
|
+
|
|
506
|
+
#### `getBatch(batchId: string): Promise<BatchMessageResponse>`
|
|
507
|
+
|
|
508
|
+
Get batch status by ID.
|
|
509
|
+
|
|
510
|
+
#### `listBatches(options?: ListBatchesOptions): Promise<BatchListResponse>`
|
|
511
|
+
|
|
512
|
+
List all batches.
|
|
513
|
+
|
|
514
|
+
### `sendly.webhooks`
|
|
515
|
+
|
|
516
|
+
#### `create(request: CreateWebhookRequest): Promise<Webhook>`
|
|
517
|
+
|
|
518
|
+
Create a new webhook endpoint.
|
|
519
|
+
|
|
520
|
+
#### `list(): Promise<Webhook[]>`
|
|
521
|
+
|
|
522
|
+
List all webhooks.
|
|
523
|
+
|
|
524
|
+
#### `get(id: string): Promise<Webhook>`
|
|
525
|
+
|
|
526
|
+
Get a webhook by ID.
|
|
527
|
+
|
|
528
|
+
#### `update(id: string, request: UpdateWebhookRequest): Promise<Webhook>`
|
|
529
|
+
|
|
530
|
+
Update a webhook.
|
|
531
|
+
|
|
532
|
+
#### `delete(id: string): Promise<void>`
|
|
533
|
+
|
|
534
|
+
Delete a webhook.
|
|
535
|
+
|
|
536
|
+
#### `test(id: string): Promise<WebhookTestResult>`
|
|
537
|
+
|
|
538
|
+
Send a test event to a webhook.
|
|
539
|
+
|
|
540
|
+
#### `rotateSecret(id: string): Promise<WebhookSecretRotation>`
|
|
541
|
+
|
|
542
|
+
Rotate webhook secret.
|
|
543
|
+
|
|
544
|
+
#### `getDeliveries(id: string): Promise<WebhookDelivery[]>`
|
|
545
|
+
|
|
546
|
+
Get delivery history for a webhook.
|
|
547
|
+
|
|
548
|
+
#### `retryDelivery(webhookId: string, deliveryId: string): Promise<void>`
|
|
549
|
+
|
|
550
|
+
Retry a failed delivery.
|
|
551
|
+
|
|
552
|
+
### `sendly.account`
|
|
553
|
+
|
|
554
|
+
#### `get(): Promise<Account>`
|
|
555
|
+
|
|
556
|
+
Get account information.
|
|
557
|
+
|
|
558
|
+
#### `getCredits(): Promise<Credits>`
|
|
559
|
+
|
|
560
|
+
Get credit balance.
|
|
561
|
+
|
|
562
|
+
#### `getCreditTransactions(): Promise<CreditTransactionListResponse>`
|
|
563
|
+
|
|
564
|
+
Get credit transaction history.
|
|
565
|
+
|
|
566
|
+
#### `listApiKeys(): Promise<ApiKeyListResponse>`
|
|
567
|
+
|
|
568
|
+
List API keys.
|
|
569
|
+
|
|
570
|
+
#### `getApiKey(id: string): Promise<ApiKey>`
|
|
571
|
+
|
|
572
|
+
Get an API key by ID.
|
|
573
|
+
|
|
574
|
+
#### `getApiKeyUsage(id: string): Promise<ApiKeyUsage>`
|
|
575
|
+
|
|
576
|
+
Get usage statistics for an API key.
|
|
577
|
+
|
|
329
578
|
## Support
|
|
330
579
|
|
|
331
580
|
- 📚 [Documentation](https://sendly.live/docs)
|
package/dist/index.js
CHANGED
|
@@ -638,7 +638,8 @@ var MessagesResource = class {
|
|
|
638
638
|
body: {
|
|
639
639
|
to: request.to,
|
|
640
640
|
text: request.text,
|
|
641
|
-
...request.from && { from: request.from }
|
|
641
|
+
...request.from && { from: request.from },
|
|
642
|
+
...request.messageType && { messageType: request.messageType }
|
|
642
643
|
}
|
|
643
644
|
});
|
|
644
645
|
return message;
|
|
@@ -802,7 +803,8 @@ var MessagesResource = class {
|
|
|
802
803
|
to: request.to,
|
|
803
804
|
text: request.text,
|
|
804
805
|
scheduledAt: request.scheduledAt,
|
|
805
|
-
...request.from && { from: request.from }
|
|
806
|
+
...request.from && { from: request.from },
|
|
807
|
+
...request.messageType && { messageType: request.messageType }
|
|
806
808
|
}
|
|
807
809
|
});
|
|
808
810
|
return scheduled;
|
|
@@ -925,7 +927,8 @@ var MessagesResource = class {
|
|
|
925
927
|
path: "/messages/batch",
|
|
926
928
|
body: {
|
|
927
929
|
messages: request.messages,
|
|
928
|
-
...request.from && { from: request.from }
|
|
930
|
+
...request.from && { from: request.from },
|
|
931
|
+
...request.messageType && { messageType: request.messageType }
|
|
929
932
|
}
|
|
930
933
|
});
|
|
931
934
|
return batch;
|
package/dist/index.mjs
CHANGED
|
@@ -578,7 +578,8 @@ var MessagesResource = class {
|
|
|
578
578
|
body: {
|
|
579
579
|
to: request.to,
|
|
580
580
|
text: request.text,
|
|
581
|
-
...request.from && { from: request.from }
|
|
581
|
+
...request.from && { from: request.from },
|
|
582
|
+
...request.messageType && { messageType: request.messageType }
|
|
582
583
|
}
|
|
583
584
|
});
|
|
584
585
|
return message;
|
|
@@ -742,7 +743,8 @@ var MessagesResource = class {
|
|
|
742
743
|
to: request.to,
|
|
743
744
|
text: request.text,
|
|
744
745
|
scheduledAt: request.scheduledAt,
|
|
745
|
-
...request.from && { from: request.from }
|
|
746
|
+
...request.from && { from: request.from },
|
|
747
|
+
...request.messageType && { messageType: request.messageType }
|
|
746
748
|
}
|
|
747
749
|
});
|
|
748
750
|
return scheduled;
|
|
@@ -865,7 +867,8 @@ var MessagesResource = class {
|
|
|
865
867
|
path: "/messages/batch",
|
|
866
868
|
body: {
|
|
867
869
|
messages: request.messages,
|
|
868
|
-
...request.from && { from: request.from }
|
|
870
|
+
...request.from && { from: request.from },
|
|
871
|
+
...request.messageType && { messageType: request.messageType }
|
|
869
872
|
}
|
|
870
873
|
});
|
|
871
874
|
return batch;
|