botcast-sdk 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/LICENSE +21 -0
- package/README.md +257 -0
- package/dist/client.cjs +91 -0
- package/dist/client.d.ts +64 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +87 -0
- package/dist/errors.cjs +59 -0
- package/dist/errors.d.ts +25 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +49 -0
- package/dist/index.cjs +26 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/modules/base.cjs +113 -0
- package/dist/modules/base.d.ts +22 -0
- package/dist/modules/base.d.ts.map +1 -0
- package/dist/modules/base.js +109 -0
- package/dist/modules/broadcast.cjs +30 -0
- package/dist/modules/broadcast.d.ts +27 -0
- package/dist/modules/broadcast.d.ts.map +1 -0
- package/dist/modules/broadcast.js +26 -0
- package/dist/modules/chats.cjs +113 -0
- package/dist/modules/chats.d.ts +106 -0
- package/dist/modules/chats.d.ts.map +1 -0
- package/dist/modules/chats.js +109 -0
- package/dist/modules/groups.cjs +200 -0
- package/dist/modules/groups.d.ts +139 -0
- package/dist/modules/groups.d.ts.map +1 -0
- package/dist/modules/groups.js +196 -0
- package/dist/modules/instances.cjs +138 -0
- package/dist/modules/instances.d.ts +91 -0
- package/dist/modules/instances.d.ts.map +1 -0
- package/dist/modules/instances.js +134 -0
- package/dist/modules/messages.cjs +217 -0
- package/dist/modules/messages.d.ts +155 -0
- package/dist/modules/messages.d.ts.map +1 -0
- package/dist/modules/messages.js +213 -0
- package/dist/modules/profile.cjs +129 -0
- package/dist/modules/profile.d.ts +92 -0
- package/dist/modules/profile.d.ts.map +1 -0
- package/dist/modules/profile.js +125 -0
- package/dist/types/chats.cjs +2 -0
- package/dist/types/chats.d.ts +62 -0
- package/dist/types/chats.d.ts.map +1 -0
- package/dist/types/chats.js +1 -0
- package/dist/types/groups.cjs +2 -0
- package/dist/types/groups.d.ts +47 -0
- package/dist/types/groups.d.ts.map +1 -0
- package/dist/types/groups.js +1 -0
- package/dist/types/index.cjs +22 -0
- package/dist/types/index.d.ts +34 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +6 -0
- package/dist/types/instances.cjs +2 -0
- package/dist/types/instances.d.ts +65 -0
- package/dist/types/instances.d.ts.map +1 -0
- package/dist/types/instances.js +1 -0
- package/dist/types/messages.cjs +2 -0
- package/dist/types/messages.d.ts +86 -0
- package/dist/types/messages.d.ts.map +1 -0
- package/dist/types/messages.js +1 -0
- package/dist/types/profile.cjs +2 -0
- package/dist/types/profile.d.ts +25 -0
- package/dist/types/profile.d.ts.map +1 -0
- package/dist/types/profile.js +1 -0
- package/dist/types/webhooks.cjs +2 -0
- package/dist/types/webhooks.d.ts +17 -0
- package/dist/types/webhooks.d.ts.map +1 -0
- package/dist/types/webhooks.js +1 -0
- package/dist/webhooks/index.cjs +71 -0
- package/dist/webhooks/index.d.ts +26 -0
- package/dist/webhooks/index.d.ts.map +1 -0
- package/dist/webhooks/index.js +67 -0
- package/package.json +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Botcast (https://botcast.site)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
# botcast-sdk
|
|
2
|
+
|
|
3
|
+
Node.js and TypeScript client for [Botcast](https://botcast.site), a multi-instance WhatsApp API gateway.
|
|
4
|
+
|
|
5
|
+
Connect WhatsApp numbers, send messages (text, OTP, media, documents, polls), manage group chats, and process incoming webhooks.
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/botcast-sdk)
|
|
8
|
+
[](https://opensource.org/licenses/MIT)
|
|
9
|
+
[](https://www.typescriptlang.org/)
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install botcast-sdk
|
|
17
|
+
# or
|
|
18
|
+
yarn add botcast-sdk
|
|
19
|
+
# or
|
|
20
|
+
pnpm add botcast-sdk
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Quick start
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { BotcastClient } from 'botcast-sdk';
|
|
29
|
+
|
|
30
|
+
const botcast = new BotcastClient({
|
|
31
|
+
baseUrl: 'https://botcast.site', // or your self-hosted server URL
|
|
32
|
+
instanceId: 'your_instance_id',
|
|
33
|
+
instanceToken: 'your_instance_token',
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
async function main() {
|
|
37
|
+
// 1. Check WhatsApp connection status
|
|
38
|
+
const status = await botcast.instances.getStatus();
|
|
39
|
+
console.log('Status:', status.status, 'Phone:', status.phoneNumber);
|
|
40
|
+
|
|
41
|
+
// 2. Send a text message
|
|
42
|
+
const result = await botcast.messages.sendText('201000000000', 'Hello from Botcast SDK');
|
|
43
|
+
console.log('Sent message ID:', result.messageId);
|
|
44
|
+
|
|
45
|
+
// 3. Send an OTP verification code
|
|
46
|
+
const otp = await botcast.messages.sendOTP('201000000000', {
|
|
47
|
+
code: '849201',
|
|
48
|
+
appName: 'My SaaS App',
|
|
49
|
+
expiryMinutes: 5,
|
|
50
|
+
});
|
|
51
|
+
console.log('OTP dispatched:', otp.codeSent);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
main().catch(console.error);
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## CommonJS usage
|
|
60
|
+
|
|
61
|
+
```javascript
|
|
62
|
+
const { BotcastClient } = require('botcast-sdk');
|
|
63
|
+
|
|
64
|
+
const botcast = new BotcastClient({
|
|
65
|
+
instanceId: 'your_instance_id',
|
|
66
|
+
instanceToken: 'your_instance_token',
|
|
67
|
+
});
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## API reference
|
|
73
|
+
|
|
74
|
+
### 1. Instance management
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
// Get status and phone profile details
|
|
78
|
+
const status = await botcast.instances.getStatus();
|
|
79
|
+
|
|
80
|
+
// Get QR code string for scanning
|
|
81
|
+
const qr = await botcast.instances.getQR();
|
|
82
|
+
|
|
83
|
+
// Generate an 8-digit phone pairing code (no camera scan needed)
|
|
84
|
+
const pair = await botcast.instances.pairWithCode('201000000000');
|
|
85
|
+
console.log('Enter this code in WhatsApp:', pair.formattedCode); // e.g. 1234-5678
|
|
86
|
+
|
|
87
|
+
// Start, stop, or log out
|
|
88
|
+
await botcast.instances.start();
|
|
89
|
+
await botcast.instances.stop();
|
|
90
|
+
await botcast.instances.logout();
|
|
91
|
+
|
|
92
|
+
// Check whether a phone number is on WhatsApp
|
|
93
|
+
const check = await botcast.instances.checkNumber('201000000000');
|
|
94
|
+
console.log('Exists:', check.exists, 'JID:', check.jid);
|
|
95
|
+
|
|
96
|
+
// Set presence (typing, recording audio, online/offline)
|
|
97
|
+
await botcast.instances.setPresence({
|
|
98
|
+
presence: 'composing', // 'available' | 'unavailable' | 'composing' | 'recording' | 'paused'
|
|
99
|
+
recipient: '201000000000',
|
|
100
|
+
});
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
### 2. Messaging
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
// 1. Text message with mentions
|
|
109
|
+
await botcast.messages.sendText('201000000000', 'Hello @user', {
|
|
110
|
+
mentions: ['201000000000'],
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
// 2. Image with caption
|
|
114
|
+
await botcast.messages.sendImage('201000000000', {
|
|
115
|
+
url: 'https://example.com/invoice.png',
|
|
116
|
+
caption: 'Here is your monthly invoice.',
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
// 3. Document / PDF
|
|
120
|
+
await botcast.messages.sendDocument('201000000000', {
|
|
121
|
+
url: 'https://example.com/statement.pdf',
|
|
122
|
+
fileName: 'Statement_August.pdf',
|
|
123
|
+
mimetype: 'application/pdf',
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
// 4. Voice note (PTT waveform)
|
|
127
|
+
await botcast.messages.sendVoice('201000000000', {
|
|
128
|
+
url: 'https://example.com/audio-note.mp3',
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
// 5. Interactive poll
|
|
132
|
+
await botcast.messages.sendPoll('201000000000', {
|
|
133
|
+
name: 'How was our service?',
|
|
134
|
+
values: ['Great', 'Average', 'Needs work'],
|
|
135
|
+
selectableCount: 1,
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// 6. Contact card (vCard)
|
|
139
|
+
await botcast.messages.sendContact('201000000000', {
|
|
140
|
+
displayName: 'Customer Support',
|
|
141
|
+
vcard: 'BEGIN:VCARD\nVERSION:3.0\nFN:Customer Support\nTEL;TYPE=CELL:+201000000000\nEND:VCARD',
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
// 7. Message actions: react, pin, edit, delete for everyone
|
|
145
|
+
await botcast.messages.react('201000000000', msgKey, '👍');
|
|
146
|
+
await botcast.messages.pin('201000000000', msgKey, 1, 86400); // pin for 24 hours
|
|
147
|
+
await botcast.messages.edit('201000000000', msgKey, 'Updated text message');
|
|
148
|
+
await botcast.messages.delete('201000000000', msgKey); // Revoke for everyone
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
### 3. Group administration
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
// Create a group
|
|
157
|
+
const newGroup = await botcast.groups.create('VIP Customers', ['201000000000', '201111111111']);
|
|
158
|
+
|
|
159
|
+
// List joined groups
|
|
160
|
+
const groups = await botcast.groups.list();
|
|
161
|
+
|
|
162
|
+
// Add or remove participants
|
|
163
|
+
await botcast.groups.addParticipants('group-jid@g.us', ['201222222222']);
|
|
164
|
+
await botcast.groups.removeParticipants('group-jid@g.us', ['201222222222']);
|
|
165
|
+
|
|
166
|
+
// Promote or demote admins
|
|
167
|
+
await botcast.groups.promoteParticipants('group-jid@g.us', ['201000000000']);
|
|
168
|
+
|
|
169
|
+
// Update permissions and settings
|
|
170
|
+
await botcast.groups.updateSettings('group-jid@g.us', 'announcement'); // Only admins can send messages
|
|
171
|
+
await botcast.groups.updateSubject('group-jid@g.us', 'New Group Name');
|
|
172
|
+
await botcast.groups.updateDescription('group-jid@g.us', 'Official VIP group discussion.');
|
|
173
|
+
|
|
174
|
+
// Get invite link
|
|
175
|
+
const invite = await botcast.groups.getInviteCode('group-jid@g.us');
|
|
176
|
+
console.log('Invite link:', invite.link);
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
### 4. Webhook handling
|
|
182
|
+
|
|
183
|
+
The package includes a helper for parsing incoming events in Express, Fastify, Next.js, or plain Node HTTP:
|
|
184
|
+
|
|
185
|
+
#### Express example:
|
|
186
|
+
```typescript
|
|
187
|
+
import express from 'express';
|
|
188
|
+
import { BotcastClient } from 'botcast-sdk';
|
|
189
|
+
|
|
190
|
+
const app = express();
|
|
191
|
+
app.use(express.json());
|
|
192
|
+
|
|
193
|
+
const botcast = new BotcastClient({
|
|
194
|
+
instanceId: 'inst_123',
|
|
195
|
+
instanceToken: 'tok_abc',
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
// Listen for incoming messages
|
|
199
|
+
botcast.webhook.onMessage(async (event) => {
|
|
200
|
+
console.log(`Incoming message from +${event.sender}: ${event.message}`);
|
|
201
|
+
|
|
202
|
+
if (event.message.toLowerCase() === 'ping') {
|
|
203
|
+
await botcast.messages.sendText(event.sender, 'pong');
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
// Mount the webhook handler
|
|
208
|
+
app.post('/webhook', botcast.webhook.middleware());
|
|
209
|
+
|
|
210
|
+
app.listen(3000, () => console.log('Webhook server listening on port 3000'));
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
### 5. Error handling
|
|
216
|
+
|
|
217
|
+
The SDK maps API status codes to typed error classes:
|
|
218
|
+
|
|
219
|
+
```typescript
|
|
220
|
+
import {
|
|
221
|
+
BotcastClient,
|
|
222
|
+
BotcastAuthError,
|
|
223
|
+
BotcastPaymentRequiredError,
|
|
224
|
+
BotcastSubscriptionExpiredError,
|
|
225
|
+
BotcastRateLimitError,
|
|
226
|
+
} from 'botcast-sdk';
|
|
227
|
+
|
|
228
|
+
try {
|
|
229
|
+
await botcast.messages.sendText('201000000000', 'Test');
|
|
230
|
+
} catch (error) {
|
|
231
|
+
if (error instanceof BotcastAuthError) {
|
|
232
|
+
console.error('Invalid instance token or instance ID');
|
|
233
|
+
} else if (error instanceof BotcastPaymentRequiredError) {
|
|
234
|
+
console.error('Instance requires payment confirmation before sending messages');
|
|
235
|
+
} else if (error instanceof BotcastSubscriptionExpiredError) {
|
|
236
|
+
console.error('Instance subscription expired on:', error.expiresAt);
|
|
237
|
+
} else if (error instanceof BotcastRateLimitError) {
|
|
238
|
+
console.error('Rate limit reached. Reduce request frequency.');
|
|
239
|
+
} else {
|
|
240
|
+
console.error('Request error:', error.message);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
---
|
|
246
|
+
|
|
247
|
+
## Links
|
|
248
|
+
|
|
249
|
+
- Website: [https://botcast.site](https://botcast.site)
|
|
250
|
+
- Dashboard: [https://botcast.site/?lang=en](https://botcast.site/?lang=en)
|
|
251
|
+
- Service health: [https://botcast.site/health](https://botcast.site/health)
|
|
252
|
+
|
|
253
|
+
---
|
|
254
|
+
|
|
255
|
+
## License
|
|
256
|
+
|
|
257
|
+
MIT (c) [Botcast](https://botcast.site)
|
package/dist/client.cjs
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BotcastClient = void 0;
|
|
4
|
+
const instances_js_1 = require("./modules/instances.js");
|
|
5
|
+
const messages_js_1 = require("./modules/messages.js");
|
|
6
|
+
const chats_js_1 = require("./modules/chats.js");
|
|
7
|
+
const groups_js_1 = require("./modules/groups.js");
|
|
8
|
+
const profile_js_1 = require("./modules/profile.js");
|
|
9
|
+
const broadcast_js_1 = require("./modules/broadcast.js");
|
|
10
|
+
const index_js_1 = require("./webhooks/index.js");
|
|
11
|
+
class BotcastClient {
|
|
12
|
+
config;
|
|
13
|
+
/** Instance Lifecycle & Connection Management */
|
|
14
|
+
instances;
|
|
15
|
+
/** WhatsApp Message Dispatcher (Text, OTP, Media, Polls, Reactions, etc.) */
|
|
16
|
+
messages;
|
|
17
|
+
/** Chats, Contacts, History, and Chat State Management */
|
|
18
|
+
chats;
|
|
19
|
+
/** WhatsApp Group Operations & Administration */
|
|
20
|
+
groups;
|
|
21
|
+
/** Profile, Avatar, About Status, and Privacy Settings */
|
|
22
|
+
profile;
|
|
23
|
+
/** WhatsApp Status Stories & Broadcast Lists */
|
|
24
|
+
broadcast;
|
|
25
|
+
/** Webhook Handler & Middleware */
|
|
26
|
+
webhook;
|
|
27
|
+
/**
|
|
28
|
+
* Initializes a new Botcast API Client.
|
|
29
|
+
*
|
|
30
|
+
* @param config Client configuration options
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { BotcastClient } from 'botcast-sdk';
|
|
35
|
+
*
|
|
36
|
+
* const botcast = new BotcastClient({
|
|
37
|
+
* baseUrl: 'https://botcast.site',
|
|
38
|
+
* instanceId: 'inst_abc123',
|
|
39
|
+
* instanceToken: 'token_xyz789'
|
|
40
|
+
* });
|
|
41
|
+
*
|
|
42
|
+
* // Send a text message
|
|
43
|
+
* await botcast.messages.sendText('201000000000', 'Hello from Botcast SDK!');
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
constructor(config) {
|
|
47
|
+
if (!config.instanceId) {
|
|
48
|
+
throw new Error('BotcastClient requires a valid "instanceId"');
|
|
49
|
+
}
|
|
50
|
+
if (!config.instanceToken) {
|
|
51
|
+
throw new Error('BotcastClient requires a valid "instanceToken"');
|
|
52
|
+
}
|
|
53
|
+
this.config = {
|
|
54
|
+
baseUrl: config.baseUrl || 'https://botcast.site',
|
|
55
|
+
instanceId: config.instanceId,
|
|
56
|
+
instanceToken: config.instanceToken,
|
|
57
|
+
timeout: config.timeout || 30000,
|
|
58
|
+
maxRetries: config.maxRetries ?? 2,
|
|
59
|
+
headers: config.headers || {},
|
|
60
|
+
};
|
|
61
|
+
this.instances = new instances_js_1.InstancesModule(this.config);
|
|
62
|
+
this.messages = new messages_js_1.MessagesModule(this.config);
|
|
63
|
+
this.chats = new chats_js_1.ChatsModule(this.config);
|
|
64
|
+
this.groups = new groups_js_1.GroupsModule(this.config);
|
|
65
|
+
this.profile = new profile_js_1.ProfileModule(this.config);
|
|
66
|
+
this.broadcast = new broadcast_js_1.BroadcastModule(this.config);
|
|
67
|
+
this.webhook = new index_js_1.BotcastWebhook();
|
|
68
|
+
}
|
|
69
|
+
// =========================================================================
|
|
70
|
+
// Top-Level Convenience Shortcuts
|
|
71
|
+
// =========================================================================
|
|
72
|
+
/**
|
|
73
|
+
* Shortcut to send a text message.
|
|
74
|
+
*/
|
|
75
|
+
async sendText(recipient, text) {
|
|
76
|
+
return this.messages.sendText(recipient, text);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Shortcut to send an automated OTP verification code.
|
|
80
|
+
*/
|
|
81
|
+
async sendOTP(recipient, options) {
|
|
82
|
+
return this.messages.sendOTP(recipient, options);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Shortcut to check instance connectivity status.
|
|
86
|
+
*/
|
|
87
|
+
async getStatus() {
|
|
88
|
+
return this.instances.getStatus();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.BotcastClient = BotcastClient;
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { BotcastClientConfig } from './types/index.js';
|
|
2
|
+
import { InstancesModule } from './modules/instances.js';
|
|
3
|
+
import { MessagesModule } from './modules/messages.js';
|
|
4
|
+
import { ChatsModule } from './modules/chats.js';
|
|
5
|
+
import { GroupsModule } from './modules/groups.js';
|
|
6
|
+
import { ProfileModule } from './modules/profile.js';
|
|
7
|
+
import { BroadcastModule } from './modules/broadcast.js';
|
|
8
|
+
import { BotcastWebhook } from './webhooks/index.js';
|
|
9
|
+
export declare class BotcastClient {
|
|
10
|
+
private config;
|
|
11
|
+
/** Instance Lifecycle & Connection Management */
|
|
12
|
+
instances: InstancesModule;
|
|
13
|
+
/** WhatsApp Message Dispatcher (Text, OTP, Media, Polls, Reactions, etc.) */
|
|
14
|
+
messages: MessagesModule;
|
|
15
|
+
/** Chats, Contacts, History, and Chat State Management */
|
|
16
|
+
chats: ChatsModule;
|
|
17
|
+
/** WhatsApp Group Operations & Administration */
|
|
18
|
+
groups: GroupsModule;
|
|
19
|
+
/** Profile, Avatar, About Status, and Privacy Settings */
|
|
20
|
+
profile: ProfileModule;
|
|
21
|
+
/** WhatsApp Status Stories & Broadcast Lists */
|
|
22
|
+
broadcast: BroadcastModule;
|
|
23
|
+
/** Webhook Handler & Middleware */
|
|
24
|
+
webhook: BotcastWebhook;
|
|
25
|
+
/**
|
|
26
|
+
* Initializes a new Botcast API Client.
|
|
27
|
+
*
|
|
28
|
+
* @param config Client configuration options
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* import { BotcastClient } from 'botcast-sdk';
|
|
33
|
+
*
|
|
34
|
+
* const botcast = new BotcastClient({
|
|
35
|
+
* baseUrl: 'https://botcast.site',
|
|
36
|
+
* instanceId: 'inst_abc123',
|
|
37
|
+
* instanceToken: 'token_xyz789'
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* // Send a text message
|
|
41
|
+
* await botcast.messages.sendText('201000000000', 'Hello from Botcast SDK!');
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
constructor(config: BotcastClientConfig);
|
|
45
|
+
/**
|
|
46
|
+
* Shortcut to send a text message.
|
|
47
|
+
*/
|
|
48
|
+
sendText(recipient: string, text: string): Promise<import("./types/messages.js").SendMessageResponse>;
|
|
49
|
+
/**
|
|
50
|
+
* Shortcut to send an automated OTP verification code.
|
|
51
|
+
*/
|
|
52
|
+
sendOTP(recipient: string, options?: {
|
|
53
|
+
code?: string;
|
|
54
|
+
appName?: string;
|
|
55
|
+
expiryMinutes?: number;
|
|
56
|
+
}): Promise<import("./types/messages.js").SendMessageResponse & {
|
|
57
|
+
codeSent: string;
|
|
58
|
+
}>;
|
|
59
|
+
/**
|
|
60
|
+
* Shortcut to check instance connectivity status.
|
|
61
|
+
*/
|
|
62
|
+
getStatus(): Promise<import("./types/instances.js").InstanceStatusResponse>;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAgC;IAE9C,iDAAiD;IAC1C,SAAS,EAAE,eAAe,CAAC;IAElC,6EAA6E;IACtE,QAAQ,EAAE,cAAc,CAAC;IAEhC,0DAA0D;IACnD,KAAK,EAAE,WAAW,CAAC;IAE1B,iDAAiD;IAC1C,MAAM,EAAE,YAAY,CAAC;IAE5B,0DAA0D;IACnD,OAAO,EAAE,aAAa,CAAC;IAE9B,gDAAgD;IACzC,SAAS,EAAE,eAAe,CAAC;IAElC,mCAAmC;IAC5B,OAAO,EAAE,cAAc,CAAC;IAE/B;;;;;;;;;;;;;;;;;;OAkBG;IACH,YAAY,MAAM,EAAE,mBAAmB,EAwBtC;IAMD;;OAEG;IACU,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,8DAEpD;IAED;;OAEG;IACU,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE;;OAE5G;IAED;;OAEG;IACU,SAAS,mEAErB;CACF"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { InstancesModule } from './modules/instances.js';
|
|
2
|
+
import { MessagesModule } from './modules/messages.js';
|
|
3
|
+
import { ChatsModule } from './modules/chats.js';
|
|
4
|
+
import { GroupsModule } from './modules/groups.js';
|
|
5
|
+
import { ProfileModule } from './modules/profile.js';
|
|
6
|
+
import { BroadcastModule } from './modules/broadcast.js';
|
|
7
|
+
import { BotcastWebhook } from './webhooks/index.js';
|
|
8
|
+
export class BotcastClient {
|
|
9
|
+
config;
|
|
10
|
+
/** Instance Lifecycle & Connection Management */
|
|
11
|
+
instances;
|
|
12
|
+
/** WhatsApp Message Dispatcher (Text, OTP, Media, Polls, Reactions, etc.) */
|
|
13
|
+
messages;
|
|
14
|
+
/** Chats, Contacts, History, and Chat State Management */
|
|
15
|
+
chats;
|
|
16
|
+
/** WhatsApp Group Operations & Administration */
|
|
17
|
+
groups;
|
|
18
|
+
/** Profile, Avatar, About Status, and Privacy Settings */
|
|
19
|
+
profile;
|
|
20
|
+
/** WhatsApp Status Stories & Broadcast Lists */
|
|
21
|
+
broadcast;
|
|
22
|
+
/** Webhook Handler & Middleware */
|
|
23
|
+
webhook;
|
|
24
|
+
/**
|
|
25
|
+
* Initializes a new Botcast API Client.
|
|
26
|
+
*
|
|
27
|
+
* @param config Client configuration options
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { BotcastClient } from 'botcast-sdk';
|
|
32
|
+
*
|
|
33
|
+
* const botcast = new BotcastClient({
|
|
34
|
+
* baseUrl: 'https://botcast.site',
|
|
35
|
+
* instanceId: 'inst_abc123',
|
|
36
|
+
* instanceToken: 'token_xyz789'
|
|
37
|
+
* });
|
|
38
|
+
*
|
|
39
|
+
* // Send a text message
|
|
40
|
+
* await botcast.messages.sendText('201000000000', 'Hello from Botcast SDK!');
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
constructor(config) {
|
|
44
|
+
if (!config.instanceId) {
|
|
45
|
+
throw new Error('BotcastClient requires a valid "instanceId"');
|
|
46
|
+
}
|
|
47
|
+
if (!config.instanceToken) {
|
|
48
|
+
throw new Error('BotcastClient requires a valid "instanceToken"');
|
|
49
|
+
}
|
|
50
|
+
this.config = {
|
|
51
|
+
baseUrl: config.baseUrl || 'https://botcast.site',
|
|
52
|
+
instanceId: config.instanceId,
|
|
53
|
+
instanceToken: config.instanceToken,
|
|
54
|
+
timeout: config.timeout || 30000,
|
|
55
|
+
maxRetries: config.maxRetries ?? 2,
|
|
56
|
+
headers: config.headers || {},
|
|
57
|
+
};
|
|
58
|
+
this.instances = new InstancesModule(this.config);
|
|
59
|
+
this.messages = new MessagesModule(this.config);
|
|
60
|
+
this.chats = new ChatsModule(this.config);
|
|
61
|
+
this.groups = new GroupsModule(this.config);
|
|
62
|
+
this.profile = new ProfileModule(this.config);
|
|
63
|
+
this.broadcast = new BroadcastModule(this.config);
|
|
64
|
+
this.webhook = new BotcastWebhook();
|
|
65
|
+
}
|
|
66
|
+
// =========================================================================
|
|
67
|
+
// Top-Level Convenience Shortcuts
|
|
68
|
+
// =========================================================================
|
|
69
|
+
/**
|
|
70
|
+
* Shortcut to send a text message.
|
|
71
|
+
*/
|
|
72
|
+
async sendText(recipient, text) {
|
|
73
|
+
return this.messages.sendText(recipient, text);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Shortcut to send an automated OTP verification code.
|
|
77
|
+
*/
|
|
78
|
+
async sendOTP(recipient, options) {
|
|
79
|
+
return this.messages.sendOTP(recipient, options);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Shortcut to check instance connectivity status.
|
|
83
|
+
*/
|
|
84
|
+
async getStatus() {
|
|
85
|
+
return this.instances.getStatus();
|
|
86
|
+
}
|
|
87
|
+
}
|
package/dist/errors.cjs
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BotcastNotFoundError = exports.BotcastValidationError = exports.BotcastRateLimitError = exports.BotcastSubscriptionExpiredError = exports.BotcastPaymentRequiredError = exports.BotcastAuthError = exports.BotcastError = void 0;
|
|
4
|
+
class BotcastError extends Error {
|
|
5
|
+
statusCode;
|
|
6
|
+
details;
|
|
7
|
+
constructor(message, statusCode, details) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = 'BotcastError';
|
|
10
|
+
this.statusCode = statusCode;
|
|
11
|
+
this.details = details;
|
|
12
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.BotcastError = BotcastError;
|
|
16
|
+
class BotcastAuthError extends BotcastError {
|
|
17
|
+
constructor(message = 'Unauthorized: Invalid instance credentials', details) {
|
|
18
|
+
super(message, 401, details);
|
|
19
|
+
this.name = 'BotcastAuthError';
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.BotcastAuthError = BotcastAuthError;
|
|
23
|
+
class BotcastPaymentRequiredError extends BotcastError {
|
|
24
|
+
constructor(message = 'Payment Required: Instance is awaiting payment confirmation', details) {
|
|
25
|
+
super(message, 402, details);
|
|
26
|
+
this.name = 'BotcastPaymentRequiredError';
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.BotcastPaymentRequiredError = BotcastPaymentRequiredError;
|
|
30
|
+
class BotcastSubscriptionExpiredError extends BotcastError {
|
|
31
|
+
expiresAt;
|
|
32
|
+
constructor(message = 'Subscription Expired', expiresAt, details) {
|
|
33
|
+
super(message, 403, details);
|
|
34
|
+
this.name = 'BotcastSubscriptionExpiredError';
|
|
35
|
+
this.expiresAt = expiresAt;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.BotcastSubscriptionExpiredError = BotcastSubscriptionExpiredError;
|
|
39
|
+
class BotcastRateLimitError extends BotcastError {
|
|
40
|
+
constructor(message = 'Rate limit exceeded', details) {
|
|
41
|
+
super(message, 429, details);
|
|
42
|
+
this.name = 'BotcastRateLimitError';
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.BotcastRateLimitError = BotcastRateLimitError;
|
|
46
|
+
class BotcastValidationError extends BotcastError {
|
|
47
|
+
constructor(message = 'Validation Error: Invalid parameters provided', details) {
|
|
48
|
+
super(message, 400, details);
|
|
49
|
+
this.name = 'BotcastValidationError';
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.BotcastValidationError = BotcastValidationError;
|
|
53
|
+
class BotcastNotFoundError extends BotcastError {
|
|
54
|
+
constructor(message = 'Not Found: Resource or instance does not exist', details) {
|
|
55
|
+
super(message, 404, details);
|
|
56
|
+
this.name = 'BotcastNotFoundError';
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.BotcastNotFoundError = BotcastNotFoundError;
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare class BotcastError extends Error {
|
|
2
|
+
statusCode?: number;
|
|
3
|
+
details?: any;
|
|
4
|
+
constructor(message: string, statusCode?: number, details?: any);
|
|
5
|
+
}
|
|
6
|
+
export declare class BotcastAuthError extends BotcastError {
|
|
7
|
+
constructor(message?: string, details?: any);
|
|
8
|
+
}
|
|
9
|
+
export declare class BotcastPaymentRequiredError extends BotcastError {
|
|
10
|
+
constructor(message?: string, details?: any);
|
|
11
|
+
}
|
|
12
|
+
export declare class BotcastSubscriptionExpiredError extends BotcastError {
|
|
13
|
+
expiresAt?: string;
|
|
14
|
+
constructor(message?: string, expiresAt?: string, details?: any);
|
|
15
|
+
}
|
|
16
|
+
export declare class BotcastRateLimitError extends BotcastError {
|
|
17
|
+
constructor(message?: string, details?: any);
|
|
18
|
+
}
|
|
19
|
+
export declare class BotcastValidationError extends BotcastError {
|
|
20
|
+
constructor(message?: string, details?: any);
|
|
21
|
+
}
|
|
22
|
+
export declare class BotcastNotFoundError extends BotcastError {
|
|
23
|
+
constructor(message?: string, details?: any);
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,YAAa,SAAQ,KAAK;IAC9B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,GAAG,CAAC;IAErB,YAAY,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAM9D;CACF;AAED,qBAAa,gBAAiB,SAAQ,YAAY;IAChD,YAAY,OAAO,GAAE,MAAqD,EAAE,OAAO,CAAC,EAAE,GAAG,EAGxF;CACF;AAED,qBAAa,2BAA4B,SAAQ,YAAY;IAC3D,YAAY,OAAO,GAAE,MAAsE,EAAE,OAAO,CAAC,EAAE,GAAG,EAGzG;CACF;AAED,qBAAa,+BAAgC,SAAQ,YAAY;IACxD,SAAS,CAAC,EAAE,MAAM,CAAC;IAE1B,YAAY,OAAO,GAAE,MAA+B,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAItF;CACF;AAED,qBAAa,qBAAsB,SAAQ,YAAY;IACrD,YAAY,OAAO,GAAE,MAA8B,EAAE,OAAO,CAAC,EAAE,GAAG,EAGjE;CACF;AAED,qBAAa,sBAAuB,SAAQ,YAAY;IACtD,YAAY,OAAO,GAAE,MAAwD,EAAE,OAAO,CAAC,EAAE,GAAG,EAG3F;CACF;AAED,qBAAa,oBAAqB,SAAQ,YAAY;IACpD,YAAY,OAAO,GAAE,MAAyD,EAAE,OAAO,CAAC,EAAE,GAAG,EAG5F;CACF"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export class BotcastError extends Error {
|
|
2
|
+
statusCode;
|
|
3
|
+
details;
|
|
4
|
+
constructor(message, statusCode, details) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = 'BotcastError';
|
|
7
|
+
this.statusCode = statusCode;
|
|
8
|
+
this.details = details;
|
|
9
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export class BotcastAuthError extends BotcastError {
|
|
13
|
+
constructor(message = 'Unauthorized: Invalid instance credentials', details) {
|
|
14
|
+
super(message, 401, details);
|
|
15
|
+
this.name = 'BotcastAuthError';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export class BotcastPaymentRequiredError extends BotcastError {
|
|
19
|
+
constructor(message = 'Payment Required: Instance is awaiting payment confirmation', details) {
|
|
20
|
+
super(message, 402, details);
|
|
21
|
+
this.name = 'BotcastPaymentRequiredError';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export class BotcastSubscriptionExpiredError extends BotcastError {
|
|
25
|
+
expiresAt;
|
|
26
|
+
constructor(message = 'Subscription Expired', expiresAt, details) {
|
|
27
|
+
super(message, 403, details);
|
|
28
|
+
this.name = 'BotcastSubscriptionExpiredError';
|
|
29
|
+
this.expiresAt = expiresAt;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export class BotcastRateLimitError extends BotcastError {
|
|
33
|
+
constructor(message = 'Rate limit exceeded', details) {
|
|
34
|
+
super(message, 429, details);
|
|
35
|
+
this.name = 'BotcastRateLimitError';
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export class BotcastValidationError extends BotcastError {
|
|
39
|
+
constructor(message = 'Validation Error: Invalid parameters provided', details) {
|
|
40
|
+
super(message, 400, details);
|
|
41
|
+
this.name = 'BotcastValidationError';
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export class BotcastNotFoundError extends BotcastError {
|
|
45
|
+
constructor(message = 'Not Found: Resource or instance does not exist', details) {
|
|
46
|
+
super(message, 404, details);
|
|
47
|
+
this.name = 'BotcastNotFoundError';
|
|
48
|
+
}
|
|
49
|
+
}
|