zohocpaas 1.0.1 → 1.0.2
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/CHANGELOG.md +39 -0
- package/README.md +218 -183
- package/index.js +2 -2
- package/lib/js/init.cjs +186 -125
- package/lib/js/init.js +186 -126
- package/lib/js/types/index.d.cts +28 -20
- package/lib/js/types/index.d.ts +28 -20
- package/package.json +3 -2
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `zohocpaas` are documented here.
|
|
4
|
+
|
|
5
|
+
## [1.0.2] - 2026-12-03
|
|
6
|
+
|
|
7
|
+
### Breaking
|
|
8
|
+
|
|
9
|
+
- `NetworkError` and `TimeoutError` no longer extend `AuthenticationError`. Both now extend the new `SdkError` base. Code that caught `AuthenticationError` for network or timeout failures should catch `NetworkError`, `TimeoutError`, or `SdkError` instead.
|
|
10
|
+
- The empty-credential message from `SendMailClient` changed from `Send Mail token cannot be empty` to `API key cannot be empty`. Update any code that matches the message text.
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- `SdkError` base class, exported from the package. Every error the SDK throws extends it, so `err instanceof SdkError` matches all of them.
|
|
15
|
+
- `SendMailClient` accepts `apiKey`, the same credential used by the WhatsApp, SMS, and Voice `apiKey` option. `token` still works as a fallback. When both are set, `apiKey` is used.
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
|
|
19
|
+
- `SendMailClient`: when `url` contained `/v1.1`, every send method (`sendMail`, `sendBatchMail`, `sendMailWithTemplate`, `mailBatchWithTemplate`) was posted to the same endpoint. Each method now uses its own path. URLs without a trailing slash and URLs with a plain-HTTP scheme are also handled correctly.
|
|
20
|
+
- Path parameters (domain key, agent key, email reference, suppression type) are URL-encoded.
|
|
21
|
+
- Suppression email and domain validation no longer backtracks exponentially on long input. Accepted inputs are unchanged for the tested samples.
|
|
22
|
+
|
|
23
|
+
### Changed
|
|
24
|
+
|
|
25
|
+
- Documentation: Quick Start shows Email, WhatsApp, SMS, and Voice side by side. Added a channel configuration section with setup links, and a single credential table.
|
|
26
|
+
|
|
27
|
+
## [1.0.1] - 2026-11-24
|
|
28
|
+
|
|
29
|
+
### Changed
|
|
30
|
+
|
|
31
|
+
- Documentation update.
|
|
32
|
+
|
|
33
|
+
## [1.0.0] - 2026-11-23
|
|
34
|
+
|
|
35
|
+
### Added
|
|
36
|
+
|
|
37
|
+
- First release under the `zohocpaas` name, the Zoho CPaaS rename of the ZeptoMail Node.js SDK.
|
|
38
|
+
- Email (`SendMailClient`), WhatsApp, SMS, and Voice clients.
|
|
39
|
+
- Account APIs: `AgentClient`, `DomainClient`, `SuppressionClient`, and `EmailLogsClient`, authenticated with OAuth through `AuthenticationClient`.
|
package/README.md
CHANGED
|
@@ -1,25 +1,22 @@
|
|
|
1
1
|
# Zoho CPaaS (Formerly ZeptoMail) Node.js SDK
|
|
2
2
|
|
|
3
|
-
Node.js SDK for Zoho CPaaS: transactional email,
|
|
3
|
+
Node.js SDK for Zoho CPaaS: transactional email, WhatsApp, SMS, and Voice messaging, plus account management.
|
|
4
4
|
|
|
5
5
|
## Table of Contents
|
|
6
6
|
|
|
7
7
|
- [Installation](#installation)
|
|
8
8
|
- [Quick Start](#quick-start)
|
|
9
|
-
- [
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
- [Channel configuration](#channel-configuration)
|
|
10
|
+
- [Email](#email)
|
|
11
|
+
- [WhatsApp](#whatsapp)
|
|
12
|
+
- [SMS](#sms)
|
|
13
|
+
- [Voice](#voice)
|
|
14
14
|
- [Authentication](#authentication--one-client-per-scope)
|
|
15
|
-
|
|
16
|
-
- [
|
|
17
|
-
- [
|
|
18
|
-
- [
|
|
19
|
-
- [
|
|
20
|
-
- [Suppression Management](#-suppression-management)
|
|
21
|
-
- [Email logs](#-email-logs)
|
|
22
|
-
- [SMS, WhatsApp & Voice](#-sms-whatsapp--voice)
|
|
15
|
+
- [Account management](#account-management)
|
|
16
|
+
- [Agents](#-agent-management)
|
|
17
|
+
- [Domains](#-domain-management)
|
|
18
|
+
- [Suppression](#-suppression-management)
|
|
19
|
+
- [Email logs](#-email-logs)
|
|
23
20
|
- [Error handling](#error-handling)
|
|
24
21
|
- [Contact](#contact)
|
|
25
22
|
|
|
@@ -38,36 +35,109 @@ npm install zohocpaas
|
|
|
38
35
|
## Quick Start
|
|
39
36
|
|
|
40
37
|
```js
|
|
41
|
-
import { SendMailClient } from "zohocpaas";
|
|
42
|
-
// CommonJS: const { SendMailClient } = require("zohocpaas");
|
|
38
|
+
import { SendMailClient, WhatsAppClient, SmsClient, VoiceClient } from "zohocpaas";
|
|
39
|
+
// CommonJS: const { SendMailClient, WhatsAppClient, SmsClient, VoiceClient } = require("zohocpaas");
|
|
43
40
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
await client.sendMail({
|
|
41
|
+
// Same API key for Email, WhatsApp, SMS, and Voice (raw key or `Zoho-enczapikey <key>`)
|
|
42
|
+
const email = new SendMailClient({ url: "api.zeptomail.com/", apiKey: "<api-key>" });
|
|
43
|
+
await email.sendMail({
|
|
50
44
|
from: { address: "you@example.com", name: "Your App" },
|
|
51
45
|
to: [{ email_address: { address: "user@example.com", name: "User" } }],
|
|
52
|
-
subject: "Hello from
|
|
53
|
-
htmlbody: "<p>Your first email
|
|
46
|
+
subject: "Hello from Zoho CPaaS",
|
|
47
|
+
htmlbody: "<p>Your first email.</p>",
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const whatsapp = new WhatsAppClient({ apiKey: "<api-key>" });
|
|
51
|
+
await whatsapp.sendMessage({
|
|
52
|
+
from: "+919000000001",
|
|
53
|
+
to: "+919876543210",
|
|
54
|
+
templateAlias: "order-shipped",
|
|
55
|
+
mergeInfo: { name: "John", order_id: "1042" },
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const sms = new SmsClient({ apiKey: "<api-key>" });
|
|
59
|
+
await sms.sendSms({
|
|
60
|
+
senderKey: "<sms-sender-key>",
|
|
61
|
+
to: [{ mobileNo: "+919876543210" }],
|
|
62
|
+
templateAlias: "otp",
|
|
63
|
+
mergeInfo: { otp: "4 8 2 9 1 3", minutes: "5" },
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const voice = new VoiceClient({ apiKey: "<api-key>" });
|
|
67
|
+
await voice.placeCall({
|
|
68
|
+
from: "+919876543210",
|
|
69
|
+
to: "+919012345678",
|
|
70
|
+
templateAlias: "payment-reminder-ivr",
|
|
71
|
+
mergeInfo: { customer_name: "John", amount: "1250" },
|
|
54
72
|
});
|
|
55
73
|
```
|
|
56
74
|
|
|
57
|
-
|
|
75
|
+
Configure each channel before calling the APIs — see [Channel configuration](#channel-configuration).
|
|
58
76
|
|
|
59
77
|
| Area | Credential |
|
|
60
78
|
|---|---|
|
|
61
|
-
|
|
|
79
|
+
| Email, WhatsApp, SMS, Voice (send, logs) | API key (`apiKey`) |
|
|
80
|
+
| WhatsApp, SMS, Voice (templates) | OAuth (`Zeptomail.MailTemplates.*`) |
|
|
62
81
|
| Agents, domains, suppression, email logs | OAuth (`AuthenticationClient`, one scope per client) |
|
|
63
|
-
| SMS, WhatsApp, Voice (send, logs) | Agent API key |
|
|
64
|
-
| SMS, WhatsApp, Voice (templates) | OAuth (`Zeptomail.MailTemplates.*`) |
|
|
65
82
|
|
|
66
83
|
---
|
|
67
84
|
|
|
68
|
-
##
|
|
85
|
+
## Channel configuration
|
|
86
|
+
|
|
87
|
+
Configure each channel in the Zoho CPaaS console before calling the APIs:
|
|
88
|
+
|
|
89
|
+
| Channel | Setup guide |
|
|
90
|
+
|---|---|
|
|
91
|
+
| Email (add & verify domain) | [Domains](https://www.zoho.com/cpaas/help/domains.html) |
|
|
92
|
+
| WhatsApp | [WhatsApp](https://www.zoho.com/cpaas/help/whatsapp.html) |
|
|
93
|
+
| SMS | [SMS](https://www.zoho.com/cpaas/help/sms.html) |
|
|
94
|
+
| Voice | [Voice](https://www.zoho.com/cpaas/help/voice.html) |
|
|
69
95
|
|
|
70
|
-
|
|
96
|
+
```js
|
|
97
|
+
import { WhatsAppClient, SmsClient, VoiceClient, AuthenticationClient } from "zohocpaas";
|
|
98
|
+
|
|
99
|
+
// OAuth is needed only for the template APIs. Create it for the same data center as the client.
|
|
100
|
+
const smsAuth = new AuthenticationClient({
|
|
101
|
+
clientId: "<client-id>",
|
|
102
|
+
clientSecret: "<client-secret>",
|
|
103
|
+
refreshToken: "<refresh-token>", // scope: Zeptomail.MailTemplates.* (or .All)
|
|
104
|
+
dataCenter: "IN",
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
const whatsapp = new WhatsAppClient({ apiKey: "<api-key>", authenticationClient: whatsappAuth }); // whatsappAuth: dataCenter "US"
|
|
108
|
+
const sms = new SmsClient({ apiKey: "<api-key>", authenticationClient: smsAuth });
|
|
109
|
+
const voice = new VoiceClient({ apiKey: "<api-key>", authenticationClient: voiceAuth }); // voiceAuth: dataCenter "US"
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Credentials
|
|
113
|
+
|
|
114
|
+
| Operation | Credential |
|
|
115
|
+
|---|---|
|
|
116
|
+
| Email / WhatsApp / SMS / Voice send & logs | API key (`apiKey`; raw or `Zoho-enczapikey <key>`) |
|
|
117
|
+
| Templates | OAuth (`Zeptomail.MailTemplates.*`), same data center as the client |
|
|
118
|
+
|
|
119
|
+
- **API key:** from **Agents → SMTP/API → API key**. Pass the raw key or the full `Zoho-enczapikey <key>` value; the prefix is added when missing. Use the same `apiKey` on `SendMailClient`, WhatsApp, SMS, and Voice (`token` still works on `SendMailClient` as a fallback). The agent is implied by the key.
|
|
120
|
+
- **OAuth:** pass an `AuthenticationClient` created for the **same data center** as the client. One `AuthenticationClient` per data center can be shared by the channel clients in that region, because every channel uses the same `Zeptomail.MailTemplates.*` scope.
|
|
121
|
+
- A single channel client can hold both credentials, as `sms` does above: the API key is used for sending and logs, and OAuth for templates.
|
|
122
|
+
- Calling a method without the credential it needs rejects with an `AuthenticationError` before any request is made.
|
|
123
|
+
|
|
124
|
+
### Supported data centers
|
|
125
|
+
|
|
126
|
+
| Client | Data centers | Default |
|
|
127
|
+
|---|---|---|
|
|
128
|
+
| `WhatsAppClient` | `US`, `IN`, `EU`, `AU`, `JP` | `US` |
|
|
129
|
+
| `SmsClient` | `IN` | `IN` |
|
|
130
|
+
| `VoiceClient` | `US`, `IN`, `EU`, `AU` | `US` |
|
|
131
|
+
|
|
132
|
+
Unsupported `dataCenter` → `ValidationError`. `dataCenter` must match `authenticationClient` when both are set.
|
|
133
|
+
|
|
134
|
+
Log filters `dateFrom` / `dateTo`: `Date`, timestamp, `dd/MM/yyyy, hh:mm AM`, or ISO `yyyy-MM-ddTHH:mm:ss`. Max **50** rows per log page.
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## Email
|
|
139
|
+
|
|
140
|
+
`SendMailClient` options: `url` (e.g. `api.zeptomail.com/`), `apiKey` (raw API key or `Zoho-enczapikey <key>`; `token` is accepted as a fallback), optional `timeout` (default 30s), or `domain` instead of `url`.
|
|
71
141
|
|
|
72
142
|
### Send mail
|
|
73
143
|
|
|
@@ -106,8 +176,8 @@ Optional `idempotencyKey` (string, max 100). Sent as `idempotency_key`. Invalid
|
|
|
106
176
|
| Client | Methods |
|
|
107
177
|
|---|---|
|
|
108
178
|
| `SendMailClient` | `sendMail`, `sendBatchMail`, `sendMailWithTemplate`, `mailBatchWithTemplate` |
|
|
109
|
-
| `SmsClient` | `sendSms`, `sendBatchSms` |
|
|
110
179
|
| `WhatsAppClient` | `sendMessage` |
|
|
180
|
+
| `SmsClient` | `sendSms`, `sendBatchSms` |
|
|
111
181
|
| `VoiceClient` | `placeCall` |
|
|
112
182
|
|
|
113
183
|
|
|
@@ -196,6 +266,116 @@ await client.mailBatchWithTemplate({
|
|
|
196
266
|
|
|
197
267
|
---
|
|
198
268
|
|
|
269
|
+
## WhatsApp
|
|
270
|
+
|
|
271
|
+
```js
|
|
272
|
+
await whatsapp.sendMessage({
|
|
273
|
+
from: "+919000000001",
|
|
274
|
+
to: "+919876543210",
|
|
275
|
+
templateAlias: "order-shipped",
|
|
276
|
+
mergeInfo: { name: "John", order_id: "1042" },
|
|
277
|
+
tag: "orders",
|
|
278
|
+
clientReference: "order-1042",
|
|
279
|
+
idempotencyKey: "order-1042-whatsapp", // optional, max 100 characters
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
await whatsapp.getAllLogs({ status: "delivered", tag: ["orders"], batchStats: true });
|
|
283
|
+
await whatsapp.getLogDetails({ messageId: "<message-id>" });
|
|
284
|
+
|
|
285
|
+
await whatsapp.getAllTemplates({ limit: 20 });
|
|
286
|
+
await whatsapp.getTemplate({ templateKey: "<template-key>" });
|
|
287
|
+
await whatsapp.addTemplate({
|
|
288
|
+
templateName: "Order confirmation",
|
|
289
|
+
templateAlias: "order-confirm",
|
|
290
|
+
entityKey: "<waba-id>",
|
|
291
|
+
languageCode: "en_US",
|
|
292
|
+
category: "utility",
|
|
293
|
+
headerType: "TEXT",
|
|
294
|
+
headerText: "Order update",
|
|
295
|
+
bodyText: "Hi {{name}}, your order #{{order_id}} is confirmed.",
|
|
296
|
+
buttons: [{ url_button: { button_text: "Track", button_value: "https://example.com/track" } }],
|
|
297
|
+
});
|
|
298
|
+
await whatsapp.deleteTemplates({ templateKeys: ["<template-key>"] });
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
WhatsApp templates start `in-review` (Meta approval). `updateTemplate` is not available.
|
|
302
|
+
|
|
303
|
+
---
|
|
304
|
+
|
|
305
|
+
## SMS
|
|
306
|
+
|
|
307
|
+
```js
|
|
308
|
+
// Send
|
|
309
|
+
await sms.sendSms({
|
|
310
|
+
senderKey: "<sms-sender-key>",
|
|
311
|
+
to: [{ mobileNo: "+919876543210" }],
|
|
312
|
+
templateAlias: "otp",
|
|
313
|
+
mergeInfo: { otp: "4 8 2 9 1 3", minutes: "5" },
|
|
314
|
+
clientReference: "login-1042",
|
|
315
|
+
idempotencyKey: "login-1042-sms", // optional, max 100 characters
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
// Batch: 1 to 2000 recipients, each with its own merge values
|
|
319
|
+
await sms.sendBatchSms({
|
|
320
|
+
senderKey: "<sms-sender-key>",
|
|
321
|
+
templateAlias: "payment-reminder",
|
|
322
|
+
to: [
|
|
323
|
+
{ mobileNo: "+919876543210", mergeInfo: { name: "John", due: "1250" } },
|
|
324
|
+
{ mobileNo: "+919876543211", mergeInfo: { name: "Vincy", due: "3400" } },
|
|
325
|
+
],
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
// Logs
|
|
329
|
+
await sms.getAllLogs({ limit: 20, status: "delivered", recipient: "+919876543210" });
|
|
330
|
+
await sms.getLogDetails({ messageId: "<message-id>" });
|
|
331
|
+
|
|
332
|
+
// Templates
|
|
333
|
+
await sms.getAllTemplates({ offset: 0, limit: 20, status: "approved" });
|
|
334
|
+
await sms.getTemplate({ templateKey: "<template-key>" });
|
|
335
|
+
await sms.addTemplate({
|
|
336
|
+
templateName: "Payment reminder",
|
|
337
|
+
templateAlias: "payment-reminder",
|
|
338
|
+
entityKey: "<sms-sender-key>",
|
|
339
|
+
content: "Hi {{name}}, your payment of {{due}} is due.",
|
|
340
|
+
});
|
|
341
|
+
await sms.updateTemplate({ templateKey: "<template-key>", content: "Updated content" });
|
|
342
|
+
await sms.deleteTemplates({ templateKeys: ["<template-key>"] }); // resolves with no value
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
---
|
|
346
|
+
|
|
347
|
+
## Voice
|
|
348
|
+
|
|
349
|
+
```js
|
|
350
|
+
// Place a call from a template, or from plain text with `messageContent`
|
|
351
|
+
await voice.placeCall({
|
|
352
|
+
from: "+919876543210",
|
|
353
|
+
to: "+919012345678",
|
|
354
|
+
templateAlias: "payment-reminder-ivr",
|
|
355
|
+
mergeInfo: { customer_name: "John", amount: "1250" },
|
|
356
|
+
language: "en",
|
|
357
|
+
voiceGender: "female",
|
|
358
|
+
idempotencyKey: "order-1042-call", // optional, max 100 characters
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
await voice.getAllCallLogs({ status: "answered", limit: 20 });
|
|
362
|
+
await voice.getCallDetails({ messageId: "<message-id>" });
|
|
363
|
+
await voice.getVoiceNumbers({ status: "approved" });
|
|
364
|
+
|
|
365
|
+
await voice.getAllTemplates();
|
|
366
|
+
await voice.getTemplate({ templateKey: "<template-key>" });
|
|
367
|
+
await voice.addTemplate({
|
|
368
|
+
templateName: "Appointment Reminder",
|
|
369
|
+
templateAlias: "appointment-reminder",
|
|
370
|
+
entityKey: "<agent-key>",
|
|
371
|
+
content: { start_node: "reminder_prompt", nodes: { /* IVR flow */ } },
|
|
372
|
+
});
|
|
373
|
+
await voice.updateTemplate({ templateKey: "<template-key>", content: { /* IVR flow */ } });
|
|
374
|
+
await voice.deleteTemplates({ templateKeys: ["<template-key>"] });
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
---
|
|
378
|
+
|
|
199
379
|
## Authentication — one client per scope
|
|
200
380
|
|
|
201
381
|
Use a separate `AuthenticationClient` per scope (refresh tokens are not interchangeable across clients).
|
|
@@ -263,6 +443,9 @@ await agentAuth.refreshAccessToken(); // call this before making requests
|
|
|
263
443
|
|
|
264
444
|
---
|
|
265
445
|
|
|
446
|
+
## Account management
|
|
447
|
+
|
|
448
|
+
OAuth clients for agents, domains, suppressions, and email logs. Use a separate `AuthenticationClient` per scope — see [Authentication](#authentication--one-client-per-scope).
|
|
266
449
|
|
|
267
450
|
## 🧩 Agent Management
|
|
268
451
|
|
|
@@ -535,157 +718,6 @@ const response = await logs.getEmailDetails({
|
|
|
535
718
|
|
|
536
719
|
---
|
|
537
720
|
|
|
538
|
-
## 💬 SMS, WhatsApp & Voice
|
|
539
|
-
|
|
540
|
-
```js
|
|
541
|
-
import { SmsClient, WhatsAppClient, VoiceClient, AuthenticationClient } from "zohocpaas";
|
|
542
|
-
|
|
543
|
-
// OAuth is needed only for the template APIs. Create it for the same data center as the client.
|
|
544
|
-
const smsAuth = new AuthenticationClient({
|
|
545
|
-
clientId: "<client-id>",
|
|
546
|
-
clientSecret: "<client-secret>",
|
|
547
|
-
refreshToken: "<refresh-token>", // scope: Zeptomail.MailTemplates.* (or .All)
|
|
548
|
-
dataCenter: "IN",
|
|
549
|
-
});
|
|
550
|
-
|
|
551
|
-
const sms = new SmsClient({ apiKey: "<agent-api-key>", authenticationClient: smsAuth });
|
|
552
|
-
const whatsapp = new WhatsAppClient({ apiKey: "<agent-api-key>", authenticationClient: whatsappAuth }); // whatsappAuth: dataCenter "US"
|
|
553
|
-
const voice = new VoiceClient({ apiKey: "<agent-api-key>", authenticationClient: voiceAuth }); // voiceAuth: dataCenter "US"
|
|
554
|
-
```
|
|
555
|
-
|
|
556
|
-
### Authentication
|
|
557
|
-
|
|
558
|
-
| Operation | Credential |
|
|
559
|
-
|---|---|
|
|
560
|
-
| Send, logs, voice numbers | API key (raw or `Zoho-enczapikey <key>`) |
|
|
561
|
-
| Templates | OAuth (`Zeptomail.MailTemplates.*`), same data center as the client |
|
|
562
|
-
|
|
563
|
-
One client may hold both. Missing credentials throw `AuthenticationError` before the request.
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
- **API key:** the agent API key (**Agents → SMTP/API → API key**). Pass the raw key or the full `Zoho-enczapikey <key>` value; the prefix is added when missing. The agent is implied by the key.
|
|
567
|
-
- **OAuth:** pass an `AuthenticationClient` created for the **same data center** as the client. One `AuthenticationClient` per data center can be shared by the channel clients in that region, because every channel uses the same `Zeptomail.MailTemplates.*` scope.
|
|
568
|
-
- A single client can hold both credentials, as `sms` does above: the API key is used for sending and logs, and OAuth for templates.
|
|
569
|
-
- Calling a method without the credential it needs (for example a template method on a client that only has an API key) rejects with an `AuthenticationError` before any request is made. The message names what is missing.
|
|
570
|
-
|
|
571
|
-
### Supported data centers
|
|
572
|
-
|
|
573
|
-
| Client | Data centers | Default |
|
|
574
|
-
|---|---|---|
|
|
575
|
-
| `SmsClient` | `IN` | `IN` |
|
|
576
|
-
| `WhatsAppClient` | `US`, `IN`, `EU`, `AU`, `JP` | `US` |
|
|
577
|
-
| `VoiceClient` | `US`, `IN`, `EU`, `AU` | `US` |
|
|
578
|
-
|
|
579
|
-
Unsupported `dataCenter` → `ValidationError`. `dataCenter` must match `authenticationClient` when both are set.
|
|
580
|
-
|
|
581
|
-
### SMS
|
|
582
|
-
|
|
583
|
-
```js
|
|
584
|
-
// Send
|
|
585
|
-
await sms.sendSms({
|
|
586
|
-
senderKey: "<sms-sender-key>",
|
|
587
|
-
to: [{ mobileNo: "+919876543210" }],
|
|
588
|
-
templateAlias: "otp",
|
|
589
|
-
mergeInfo: { otp: "4 8 2 9 1 3", minutes: "5" },
|
|
590
|
-
clientReference: "login-1042",
|
|
591
|
-
idempotencyKey: "login-1042-sms", // optional, max 100 characters
|
|
592
|
-
});
|
|
593
|
-
|
|
594
|
-
// Batch: 1 to 2000 recipients, each with its own merge values
|
|
595
|
-
await sms.sendBatchSms({
|
|
596
|
-
senderKey: "<sms-sender-key>",
|
|
597
|
-
templateAlias: "payment-reminder",
|
|
598
|
-
to: [
|
|
599
|
-
{ mobileNo: "+919876543210", mergeInfo: { name: "Arun", due: "1250" } },
|
|
600
|
-
{ mobileNo: "+919876543211", mergeInfo: { name: "Meera", due: "3400" } },
|
|
601
|
-
],
|
|
602
|
-
});
|
|
603
|
-
|
|
604
|
-
// Logs
|
|
605
|
-
await sms.getAllLogs({ limit: 20, status: "delivered", recipient: "+919876543210" });
|
|
606
|
-
await sms.getLogDetails({ messageId: "<message-id>" });
|
|
607
|
-
|
|
608
|
-
// Templates
|
|
609
|
-
await sms.getAllTemplates({ offset: 0, limit: 20, status: "approved" });
|
|
610
|
-
await sms.getTemplate({ templateKey: "<template-key>" });
|
|
611
|
-
await sms.addTemplate({
|
|
612
|
-
templateName: "Payment reminder",
|
|
613
|
-
templateAlias: "payment-reminder",
|
|
614
|
-
entityKey: "<sms-sender-key>",
|
|
615
|
-
content: "Hi {{name}}, your payment of {{due}} is due.",
|
|
616
|
-
});
|
|
617
|
-
await sms.updateTemplate({ templateKey: "<template-key>", content: "Updated content" });
|
|
618
|
-
await sms.deleteTemplates({ templateKeys: ["<template-key>"] }); // resolves with no value
|
|
619
|
-
```
|
|
620
|
-
|
|
621
|
-
### WhatsApp
|
|
622
|
-
|
|
623
|
-
```js
|
|
624
|
-
await whatsapp.sendMessage({
|
|
625
|
-
from: "+919000000001",
|
|
626
|
-
to: "+919876543210",
|
|
627
|
-
templateAlias: "order-shipped",
|
|
628
|
-
mergeInfo: { name: "Arun", order_id: "1042" },
|
|
629
|
-
tag: "orders",
|
|
630
|
-
clientReference: "order-1042",
|
|
631
|
-
idempotencyKey: "order-1042-whatsapp", // optional, max 100 characters
|
|
632
|
-
});
|
|
633
|
-
|
|
634
|
-
await whatsapp.getAllLogs({ status: "delivered", tag: ["orders"], batchStats: true });
|
|
635
|
-
await whatsapp.getLogDetails({ messageId: "<message-id>" });
|
|
636
|
-
|
|
637
|
-
await whatsapp.getAllTemplates({ limit: 20 });
|
|
638
|
-
await whatsapp.getTemplate({ templateKey: "<template-key>" });
|
|
639
|
-
await whatsapp.addTemplate({
|
|
640
|
-
templateName: "Order confirmation",
|
|
641
|
-
templateAlias: "order-confirm",
|
|
642
|
-
entityKey: "<waba-id>",
|
|
643
|
-
languageCode: "en_US",
|
|
644
|
-
category: "utility",
|
|
645
|
-
headerType: "TEXT",
|
|
646
|
-
headerText: "Order update",
|
|
647
|
-
bodyText: "Hi {{name}}, your order #{{order_id}} is confirmed.",
|
|
648
|
-
buttons: [{ url_button: { button_text: "Track", button_value: "https://example.com/track" } }],
|
|
649
|
-
});
|
|
650
|
-
await whatsapp.deleteTemplates({ templateKeys: ["<template-key>"] });
|
|
651
|
-
```
|
|
652
|
-
|
|
653
|
-
WhatsApp templates start `in-review` (Meta approval). `updateTemplate` is not available.
|
|
654
|
-
|
|
655
|
-
### Voice
|
|
656
|
-
|
|
657
|
-
```js
|
|
658
|
-
// Place a call from a template, or from plain text with `messageContent`
|
|
659
|
-
await voice.placeCall({
|
|
660
|
-
from: "+919876543210",
|
|
661
|
-
to: "+919012345678",
|
|
662
|
-
templateAlias: "payment-reminder-ivr",
|
|
663
|
-
mergeInfo: { customer_name: "Arun", amount: "1250" },
|
|
664
|
-
language: "en",
|
|
665
|
-
voiceGender: "female",
|
|
666
|
-
idempotencyKey: "order-1042-call", // optional, max 100 characters
|
|
667
|
-
});
|
|
668
|
-
|
|
669
|
-
await voice.getAllCallLogs({ status: "answered", limit: 20 });
|
|
670
|
-
await voice.getCallDetails({ messageId: "<message-id>" });
|
|
671
|
-
await voice.getVoiceNumbers({ status: "approved" });
|
|
672
|
-
|
|
673
|
-
await voice.getAllTemplates();
|
|
674
|
-
await voice.getTemplate({ templateKey: "<template-key>" });
|
|
675
|
-
await voice.addTemplate({
|
|
676
|
-
templateName: "Appointment Reminder",
|
|
677
|
-
templateAlias: "appointment-reminder",
|
|
678
|
-
entityKey: "<agent-key>",
|
|
679
|
-
content: { start_node: "reminder_prompt", nodes: { /* IVR flow */ } },
|
|
680
|
-
});
|
|
681
|
-
await voice.updateTemplate({ templateKey: "<template-key>", content: { /* IVR flow */ } });
|
|
682
|
-
await voice.deleteTemplates({ templateKeys: ["<template-key>"] });
|
|
683
|
-
```
|
|
684
|
-
|
|
685
|
-
Log filters `dateFrom` / `dateTo`: `Date`, timestamp, `dd/MM/yyyy, hh:mm AM`, or ISO `yyyy-MM-ddTHH:mm:ss`. Max **50** rows per log page.
|
|
686
|
-
|
|
687
|
-
---
|
|
688
|
-
|
|
689
721
|
## Error handling
|
|
690
722
|
|
|
691
723
|
| Error | Typical cause |
|
|
@@ -695,11 +727,13 @@ Log filters `dateFrom` / `dateTo`: `Date`, timestamp, `dd/MM/yyyy, hh:mm AM`, or
|
|
|
695
727
|
| `ApiError` | HTTP error response (`status`, response body on the error) |
|
|
696
728
|
| `TimeoutError` | Request or token refresh timed out |
|
|
697
729
|
| `NetworkError` | No connectivity |
|
|
730
|
+
| `SdkError` | Shared base for all of the above |
|
|
698
731
|
|
|
699
732
|
`SendMailClient` does not use OAuth (no `AuthenticationError`). Use `instanceof` on the error classes imported from `zohocpaas`.
|
|
700
733
|
|
|
701
734
|
```js
|
|
702
735
|
import {
|
|
736
|
+
SdkError,
|
|
703
737
|
AuthenticationError,
|
|
704
738
|
ApiError,
|
|
705
739
|
NetworkError,
|
|
@@ -715,6 +749,7 @@ try {
|
|
|
715
749
|
else if (err instanceof TimeoutError) { /* retry or increase timeout */ }
|
|
716
750
|
else if (err instanceof NetworkError) { /* connectivity */ }
|
|
717
751
|
else if (err instanceof AuthenticationError) { /* OAuth or channel credentials */ }
|
|
752
|
+
else if (err instanceof SdkError) { /* other SDK error */ }
|
|
718
753
|
}
|
|
719
754
|
```
|
|
720
755
|
|
|
@@ -722,4 +757,4 @@ try {
|
|
|
722
757
|
|
|
723
758
|
## Contact
|
|
724
759
|
|
|
725
|
-
[support@zohocpaas.com](mailto:support@zohocpaas.com)
|
|
760
|
+
For issues or assistance with this SDK, contact [support@zohocpaas.com](mailto:support@zohocpaas.com).
|
package/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { AgentClient, ApiError, AuthenticationClient, AuthenticationError, DomainClient, EmailLogsClient, NetworkError, SendMailClient, SmsClient, SuppressionClient, TimeoutError, ValidationError, VoiceClient, WhatsAppClient } from "./lib/js/init.js";
|
|
1
|
+
import { AgentClient, ApiError, AuthenticationClient, AuthenticationError, DomainClient, EmailLogsClient, NetworkError, SdkError, SendMailClient, SmsClient, SuppressionClient, TimeoutError, ValidationError, VoiceClient, WhatsAppClient } from "./lib/js/init.js";
|
|
2
2
|
|
|
3
|
-
export { AgentClient, ApiError, AuthenticationClient, AuthenticationError, DomainClient, EmailLogsClient, NetworkError, SendMailClient, SmsClient, SuppressionClient, TimeoutError, ValidationError, VoiceClient, WhatsAppClient };
|
|
3
|
+
export { AgentClient, ApiError, AuthenticationClient, AuthenticationError, DomainClient, EmailLogsClient, NetworkError, SdkError, SendMailClient, SmsClient, SuppressionClient, TimeoutError, ValidationError, VoiceClient, WhatsAppClient };
|