botcast-sdk 1.0.6 → 1.0.7

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.
Files changed (2) hide show
  1. package/README.md +109 -94
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -16,7 +16,7 @@ Official Node.js and TypeScript SDK for [Botcast](https://botcast.site) — a hi
16
16
  - **Strict TypeScript Types**: Fully typed request parameters, response models, error classes, and event payloads.
17
17
  - **Dual Authentication**:
18
18
  - **WhatsApp**: Scan QR code string or request an 8-digit PIN code without a camera.
19
- - **Telegram**: Scan QR code via *Telegram > Settings > Devices > Link Desktop Device* or authenticate via phone verification code with optional Cloud 2FA password.
19
+ - **Telegram**: Scan QR code via _Telegram > Settings > Devices > Link Desktop Device_ or authenticate via phone verification code with optional Cloud 2FA password.
20
20
  - **Unified Messaging**: Send text messages, automated OTP codes, images, videos, audio, voice notes (PTT), documents, stickers, locations, contact cards, and interactive polls.
21
21
  - **Message Operations**: Edit sent messages, delete for everyone (revoke), mark as read, reactions, pin messages, and forward.
22
22
  - **Chat & History Management**: Query dialogs, contact lists, and message history for both platforms.
@@ -46,10 +46,10 @@ bun add botcast-sdk
46
46
  Use `BotcastAdminClient` with your Master Partner API Key (`bcast_live_...`) to programmatically create and manage customer instances:
47
47
 
48
48
  ```typescript
49
- import { BotcastAdminClient } from 'botcast-sdk';
49
+ import { BotcastAdminClient } from "botcast-sdk";
50
50
 
51
51
  const admin = new BotcastAdminClient({
52
- baseUrl: 'https://botcast.site',
52
+ baseUrl: "https://botcast.site",
53
53
  apiKey: process.env.BOTCAST_API_KEY!, // Master API Key
54
54
  });
55
55
 
@@ -58,9 +58,9 @@ const { instances } = await admin.listInstances();
58
58
 
59
59
  // Create a new WhatsApp or Telegram instance for a customer
60
60
  const { instance } = await admin.createInstance({
61
- name: 'Customer Store 1',
62
- platform: 'whatsapp',
63
- type: 'paid',
61
+ name: "Customer Store 1",
62
+ platform: "whatsapp",
63
+ type: "paid",
64
64
  plan_months: 12,
65
65
  });
66
66
 
@@ -73,30 +73,35 @@ await admin.renewInstance(instance.id, { months: 12 });
73
73
  ### 2. WhatsApp Client
74
74
 
75
75
  ```typescript
76
- import { BotcastClient } from 'botcast-sdk';
76
+ import { BotcastClient } from "botcast-sdk";
77
77
 
78
78
  const whatsappBot = new BotcastClient({
79
- baseUrl: 'https://botcast.site', // or your self-hosted server URL
80
- platform: 'whatsapp', // 'whatsapp' (default) or 'telegram'
81
- instanceId: 'your_instance_id',
82
- instanceToken: 'your_instance_token',
79
+ baseUrl: "https://botcast.site", // or your self-hosted server URL
80
+ platform: "whatsapp", // 'whatsapp' (default) or 'telegram'
81
+ instanceId: "your_instance_id",
82
+ instanceToken: "your_instance_token",
83
83
  });
84
84
 
85
85
  async function main() {
86
86
  // Check connectivity
87
87
  const status = await whatsappBot.getStatus();
88
- console.log(`WhatsApp state: ${status.status} (${status.phoneNumber || 'Unpaired'})`);
88
+ console.log(
89
+ `WhatsApp state: ${status.status} (${status.phoneNumber || "Unpaired"})`,
90
+ );
89
91
 
90
92
  // Send a text message
91
- const res = await whatsappBot.messages.sendText('201012345678', 'Hello from WhatsApp via Botcast SDK!');
92
- console.log('Message sent! ID:', res.messageId);
93
+ const res = await whatsappBot.messages.sendText(
94
+ "201012345678",
95
+ "Hello from WhatsApp via Botcast SDK!",
96
+ );
97
+ console.log("Message sent! ID:", res.messageId);
93
98
 
94
99
  // Send a secure 6-digit OTP code
95
- const otp = await whatsappBot.messages.sendOTP('201012345678', {
96
- appName: 'My App',
100
+ const otp = await whatsappBot.messages.sendOTP("201012345678", {
101
+ appName: "My App",
97
102
  expiryMinutes: 5,
98
103
  });
99
- console.log('Dispatched OTP:', otp.codeSent);
104
+ console.log("Dispatched OTP:", otp.codeSent);
100
105
  }
101
106
 
102
107
  main().catch(console.error);
@@ -107,13 +112,13 @@ main().catch(console.error);
107
112
  ### 2. Telegram MTProto Client
108
113
 
109
114
  ```typescript
110
- import { BotcastClient } from 'botcast-sdk';
115
+ import { BotcastClient } from "botcast-sdk";
111
116
 
112
117
  const telegramBot = new BotcastClient({
113
- baseUrl: 'https://botcast.site',
114
- platform: 'telegram',
115
- instanceId: 'your_telegram_instance_id',
116
- instanceToken: 'your_telegram_instance_token',
118
+ baseUrl: "https://botcast.site",
119
+ platform: "telegram",
120
+ instanceId: "your_telegram_instance_id",
121
+ instanceToken: "your_telegram_instance_token",
117
122
  });
118
123
 
119
124
  async function main() {
@@ -122,20 +127,23 @@ async function main() {
122
127
  console.log(`Telegram state: ${status.status}`);
123
128
 
124
129
  // Send a text message to a phone number or @username
125
- const res = await telegramBot.messages.sendText('+1234567890', 'Hello from Telegram MTProto!');
126
- console.log('Message ID:', res.messageId);
130
+ const res = await telegramBot.messages.sendText(
131
+ "+1234567890",
132
+ "Hello from Telegram MTProto!",
133
+ );
134
+ console.log("Message ID:", res.messageId);
127
135
 
128
136
  // Send a photo
129
- await telegramBot.messages.sendImage('+1234567890', {
130
- url: 'https://images.unsplash.com/photo-1618005182384-a83a8bd57fbe?w=800',
131
- caption: 'Welcome flyer',
137
+ await telegramBot.messages.sendImage("+1234567890", {
138
+ url: "https://images.unsplash.com/photo-1618005182384-a83a8bd57fbe?w=800",
139
+ caption: "Welcome flyer",
132
140
  });
133
141
 
134
142
  // Send OTP
135
- const otp = await telegramBot.messages.sendOTP('+1234567890', {
136
- appName: 'Security Portal',
143
+ const otp = await telegramBot.messages.sendOTP("+1234567890", {
144
+ appName: "Security Portal",
137
145
  });
138
- console.log('Telegram OTP sent:', otp.codeSent);
146
+ console.log("Telegram OTP sent:", otp.codeSent);
139
147
  }
140
148
 
141
149
  main().catch(console.error);
@@ -146,12 +154,12 @@ main().catch(console.error);
146
154
  ### CommonJS (require)
147
155
 
148
156
  ```javascript
149
- const { BotcastClient } = require('botcast-sdk');
157
+ const { BotcastClient } = require("botcast-sdk");
150
158
 
151
159
  const client = new BotcastClient({
152
- platform: 'telegram', // or 'whatsapp'
153
- instanceId: 'your_instance_id',
154
- instanceToken: 'your_instance_token',
160
+ platform: "telegram", // or 'whatsapp'
161
+ instanceId: "your_instance_id",
162
+ instanceToken: "your_instance_token",
155
163
  });
156
164
  ```
157
165
 
@@ -164,24 +172,24 @@ const client = new BotcastClient({
164
172
  ```typescript
165
173
  // 1. Get live status
166
174
  const status = await client.instances.getStatus();
167
- console.log('State:', status.status); // 'connected' | 'qr_ready' | 'stopped' | 'connecting'
175
+ console.log("State:", status.status); // 'connected' | 'qr_ready' | 'stopped' | 'connecting'
168
176
 
169
177
  // 2. Option A: Get QR code string for camera scanning
170
178
  // (WhatsApp: Linked Devices | Telegram: Settings > Devices > Link Desktop Device)
171
179
  const qr = await client.getQR(); // or client.instances.getQR()
172
- console.log('QR DataURL:', qr.qr);
180
+ console.log("QR DataURL:", qr.qr);
173
181
 
174
182
  // 3. Option B: Request Phone Pairing / Login Code
175
183
  // (WhatsApp sends 8-digit PIN | Telegram sends verification code into app)
176
- const pair = await client.pairWithCode('+1234567890');
177
- console.log('Code request status:', pair);
184
+ const pair = await client.pairWithCode("+1234567890");
185
+ console.log("Code request status:", pair);
178
186
 
179
187
  // 4. Complete Telegram Phone Login (with optional 2FA cloud password)
180
- await client.instances.verifyCode('+1234567890', '12345', 'myCloudPassword2fa');
188
+ await client.instances.verifyCode("+1234567890", "12345", "myCloudPassword2fa");
181
189
 
182
190
  // 5. Socket engine controls
183
- await client.instances.start(); // Boots socket / MTProto connection
184
- await client.instances.stop(); // Suspends socket session
191
+ await client.instances.start(); // Boots socket / MTProto connection
192
+ await client.instances.stop(); // Suspends socket session
185
193
  await client.instances.logout(); // Unlinks device and clears session credentials
186
194
  ```
187
195
 
@@ -193,51 +201,51 @@ All messaging methods work across both **WhatsApp** and **Telegram**:
193
201
 
194
202
  ```typescript
195
203
  // 1. Text message
196
- await client.messages.sendText('+1234567890', 'Hello World', {
197
- mentions: ['1234567890'], // WhatsApp mentions
204
+ await client.messages.sendText("+1234567890", "Hello World", {
205
+ mentions: ["1234567890"], // WhatsApp mentions
198
206
  });
199
207
 
200
208
  // 2. Image / Photo
201
- await client.messages.sendImage('+1234567890', {
202
- url: 'https://images.unsplash.com/photo-1618005182384-a83a8bd57fbe?w=800',
203
- caption: 'Photo preview',
209
+ await client.messages.sendImage("+1234567890", {
210
+ url: "https://images.unsplash.com/photo-1618005182384-a83a8bd57fbe?w=800",
211
+ caption: "Photo preview",
204
212
  });
205
213
 
206
214
  // 3. Video
207
- await client.messages.sendVideo('+1234567890', {
208
- url: 'https://sample-videos.com/video321/mp4/720/big_buck_bunny_720p_1mb.mp4',
209
- caption: 'Product tutorial video',
215
+ await client.messages.sendVideo("+1234567890", {
216
+ url: "https://sample-videos.com/video321/mp4/720/big_buck_bunny_720p_1mb.mp4",
217
+ caption: "Product tutorial video",
210
218
  });
211
219
 
212
220
  // 4. Voice note and audio
213
- await client.messages.sendVoice('+1234567890', {
214
- url: 'https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3',
221
+ await client.messages.sendVoice("+1234567890", {
222
+ url: "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3",
215
223
  });
216
224
 
217
225
  // 5. Document / PDF / File
218
- await client.messages.sendDocument('+1234567890', {
219
- url: 'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf',
220
- fileName: 'Invoice_2026.pdf',
221
- caption: 'Monthly invoice statement',
226
+ await client.messages.sendDocument("+1234567890", {
227
+ url: "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf",
228
+ fileName: "Invoice_2026.pdf",
229
+ caption: "Monthly invoice statement",
222
230
  });
223
231
 
224
232
  // 6. Location coordinates
225
- await client.messages.sendLocation('+1234567890', {
233
+ await client.messages.sendLocation("+1234567890", {
226
234
  latitude: 24.7136,
227
235
  longitude: 46.6753,
228
- name: 'Kingdom Tower',
229
- address: 'King Fahd Rd, Riyadh, Saudi Arabia',
236
+ name: "Kingdom Tower",
237
+ address: "King Fahd Rd, Riyadh, Saudi Arabia",
230
238
  });
231
239
 
232
240
  // 7. Contact Card
233
- await client.messages.sendContact('+1234567890', {
234
- firstName: 'Support Agent',
235
- phone: '+1234567890',
241
+ await client.messages.sendContact("+1234567890", {
242
+ firstName: "Support Agent",
243
+ phone: "+1234567890",
236
244
  });
237
245
 
238
246
  // 8. Automated OTP verification code
239
- const otp = await client.messages.sendOTP('+1234567890', {
240
- appName: 'Botcast Portal',
247
+ const otp = await client.messages.sendOTP("+1234567890", {
248
+ appName: "Botcast Portal",
241
249
  expiryMinutes: 5,
242
250
  });
243
251
  ```
@@ -248,28 +256,30 @@ const otp = await client.messages.sendOTP('+1234567890', {
248
256
 
249
257
  ```typescript
250
258
  const msgKey = {
251
- remoteJid: '201012345678@s.whatsapp.net',
259
+ remoteJid: "201012345678@s.whatsapp.net",
252
260
  fromMe: true,
253
- id: '3EB0ABCDEF1234567890',
261
+ id: "3EB0ABCDEF1234567890",
254
262
  };
255
263
 
256
264
  // 1. Edit sent message
257
- await client.messages.edit('201012345678', msgKey, 'Corrected text content');
265
+ await client.messages.edit("201012345678", msgKey, "Corrected text content");
258
266
 
259
267
  // 2. Delete message for everyone (revoke)
260
- await client.messages.delete('201012345678', msgKey);
268
+ await client.messages.delete("201012345678", msgKey);
261
269
 
262
270
  // 3. Mark message as read
263
271
  await client.messages.markAsRead(msgKey);
264
272
 
265
273
  // 4. Emoji reaction
266
- await client.messages.react('201012345678', msgKey, '👍');
274
+ await client.messages.react("201012345678", msgKey, "👍");
267
275
 
268
276
  // 5. Pin message
269
- await client.messages.pin('201012345678', msgKey, 1, 86400);
277
+ await client.messages.pin("201012345678", msgKey, 1, 86400);
270
278
 
271
279
  // 6. Forward message
272
- await client.messages.forward('201012345678', { conversation: 'Forwarded message text' });
280
+ await client.messages.forward("201012345678", {
281
+ conversation: "Forwarded message text",
282
+ });
273
283
  ```
274
284
 
275
285
  ---
@@ -284,12 +294,15 @@ const { chats } = await client.chats.list({ limit: 50 });
284
294
  const { contacts } = await client.chats.listContacts({ limit: 100 });
285
295
 
286
296
  // 3. List messages for a chat
287
- const { messages } = await client.chats.listMessages({ chatJid: '201012345678@s.whatsapp.net', limit: 50 });
297
+ const { messages } = await client.chats.listMessages({
298
+ chatJid: "201012345678@s.whatsapp.net",
299
+ limit: 50,
300
+ });
288
301
 
289
302
  // 4. Modify WhatsApp chat state (archive, mute, pin, delete)
290
- await client.chats.archive('201012345678@s.whatsapp.net');
291
- await client.chats.mute('201012345678@s.whatsapp.net', 8 * 60 * 60 * 1000); // 8 hours
292
- await client.chats.pin('201012345678@s.whatsapp.net');
303
+ await client.chats.archive("201012345678@s.whatsapp.net");
304
+ await client.chats.mute("201012345678@s.whatsapp.net", 8 * 60 * 60 * 1000); // 8 hours
305
+ await client.chats.pin("201012345678@s.whatsapp.net");
293
306
  ```
294
307
 
295
308
  ---
@@ -301,24 +314,26 @@ The SDK includes a built-in event dispatcher and middleware for handling inbound
301
314
  #### Express Example
302
315
 
303
316
  ```typescript
304
- import express from 'express';
305
- import { BotcastClient } from 'botcast-sdk';
317
+ import express from "express";
318
+ import { BotcastClient } from "botcast-sdk";
306
319
 
307
320
  const app = express();
308
321
  app.use(express.json());
309
322
 
310
323
  const client = new BotcastClient({
311
- platform: 'telegram', // or 'whatsapp'
312
- instanceId: 'inst_123',
313
- instanceToken: 'tok_abc',
324
+ platform: "telegram", // or 'whatsapp'
325
+ instanceId: "inst_123",
326
+ instanceToken: "tok_abc",
314
327
  });
315
328
 
316
329
  // Listen for incoming messages
317
330
  client.webhook.onMessage(async (event) => {
318
- console.log(`Message from ${event.sender}: ${event.message} [Platform: ${event.platform || 'whatsapp'}]`);
331
+ console.log(
332
+ `Message from ${event.sender}: ${event.message} [Platform: ${event.platform || "whatsapp"}]`,
333
+ );
319
334
 
320
- if (event.message.trim().toLowerCase() === 'ping') {
321
- await client.messages.sendText(event.sender, 'pong');
335
+ if (event.message.trim().toLowerCase() === "ping") {
336
+ await client.messages.sendText(event.sender, "pong");
322
337
  }
323
338
  });
324
339
 
@@ -328,9 +343,9 @@ client.webhook.onConnection(async (event) => {
328
343
  });
329
344
 
330
345
  // Mount middleware on your webhook route
331
- app.post('/webhook/botcast', client.webhook.middleware());
346
+ app.post("/webhook/botcast", client.webhook.middleware());
332
347
 
333
- app.listen(3000, () => console.log('Webhook server running on port 3000'));
348
+ app.listen(3000, () => console.log("Webhook server running on port 3000"));
334
349
  ```
335
350
 
336
351
  ---
@@ -348,25 +363,25 @@ import {
348
363
  BotcastRateLimitError,
349
364
  BotcastValidationError,
350
365
  BotcastNotFoundError,
351
- } from 'botcast-sdk';
366
+ } from "botcast-sdk";
352
367
 
353
368
  try {
354
- await client.messages.sendText('+1234567890', 'Hello World');
369
+ await client.messages.sendText("+1234567890", "Hello World");
355
370
  } catch (error) {
356
371
  if (error instanceof BotcastAuthError) {
357
- console.error('Invalid instance credentials or token.');
372
+ console.error("Invalid instance credentials or token.");
358
373
  } else if (error instanceof BotcastPaymentRequiredError) {
359
- console.error('Instance requires payment confirmation.');
374
+ console.error("Instance requires payment confirmation.");
360
375
  } else if (error instanceof BotcastSubscriptionExpiredError) {
361
- console.error('Subscription expired on:', error.expiresAt);
376
+ console.error("Subscription expired on:", error.expiresAt);
362
377
  } else if (error instanceof BotcastRateLimitError) {
363
- console.error('Daily message limit reached.');
378
+ console.error("Daily message limit reached.");
364
379
  } else if (error instanceof BotcastValidationError) {
365
- console.error('Validation error:', error.message, error.details);
380
+ console.error("Validation error:", error.message, error.details);
366
381
  } else if (error instanceof BotcastNotFoundError) {
367
- console.error('Resource not found:', error.message);
382
+ console.error("Resource not found:", error.message);
368
383
  } else {
369
- console.error('Unexpected error:', error);
384
+ console.error("Unexpected error:", error);
370
385
  }
371
386
  }
372
387
  ```
@@ -378,7 +393,7 @@ try {
378
393
  - Website: [https://botcast.site](https://botcast.site)
379
394
  - Documentation: [https://botcast.site/docs](https://botcast.site/docs)
380
395
  - NPM Package: [https://www.npmjs.com/package/botcast-sdk](https://www.npmjs.com/package/botcast-sdk)
381
- - GitHub Repository: [https://github.com/ANOOBALSA/Botcast](https://github.com/ANOOBALSA/Botcast)
396
+ - GitHub Repository: [https://github.com/alsasoft-web/Botcast](https://github.com/alsasoft-web/Botcast)
382
397
 
383
398
  ---
384
399
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "botcast-sdk",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "Official TypeScript/JavaScript SDK for Botcast WhatsApp & Telegram MTProto Multi-Instance API Gateway",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -51,7 +51,7 @@
51
51
  "homepage": "https://botcast.site",
52
52
  "repository": {
53
53
  "type": "git",
54
- "url": "git+https://github.com/ANOOBALSA/botcast-sdk.git",
54
+ "url": "git+https://github.com/alsasoft-web/botcast-sdk.git",
55
55
  "directory": "packages/botcast-sdk"
56
56
  },
57
57
  "bugs": {