innovators-bot2 2.0.3 → 2.0.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 CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  A powerful WhatsApp client library that provides seamless integration between Baileys and WhatsApp-web.js style APIs. This library makes it easy to create WhatsApp bots and automation tools with a familiar interface.
4
4
 
5
+ ## Community
6
+
7
+ > Join our Discord server for support, updates, and discussions:
8
+ > https://discord.gg/G3RfM6FDHS
9
+
5
10
  ## Features
6
11
 
7
12
  - 🚀 Easy to use, familiar WhatsApp-web.js style API
@@ -91,6 +96,19 @@ await client.sendMessage('1234567890@s.whatsapp.net', {
91
96
  })
92
97
  ```
93
98
 
99
+ ### Call Methods
100
+
101
+ ```javascript
102
+ // Initiate a voice call
103
+ const { callId } = await client.initiateCall(jid)
104
+
105
+ // Initiate a video call
106
+ const videoCall = await client.initiateCall(jid, { isVideo: true })
107
+
108
+ // Cancel an outgoing call
109
+ await client.cancelCall(callId, jid)
110
+ ```
111
+
94
112
  ### 2. Media Handling
95
113
 
96
114
  ```javascript
package/example.js CHANGED
@@ -167,6 +167,10 @@ async function start() {
167
167
  });
168
168
 
169
169
  // Listen for incoming messages
170
+ let lastOutgoingCallId = null;
171
+ let lastOutgoingCallJid = null;
172
+ let autoCancelCallTimer = null;
173
+
170
174
  client.on('message', async msg => {
171
175
 
172
176
  if (msg.body === '') {
@@ -363,6 +367,87 @@ async function start() {
363
367
  });
364
368
  break
365
369
 
370
+ case '!call':
371
+ try {
372
+ if (autoCancelCallTimer) {
373
+ clearTimeout(autoCancelCallTimer);
374
+ autoCancelCallTimer = null;
375
+ }
376
+ const result = await client.initiateCall(msg.from);
377
+ lastOutgoingCallId = result?.callId || null;
378
+ lastOutgoingCallJid = msg.from;
379
+
380
+ await client.sendMessage(msg.from, `Calling... CallId: ${lastOutgoingCallId || 'unknown'}`);
381
+
382
+ if (lastOutgoingCallId) {
383
+ autoCancelCallTimer = setTimeout(async () => {
384
+ try {
385
+ await client.cancelCall(lastOutgoingCallId, lastOutgoingCallJid);
386
+ } catch (error) {
387
+ console.error('Error auto-canceling call:', error);
388
+ } finally {
389
+ lastOutgoingCallId = null;
390
+ lastOutgoingCallJid = null;
391
+ autoCancelCallTimer = null;
392
+ }
393
+ }, 10000);
394
+ }
395
+ } catch (error) {
396
+ console.error('Error initiating voice call:', error);
397
+ await client.sendMessage(msg.from, 'Failed to initiate call');
398
+ }
399
+ break
400
+
401
+ case '!videocall':
402
+ try {
403
+ if (autoCancelCallTimer) {
404
+ clearTimeout(autoCancelCallTimer);
405
+ autoCancelCallTimer = null;
406
+ }
407
+ const result = await client.initiateCall(msg.from, { isVideo: true });
408
+ lastOutgoingCallId = result?.callId || null;
409
+ lastOutgoingCallJid = msg.from;
410
+ await client.sendMessage(msg.from, `Video calling... CallId: ${lastOutgoingCallId || 'unknown'}`);
411
+
412
+ if (lastOutgoingCallId) {
413
+ autoCancelCallTimer = setTimeout(async () => {
414
+ try {
415
+ await client.cancelCall(lastOutgoingCallId, lastOutgoingCallJid);
416
+ } catch (error) {
417
+ console.error('Error auto-canceling video call:', error);
418
+ } finally {
419
+ lastOutgoingCallId = null;
420
+ lastOutgoingCallJid = null;
421
+ autoCancelCallTimer = null;
422
+ }
423
+ }, 10000);
424
+ }
425
+ } catch (error) {
426
+ console.error('Error initiating video call:', error);
427
+ await client.sendMessage(msg.from, 'Failed to initiate video call');
428
+ }
429
+ break
430
+
431
+ case '!cancelcall':
432
+ try {
433
+ if (autoCancelCallTimer) {
434
+ clearTimeout(autoCancelCallTimer);
435
+ autoCancelCallTimer = null;
436
+ }
437
+ if (!lastOutgoingCallId) {
438
+ await client.sendMessage(msg.from, 'No outgoing call to cancel');
439
+ break;
440
+ }
441
+ await client.cancelCall(lastOutgoingCallId, msg.from);
442
+ await client.sendMessage(msg.from, `Canceled call: ${lastOutgoingCallId}`);
443
+ lastOutgoingCallId = null;
444
+ lastOutgoingCallJid = null;
445
+ } catch (error) {
446
+ console.error('Error canceling call:', error);
447
+ await client.sendMessage(msg.from, 'Failed to cancel call');
448
+ }
449
+ break
450
+
366
451
  case '!help':
367
452
  const help = `*📋 Available Commands List*\n\n` +
368
453
  `*🔹 Basic Commands*\n` +
@@ -422,6 +507,11 @@ async function start() {
422
507
  `• !buttons - Button template\n` +
423
508
  `• !list - Scrollable list\n\n` +
424
509
 
510
+ `*📞 Calls*\n` +
511
+ `• !call - Initiate a voice call\n` +
512
+ `• !videocall - Initiate a video call\n` +
513
+ `• !cancelcall - Cancel last outgoing call\n\n` +
514
+
425
515
  `*� Message Store*\n` +
426
516
  `• !messages - Get stored messages for this chat\n` +
427
517
  `• !allmessages - Get statistics for all stored chats\n` +
package/index.js CHANGED
@@ -1230,6 +1230,32 @@ class WhatsAppClient extends EventEmitter {
1230
1230
  }
1231
1231
  }
1232
1232
 
1233
+ async initiateCall(jid, options = {}) {
1234
+ if (!this.isConnected) {
1235
+ throw new Error('Client is not connected');
1236
+ }
1237
+
1238
+ try {
1239
+ return await this.sock.initiateCall(jid, options);
1240
+ } catch (error) {
1241
+ console.error('Error initiating call:', error);
1242
+ throw error;
1243
+ }
1244
+ }
1245
+
1246
+ async cancelCall(callId, jid) {
1247
+ if (!this.isConnected) {
1248
+ throw new Error('Client is not connected');
1249
+ }
1250
+
1251
+ try {
1252
+ return await this.sock.cancelCall(callId, jid);
1253
+ } catch (error) {
1254
+ console.error('Error canceling call:', error);
1255
+ throw error;
1256
+ }
1257
+ }
1258
+
1233
1259
  /**
1234
1260
  * Get the underlying socket instance
1235
1261
  * @returns {object} The socket instance
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "innovators-bot2",
3
- "version": "2.0.3",
3
+ "version": "2.0.4",
4
4
  "description": "WhatsApp API",
5
5
  "main": "index.js",
6
6
  "scripts": {