wa-multi-mongodb 3.10.4 → 3.10.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.
- package/dist/Socket/index.d.ts.map +1 -1
- package/dist/Socket/index.js +99 -31
- package/dist/Types/index.d.ts +26 -5
- package/dist/Types/index.d.ts.map +1 -1
- package/dist/cjs/Socket/index.d.ts.map +1 -1
- package/dist/cjs/Socket/index.js +98 -30
- package/dist/cjs/Types/index.d.ts +26 -5
- package/dist/cjs/Types/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/readme.md +112 -26
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Socket/index.ts"],"names":[],"mappings":"AAAA,OAAqB,EAInB,QAAQ,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Socket/index.ts"],"names":[],"mappings":"AAAA,OAAqB,EAInB,QAAQ,EAET,MAAM,SAAS,CAAC;AAMjB,OAAO,KAAK,EAEV,eAAe,EACf,cAAc,EACd,kBAAkB,EAEnB,MAAM,UAAU,CAAC;AAqHlB;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAU,KAAK,MAAM,kBAkB5C,CAAC;AAEF,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,GAAG,QAEjD;AAkBD,eAAO,MAAM,YAAY,GACvB,kBAAuB,EACvB,UAAS,kBAAsC,KAC9C,OAAO,CAAC,QAAQ,CA+JlB,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,2BAA2B,GACtC,WAAW,MAAM,EACjB,aAAa,MAAM,EACnB,UAAS,kBAAuB,KAC/B,OAAO,CAAC,QAAQ,CAiNlB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,aAAa,iCArYf,kBAAkB,KAC1B,OAAO,CAAC,QAAQ,CAoYsB,CAAC;AA4C1C,eAAO,MAAM,aAAa,GAAU,WAAW,MAAM,kBAmCpD,CAAC;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;;;;GAsBG;AACH,eAAO,MAAM,WAAW,GAAU,WAAW,MAAM,EAAE,KAAK,MAAM,KAAG,OAAO,CAAC,mBAAmB,CA8C7F,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,WAAW,GAAU,WAAW,MAAM,EAAE,IAAI,MAAM,KAAG,OAAO,CAAC,kBAAkB,CAgD3F,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,iBAAiB,GAAU,WAAW,MAAM,KAAG,OAAO,CAAC,eAAe,EAAE,CA6CpF,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,WAAW,GAAI,KAAK,MAAM,KAAG,OAEzC,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,UAAU,GAAI,KAAK,MAAM,KAAG,OAExC,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,aAAa,GAAU,WAAW,MAAM,EAAE,KAAK,MAAM,KAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAoCzF,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,KAAK,GAAU,WAAW,MAAM,EAAE,KAAK,MAAM,KAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAkBjF,CAAC"}
|
package/dist/Socket/index.js
CHANGED
|
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import makeWASocket, { Browsers, DisconnectReason, fetchLatestBaileysVersion, } from "baileys";
|
|
10
|
+
import makeWASocket, { Browsers, DisconnectReason, fetchLatestBaileysVersion, jidNormalizedUser } from "baileys";
|
|
11
11
|
import path from "path";
|
|
12
12
|
import fs from "fs";
|
|
13
13
|
import QRCode from "qrcode";
|
|
@@ -21,31 +21,74 @@ import { MongoClient } from "mongodb";
|
|
|
21
21
|
import { useMongoAuthState } from "../Utils/mongo-auth-state.js";
|
|
22
22
|
import { createDelay } from "../Utils/create-delay.js";
|
|
23
23
|
const sessions = new Map();
|
|
24
|
+
/**
|
|
25
|
+
* Valid PlatformType values that WhatsApp recognizes
|
|
26
|
+
* These will be displayed as-is in "Linked Devices"
|
|
27
|
+
*/
|
|
28
|
+
const VALID_PLATFORM_TYPES = [
|
|
29
|
+
"Chrome", "Firefox", "Safari", "Edge", "Opera", "IE", "Desktop"
|
|
30
|
+
];
|
|
24
31
|
/**
|
|
25
32
|
* Helper function to generate browser configuration based on type and name
|
|
26
|
-
* @param browserType -
|
|
27
|
-
* @param browserName -
|
|
33
|
+
* @param browserType - OS type (ubuntu, macOS, windows, appropriate)
|
|
34
|
+
* @param browserName - Browser/app name to display in WhatsApp Linked Devices
|
|
35
|
+
* @param displayBrowser - Browser type to display for custom names (default: Chrome)
|
|
28
36
|
* @returns Browser configuration tuple for Baileys
|
|
37
|
+
*
|
|
38
|
+
* Display format in WhatsApp: `${browser[1]} (${browser[0]})`
|
|
39
|
+
*
|
|
40
|
+
* Examples:
|
|
41
|
+
* - browserType: "macOS", browserName: "Safari" → "Safari (Mac OS)"
|
|
42
|
+
* - browserType: "windows", browserName: "Chrome" → "Chrome (Windows)"
|
|
43
|
+
* - browserType: "windows", browserName: "My Bot" → "Chrome (My Bot)"
|
|
44
|
+
* - browserType: "windows", browserName: "My Bot", displayBrowser: "Safari" → "Safari (My Bot)"
|
|
29
45
|
*/
|
|
30
|
-
const getBrowserConfig = (browserType = "ubuntu", browserName = "Chrome") => {
|
|
31
|
-
|
|
46
|
+
const getBrowserConfig = (browserType = "ubuntu", browserName, displayBrowser = "Chrome") => {
|
|
47
|
+
// Default to Chrome if no browserName provided
|
|
48
|
+
const effectiveBrowserName = browserName || "Chrome";
|
|
49
|
+
// Validate displayBrowser - must be a valid PlatformType
|
|
50
|
+
const validDisplayBrowser = VALID_PLATFORM_TYPES.includes(displayBrowser) ? displayBrowser : "Chrome";
|
|
51
|
+
// Check if browserName is a valid PlatformType
|
|
52
|
+
const isValidPlatformType = VALID_PLATFORM_TYPES.includes(effectiveBrowserName);
|
|
53
|
+
if (isValidPlatformType) {
|
|
54
|
+
// Use standard Browsers helper - display will be "BrowserName (OsName)"
|
|
55
|
+
let browserTuple;
|
|
56
|
+
switch (browserType) {
|
|
57
|
+
case "macOS":
|
|
58
|
+
browserTuple = Browsers.macOS(effectiveBrowserName);
|
|
59
|
+
break;
|
|
60
|
+
case "windows":
|
|
61
|
+
browserTuple = Browsers.windows(effectiveBrowserName);
|
|
62
|
+
break;
|
|
63
|
+
case "appropriate":
|
|
64
|
+
browserTuple = Browsers.appropriate(effectiveBrowserName);
|
|
65
|
+
break;
|
|
66
|
+
case "ubuntu":
|
|
67
|
+
default:
|
|
68
|
+
browserTuple = Browsers.ubuntu(effectiveBrowserName);
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
return [...browserTuple];
|
|
72
|
+
}
|
|
73
|
+
// For custom browserName (not a valid PlatformType):
|
|
74
|
+
// Put custom name in browser[0], use displayBrowser as browser[1]
|
|
75
|
+
// Display will be: "displayBrowser (CustomName)"
|
|
76
|
+
let osVersion;
|
|
32
77
|
switch (browserType) {
|
|
33
78
|
case "macOS":
|
|
34
|
-
|
|
79
|
+
osVersion = "14.4.1";
|
|
35
80
|
break;
|
|
36
81
|
case "windows":
|
|
37
|
-
|
|
38
|
-
break;
|
|
39
|
-
case "appropriate":
|
|
40
|
-
browserTuple = Browsers.appropriate(browserName);
|
|
82
|
+
osVersion = "10.0.22631";
|
|
41
83
|
break;
|
|
42
84
|
case "ubuntu":
|
|
43
85
|
default:
|
|
44
|
-
|
|
86
|
+
osVersion = "22.04.4";
|
|
45
87
|
break;
|
|
46
88
|
}
|
|
47
|
-
//
|
|
48
|
-
|
|
89
|
+
// Return: [CustomName, displayBrowser, OsVersion]
|
|
90
|
+
// WhatsApp will display: "displayBrowser (CustomName)"
|
|
91
|
+
return [effectiveBrowserName, validDisplayBrowser, osVersion];
|
|
49
92
|
};
|
|
50
93
|
const callback = new Map();
|
|
51
94
|
const retryCount = new Map();
|
|
@@ -111,7 +154,7 @@ export const startSession = (...args_1) => __awaiter(void 0, [...args_1], void 0
|
|
|
111
154
|
auth: state,
|
|
112
155
|
logger: P,
|
|
113
156
|
markOnlineOnConnect: false,
|
|
114
|
-
browser: getBrowserConfig(options.browserType, options.browserName),
|
|
157
|
+
browser: getBrowserConfig(options.browserType, options.browserName, options.displayBrowser),
|
|
115
158
|
// Configure caching group metadata using our hybrid implementation with session ID
|
|
116
159
|
cachedGroupMetadata: (jid) => __awaiter(void 0, void 0, void 0, function* () {
|
|
117
160
|
return yield groupCache.get(sessionId, jid);
|
|
@@ -120,7 +163,7 @@ export const startSession = (...args_1) => __awaiter(void 0, [...args_1], void 0
|
|
|
120
163
|
sessions.set(sessionId, Object.assign({}, sock));
|
|
121
164
|
try {
|
|
122
165
|
sock.ev.process((events) => __awaiter(void 0, void 0, void 0, function* () {
|
|
123
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
166
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
124
167
|
if (events["connection.update"]) {
|
|
125
168
|
const update = events["connection.update"];
|
|
126
169
|
const { connection, lastDisconnect } = update;
|
|
@@ -228,12 +271,19 @@ export const startSession = (...args_1) => __awaiter(void 0, [...args_1], void 0
|
|
|
228
271
|
}
|
|
229
272
|
const msg = rawMsg;
|
|
230
273
|
msg.sessionId = sessionId;
|
|
274
|
+
// Get normalized sender phone number using toPhoneNumber
|
|
275
|
+
// For group messages, sender is in 'participant', for personal chats it's in 'remoteJid'
|
|
276
|
+
const isGroup = ((_r = (_q = msg.key) === null || _q === void 0 ? void 0 : _q.remoteJid) === null || _r === void 0 ? void 0 : _r.endsWith('@g.us')) || false;
|
|
277
|
+
const senderJid = isGroup
|
|
278
|
+
? (((_s = msg.key) === null || _s === void 0 ? void 0 : _s.participant) || '')
|
|
279
|
+
: (((_t = msg.key) === null || _t === void 0 ? void 0 : _t.remoteJid) || '');
|
|
280
|
+
msg.sender = yield toPhoneNumber(sessionId, senderJid);
|
|
231
281
|
msg.saveImage = (path) => saveImageHandler(msg, path);
|
|
232
282
|
msg.saveVideo = (path) => saveVideoHandler(msg, path);
|
|
233
283
|
msg.saveDocument = (path) => saveDocumentHandler(msg, path);
|
|
234
284
|
msg.saveAudio = (path) => saveAudioHandler(msg, path);
|
|
235
|
-
(
|
|
236
|
-
(
|
|
285
|
+
(_u = callback.get(CALLBACK_KEY.ON_MESSAGE_RECEIVED)) === null || _u === void 0 ? void 0 : _u(Object.assign({}, msg));
|
|
286
|
+
(_v = options.onMessageReceived) === null || _v === void 0 ? void 0 : _v.call(options, msg);
|
|
237
287
|
}
|
|
238
288
|
}
|
|
239
289
|
}));
|
|
@@ -270,7 +320,7 @@ export const startSessionWithPairingCode = (sessionId_1, phoneNumber_1, ...args_
|
|
|
270
320
|
auth: state,
|
|
271
321
|
logger: P,
|
|
272
322
|
markOnlineOnConnect: false,
|
|
273
|
-
browser: getBrowserConfig(options.browserType, options.browserName),
|
|
323
|
+
browser: getBrowserConfig(options.browserType, options.browserName, options.displayBrowser),
|
|
274
324
|
// Opsi tambahan untuk meningkatkan kompatibilitas
|
|
275
325
|
linkPreviewImageThumbnailWidth: 300,
|
|
276
326
|
generateHighQualityLinkPreview: true,
|
|
@@ -310,7 +360,7 @@ export const startSessionWithPairingCode = (sessionId_1, phoneNumber_1, ...args_
|
|
|
310
360
|
}
|
|
311
361
|
}
|
|
312
362
|
sock.ev.process((events) => __awaiter(void 0, void 0, void 0, function* () {
|
|
313
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
363
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
|
|
314
364
|
if (events["connection.update"]) {
|
|
315
365
|
const update = events["connection.update"];
|
|
316
366
|
const { connection, lastDisconnect } = update;
|
|
@@ -430,12 +480,19 @@ export const startSessionWithPairingCode = (sessionId_1, phoneNumber_1, ...args_
|
|
|
430
480
|
}
|
|
431
481
|
const msg = rawMsg;
|
|
432
482
|
msg.sessionId = sessionId;
|
|
483
|
+
// Get normalized sender phone number using toPhoneNumber
|
|
484
|
+
// For group messages, sender is in 'participant', for personal chats it's in 'remoteJid'
|
|
485
|
+
const isGroup = ((_q = (_p = msg.key) === null || _p === void 0 ? void 0 : _p.remoteJid) === null || _q === void 0 ? void 0 : _q.endsWith('@g.us')) || false;
|
|
486
|
+
const senderJid = isGroup
|
|
487
|
+
? (((_r = msg.key) === null || _r === void 0 ? void 0 : _r.participant) || '')
|
|
488
|
+
: (((_s = msg.key) === null || _s === void 0 ? void 0 : _s.remoteJid) || '');
|
|
489
|
+
msg.sender = yield toPhoneNumber(sessionId, senderJid);
|
|
433
490
|
msg.saveImage = (path) => saveImageHandler(msg, path);
|
|
434
491
|
msg.saveVideo = (path) => saveVideoHandler(msg, path);
|
|
435
492
|
msg.saveDocument = (path) => saveDocumentHandler(msg, path);
|
|
436
493
|
msg.saveAudio = (path) => saveAudioHandler(msg, path);
|
|
437
|
-
(
|
|
438
|
-
(
|
|
494
|
+
(_t = callback.get(CALLBACK_KEY.ON_MESSAGE_RECEIVED)) === null || _t === void 0 ? void 0 : _t(Object.assign({}, msg));
|
|
495
|
+
(_u = options.onMessageReceived) === null || _u === void 0 ? void 0 : _u.call(options, msg);
|
|
439
496
|
}
|
|
440
497
|
}
|
|
441
498
|
}));
|
|
@@ -882,8 +939,8 @@ export const getPNForLID = (sessionId, lid) => __awaiter(void 0, void 0, void 0,
|
|
|
882
939
|
error: "LID mapping not available in this session"
|
|
883
940
|
};
|
|
884
941
|
}
|
|
885
|
-
// Try to get the phone number for the LID
|
|
886
|
-
const pn = ((_b = (_a = signalRepo.lidMapping).getPNForLID) === null || _b === void 0 ? void 0 : _b.call(_a, normalizedLid)) || null;
|
|
942
|
+
// Try to get the phone number for the LID (getPNForLID is async!)
|
|
943
|
+
const pn = (yield ((_b = (_a = signalRepo.lidMapping).getPNForLID) === null || _b === void 0 ? void 0 : _b.call(_a, normalizedLid))) || null;
|
|
887
944
|
return {
|
|
888
945
|
success: pn !== null,
|
|
889
946
|
lid: normalizedLid,
|
|
@@ -1080,20 +1137,31 @@ export const isPNFormat = (jid) => {
|
|
|
1080
1137
|
* ```
|
|
1081
1138
|
*/
|
|
1082
1139
|
export const toPhoneNumber = (sessionId, jid) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1083
|
-
//
|
|
1140
|
+
// Handle null/undefined input
|
|
1141
|
+
if (!jid) {
|
|
1142
|
+
return null;
|
|
1143
|
+
}
|
|
1144
|
+
// If it's a group or broadcast, return null
|
|
1145
|
+
if (jid.includes('@g.us') || jid.includes('@broadcast')) {
|
|
1146
|
+
return null;
|
|
1147
|
+
}
|
|
1148
|
+
// If already in PN format, use jidNormalizedUser to remove device ID
|
|
1084
1149
|
if (isPNFormat(jid)) {
|
|
1085
|
-
|
|
1150
|
+
// Use jidNormalizedUser to normalize and remove device ID (e.g., :0, :1)
|
|
1151
|
+
const normalized = jidNormalizedUser(jid);
|
|
1152
|
+
return normalized || jid; // Fallback to original if normalization fails
|
|
1086
1153
|
}
|
|
1087
1154
|
// If it's an LID, try to convert
|
|
1088
1155
|
if (isLIDFormat(jid)) {
|
|
1089
|
-
const
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1156
|
+
const lidResult = yield getPNForLID(sessionId, jid);
|
|
1157
|
+
if (lidResult.pn) {
|
|
1158
|
+
// Use jidNormalizedUser to normalize the result and remove device ID
|
|
1159
|
+
const normalized = jidNormalizedUser(lidResult.pn);
|
|
1160
|
+
return normalized || lidResult.pn; // Fallback to original if normalization fails
|
|
1161
|
+
}
|
|
1094
1162
|
return null;
|
|
1095
1163
|
}
|
|
1096
|
-
// If it's just a number, format it as PN
|
|
1164
|
+
// If it's just a number, format it as PN (no device ID needed)
|
|
1097
1165
|
const phoneNumber = jid.replace(/\D/g, '');
|
|
1098
1166
|
if (phoneNumber.length >= 10) {
|
|
1099
1167
|
return `${phoneNumber}@s.whatsapp.net`;
|
package/dist/Types/index.d.ts
CHANGED
|
@@ -35,6 +35,11 @@ export interface MessageReceived extends proto.IWebMessageInfo {
|
|
|
35
35
|
* Your Session ID
|
|
36
36
|
*/
|
|
37
37
|
sessionId: string;
|
|
38
|
+
/**
|
|
39
|
+
* Sender's phone number in normalized format (without device ID)
|
|
40
|
+
* @example "6281234567890@s.whatsapp.net"
|
|
41
|
+
*/
|
|
42
|
+
sender: string | null;
|
|
38
43
|
/**
|
|
39
44
|
* @param path save image location path with extension
|
|
40
45
|
* @example "./myimage.jpg"
|
|
@@ -62,18 +67,34 @@ export interface StartSessionParams {
|
|
|
62
67
|
*/
|
|
63
68
|
printQR?: boolean;
|
|
64
69
|
/**
|
|
65
|
-
* Browser type for WhatsApp connection
|
|
70
|
+
* Browser type for WhatsApp connection (determines OS version used)
|
|
66
71
|
* Options: "ubuntu" (default), "macOS", "windows", "appropriate"
|
|
67
72
|
* @default "ubuntu"
|
|
68
73
|
*/
|
|
69
74
|
browserType?: BrowserType;
|
|
70
75
|
/**
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
76
|
+
* App/device name displayed in WhatsApp's "Linked Devices"
|
|
77
|
+
*
|
|
78
|
+
* If using valid browser name (Chrome, Safari, Firefox, Edge, Opera, IE, Desktop):
|
|
79
|
+
* - Display: "BrowserName (OsName)" e.g., "Safari (Mac OS)"
|
|
80
|
+
*
|
|
81
|
+
* If using custom name:
|
|
82
|
+
* - Display: "displayBrowser (CustomName)" e.g., "Safari (My Bot App)"
|
|
83
|
+
* - Default displayBrowser is "Chrome"
|
|
84
|
+
*
|
|
85
|
+
* @example "Safari" → displays as "Safari (Mac OS)"
|
|
86
|
+
* @example "My Bot App" → displays as "Chrome (My Bot App)" or "Safari (My Bot App)" if displayBrowser is set
|
|
75
87
|
*/
|
|
76
88
|
browserName?: string;
|
|
89
|
+
/**
|
|
90
|
+
* Browser type to display when using custom browserName
|
|
91
|
+
* Only used when browserName is NOT a valid browser type
|
|
92
|
+
* Valid options: "Chrome" (default), "Safari", "Firefox", "Edge", "Opera", "IE", "Desktop"
|
|
93
|
+
*
|
|
94
|
+
* @example displayBrowser: "Safari", browserName: "My Bot" → displays as "Safari (My Bot)"
|
|
95
|
+
* @default "Chrome"
|
|
96
|
+
*/
|
|
97
|
+
displayBrowser?: "Chrome" | "Safari" | "Firefox" | "Edge" | "Opera" | "IE" | "Desktop";
|
|
77
98
|
onQRUpdated?: (qr: string) => void;
|
|
78
99
|
onConnected?: () => void;
|
|
79
100
|
onConnecting?: () => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEjD;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,OAAO,GAAG,SAAS,GAAG,aAAa,CAAC;AAEzE,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,KAAK,CAAC,eAAe,CAAC;CACnC;AAED,MAAM,WAAW,2BAA4B,SAAQ,gBAAgB;IACnE,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AAED,MAAM,WAAW,cAAe,SAAQ,gBAAgB;IACtD,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,IAAI,EAAE,OA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E,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/C;AAED,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;;OAIG;IACH,WAAW,CAAC,EAAE,WAAW,CAAC;IAE1B;;;;;;;;;;;;OAYG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;;;;;OAOG;IACH,cAAc,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC;IAGvF,WAAW,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;IAC1B,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;IAC5B,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAGvC,iBAAiB,CAAC,EAAE,CAAC,OAAO,EAAE,eAAe,KAAK,IAAI,CAAC;IACvD,gBAAgB,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;CACtD;AAED,MAAM,WAAW,iCAAiC;IAChD;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,MAAM,cAAc,GAAG,eAAe,GAAG;IAC7C,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EACX,OAAO,GACP,SAAS,GACT,QAAQ,GACR,WAAW,GACX,MAAM,GACN,QAAQ,CAAC;CACZ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/Socket/index.ts"],"names":[],"mappings":"AAAA,OAAqB,EAInB,QAAQ,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/Socket/index.ts"],"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;;;GAiBG;AACH,eAAO,MAAM,aAAa,GAAU,WAAW,MAAM,EAAE,KAAK,MAAM,KAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAoCzF,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,KAAK,GAAU,WAAW,MAAM,EAAE,KAAK,MAAM,KAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAkBjF,CAAC"}
|
package/dist/cjs/Socket/index.js
CHANGED
|
@@ -61,31 +61,74 @@ const mongodb_1 = require("mongodb");
|
|
|
61
61
|
const mongo_auth_state_1 = require("../Utils/mongo-auth-state");
|
|
62
62
|
const create_delay_1 = require("../Utils/create-delay");
|
|
63
63
|
const sessions = new Map();
|
|
64
|
+
/**
|
|
65
|
+
* Valid PlatformType values that WhatsApp recognizes
|
|
66
|
+
* These will be displayed as-is in "Linked Devices"
|
|
67
|
+
*/
|
|
68
|
+
const VALID_PLATFORM_TYPES = [
|
|
69
|
+
"Chrome", "Firefox", "Safari", "Edge", "Opera", "IE", "Desktop"
|
|
70
|
+
];
|
|
64
71
|
/**
|
|
65
72
|
* Helper function to generate browser configuration based on type and name
|
|
66
|
-
* @param browserType -
|
|
67
|
-
* @param browserName -
|
|
73
|
+
* @param browserType - OS type (ubuntu, macOS, windows, appropriate)
|
|
74
|
+
* @param browserName - Browser/app name to display in WhatsApp Linked Devices
|
|
75
|
+
* @param displayBrowser - Browser type to display for custom names (default: Chrome)
|
|
68
76
|
* @returns Browser configuration tuple for Baileys
|
|
77
|
+
*
|
|
78
|
+
* Display format in WhatsApp: `${browser[1]} (${browser[0]})`
|
|
79
|
+
*
|
|
80
|
+
* Examples:
|
|
81
|
+
* - browserType: "macOS", browserName: "Safari" → "Safari (Mac OS)"
|
|
82
|
+
* - browserType: "windows", browserName: "Chrome" → "Chrome (Windows)"
|
|
83
|
+
* - browserType: "windows", browserName: "My Bot" → "Chrome (My Bot)"
|
|
84
|
+
* - browserType: "windows", browserName: "My Bot", displayBrowser: "Safari" → "Safari (My Bot)"
|
|
69
85
|
*/
|
|
70
|
-
const getBrowserConfig = (browserType = "ubuntu", browserName = "Chrome") => {
|
|
71
|
-
|
|
86
|
+
const getBrowserConfig = (browserType = "ubuntu", browserName, displayBrowser = "Chrome") => {
|
|
87
|
+
// Default to Chrome if no browserName provided
|
|
88
|
+
const effectiveBrowserName = browserName || "Chrome";
|
|
89
|
+
// Validate displayBrowser - must be a valid PlatformType
|
|
90
|
+
const validDisplayBrowser = VALID_PLATFORM_TYPES.includes(displayBrowser) ? displayBrowser : "Chrome";
|
|
91
|
+
// Check if browserName is a valid PlatformType
|
|
92
|
+
const isValidPlatformType = VALID_PLATFORM_TYPES.includes(effectiveBrowserName);
|
|
93
|
+
if (isValidPlatformType) {
|
|
94
|
+
// Use standard Browsers helper - display will be "BrowserName (OsName)"
|
|
95
|
+
let browserTuple;
|
|
96
|
+
switch (browserType) {
|
|
97
|
+
case "macOS":
|
|
98
|
+
browserTuple = baileys_1.Browsers.macOS(effectiveBrowserName);
|
|
99
|
+
break;
|
|
100
|
+
case "windows":
|
|
101
|
+
browserTuple = baileys_1.Browsers.windows(effectiveBrowserName);
|
|
102
|
+
break;
|
|
103
|
+
case "appropriate":
|
|
104
|
+
browserTuple = baileys_1.Browsers.appropriate(effectiveBrowserName);
|
|
105
|
+
break;
|
|
106
|
+
case "ubuntu":
|
|
107
|
+
default:
|
|
108
|
+
browserTuple = baileys_1.Browsers.ubuntu(effectiveBrowserName);
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
return [...browserTuple];
|
|
112
|
+
}
|
|
113
|
+
// For custom browserName (not a valid PlatformType):
|
|
114
|
+
// Put custom name in browser[0], use displayBrowser as browser[1]
|
|
115
|
+
// Display will be: "displayBrowser (CustomName)"
|
|
116
|
+
let osVersion;
|
|
72
117
|
switch (browserType) {
|
|
73
118
|
case "macOS":
|
|
74
|
-
|
|
119
|
+
osVersion = "14.4.1";
|
|
75
120
|
break;
|
|
76
121
|
case "windows":
|
|
77
|
-
|
|
78
|
-
break;
|
|
79
|
-
case "appropriate":
|
|
80
|
-
browserTuple = baileys_1.Browsers.appropriate(browserName);
|
|
122
|
+
osVersion = "10.0.22631";
|
|
81
123
|
break;
|
|
82
124
|
case "ubuntu":
|
|
83
125
|
default:
|
|
84
|
-
|
|
126
|
+
osVersion = "22.04.4";
|
|
85
127
|
break;
|
|
86
128
|
}
|
|
87
|
-
//
|
|
88
|
-
|
|
129
|
+
// Return: [CustomName, displayBrowser, OsVersion]
|
|
130
|
+
// WhatsApp will display: "displayBrowser (CustomName)"
|
|
131
|
+
return [effectiveBrowserName, validDisplayBrowser, osVersion];
|
|
89
132
|
};
|
|
90
133
|
const callback = new Map();
|
|
91
134
|
const retryCount = new Map();
|
|
@@ -152,7 +195,7 @@ const startSession = (...args_1) => __awaiter(void 0, [...args_1], void 0, funct
|
|
|
152
195
|
auth: state,
|
|
153
196
|
logger: P,
|
|
154
197
|
markOnlineOnConnect: false,
|
|
155
|
-
browser: getBrowserConfig(options.browserType, options.browserName),
|
|
198
|
+
browser: getBrowserConfig(options.browserType, options.browserName, options.displayBrowser),
|
|
156
199
|
// Configure caching group metadata using our hybrid implementation with session ID
|
|
157
200
|
cachedGroupMetadata: (jid) => __awaiter(void 0, void 0, void 0, function* () {
|
|
158
201
|
return yield Utils_1.groupCache.get(sessionId, jid);
|
|
@@ -161,7 +204,7 @@ const startSession = (...args_1) => __awaiter(void 0, [...args_1], void 0, funct
|
|
|
161
204
|
sessions.set(sessionId, Object.assign({}, sock));
|
|
162
205
|
try {
|
|
163
206
|
sock.ev.process((events) => __awaiter(void 0, void 0, void 0, function* () {
|
|
164
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
207
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
165
208
|
if (events["connection.update"]) {
|
|
166
209
|
const update = events["connection.update"];
|
|
167
210
|
const { connection, lastDisconnect } = update;
|
|
@@ -269,12 +312,19 @@ const startSession = (...args_1) => __awaiter(void 0, [...args_1], void 0, funct
|
|
|
269
312
|
}
|
|
270
313
|
const msg = rawMsg;
|
|
271
314
|
msg.sessionId = sessionId;
|
|
315
|
+
// Get normalized sender phone number using toPhoneNumber
|
|
316
|
+
// For group messages, sender is in 'participant', for personal chats it's in 'remoteJid'
|
|
317
|
+
const isGroup = ((_r = (_q = msg.key) === null || _q === void 0 ? void 0 : _q.remoteJid) === null || _r === void 0 ? void 0 : _r.endsWith('@g.us')) || false;
|
|
318
|
+
const senderJid = isGroup
|
|
319
|
+
? (((_s = msg.key) === null || _s === void 0 ? void 0 : _s.participant) || '')
|
|
320
|
+
: (((_t = msg.key) === null || _t === void 0 ? void 0 : _t.remoteJid) || '');
|
|
321
|
+
msg.sender = yield (0, exports.toPhoneNumber)(sessionId, senderJid);
|
|
272
322
|
msg.saveImage = (path) => (0, save_media_1.saveImageHandler)(msg, path);
|
|
273
323
|
msg.saveVideo = (path) => (0, save_media_1.saveVideoHandler)(msg, path);
|
|
274
324
|
msg.saveDocument = (path) => (0, save_media_1.saveDocumentHandler)(msg, path);
|
|
275
325
|
msg.saveAudio = (path) => (0, save_media_1.saveAudioHandler)(msg, path);
|
|
276
|
-
(
|
|
277
|
-
(
|
|
326
|
+
(_u = callback.get(Defaults_1.CALLBACK_KEY.ON_MESSAGE_RECEIVED)) === null || _u === void 0 ? void 0 : _u(Object.assign({}, msg));
|
|
327
|
+
(_v = options.onMessageReceived) === null || _v === void 0 ? void 0 : _v.call(options, msg);
|
|
278
328
|
}
|
|
279
329
|
}
|
|
280
330
|
}));
|
|
@@ -312,7 +362,7 @@ const startSessionWithPairingCode = (sessionId_1, phoneNumber_1, ...args_1) => _
|
|
|
312
362
|
auth: state,
|
|
313
363
|
logger: P,
|
|
314
364
|
markOnlineOnConnect: false,
|
|
315
|
-
browser: getBrowserConfig(options.browserType, options.browserName),
|
|
365
|
+
browser: getBrowserConfig(options.browserType, options.browserName, options.displayBrowser),
|
|
316
366
|
// Opsi tambahan untuk meningkatkan kompatibilitas
|
|
317
367
|
linkPreviewImageThumbnailWidth: 300,
|
|
318
368
|
generateHighQualityLinkPreview: true,
|
|
@@ -352,7 +402,7 @@ const startSessionWithPairingCode = (sessionId_1, phoneNumber_1, ...args_1) => _
|
|
|
352
402
|
}
|
|
353
403
|
}
|
|
354
404
|
sock.ev.process((events) => __awaiter(void 0, void 0, void 0, function* () {
|
|
355
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
405
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
|
|
356
406
|
if (events["connection.update"]) {
|
|
357
407
|
const update = events["connection.update"];
|
|
358
408
|
const { connection, lastDisconnect } = update;
|
|
@@ -472,12 +522,19 @@ const startSessionWithPairingCode = (sessionId_1, phoneNumber_1, ...args_1) => _
|
|
|
472
522
|
}
|
|
473
523
|
const msg = rawMsg;
|
|
474
524
|
msg.sessionId = sessionId;
|
|
525
|
+
// Get normalized sender phone number using toPhoneNumber
|
|
526
|
+
// For group messages, sender is in 'participant', for personal chats it's in 'remoteJid'
|
|
527
|
+
const isGroup = ((_q = (_p = msg.key) === null || _p === void 0 ? void 0 : _p.remoteJid) === null || _q === void 0 ? void 0 : _q.endsWith('@g.us')) || false;
|
|
528
|
+
const senderJid = isGroup
|
|
529
|
+
? (((_r = msg.key) === null || _r === void 0 ? void 0 : _r.participant) || '')
|
|
530
|
+
: (((_s = msg.key) === null || _s === void 0 ? void 0 : _s.remoteJid) || '');
|
|
531
|
+
msg.sender = yield (0, exports.toPhoneNumber)(sessionId, senderJid);
|
|
475
532
|
msg.saveImage = (path) => (0, save_media_1.saveImageHandler)(msg, path);
|
|
476
533
|
msg.saveVideo = (path) => (0, save_media_1.saveVideoHandler)(msg, path);
|
|
477
534
|
msg.saveDocument = (path) => (0, save_media_1.saveDocumentHandler)(msg, path);
|
|
478
535
|
msg.saveAudio = (path) => (0, save_media_1.saveAudioHandler)(msg, path);
|
|
479
|
-
(
|
|
480
|
-
(
|
|
536
|
+
(_t = callback.get(Defaults_1.CALLBACK_KEY.ON_MESSAGE_RECEIVED)) === null || _t === void 0 ? void 0 : _t(Object.assign({}, msg));
|
|
537
|
+
(_u = options.onMessageReceived) === null || _u === void 0 ? void 0 : _u.call(options, msg);
|
|
481
538
|
}
|
|
482
539
|
}
|
|
483
540
|
}));
|
|
@@ -949,8 +1006,8 @@ const getPNForLID = (sessionId, lid) => __awaiter(void 0, void 0, void 0, functi
|
|
|
949
1006
|
error: "LID mapping not available in this session"
|
|
950
1007
|
};
|
|
951
1008
|
}
|
|
952
|
-
// Try to get the phone number for the LID
|
|
953
|
-
const pn = ((_b = (_a = signalRepo.lidMapping).getPNForLID) === null || _b === void 0 ? void 0 : _b.call(_a, normalizedLid)) || null;
|
|
1009
|
+
// Try to get the phone number for the LID (getPNForLID is async!)
|
|
1010
|
+
const pn = (yield ((_b = (_a = signalRepo.lidMapping).getPNForLID) === null || _b === void 0 ? void 0 : _b.call(_a, normalizedLid))) || null;
|
|
954
1011
|
return {
|
|
955
1012
|
success: pn !== null,
|
|
956
1013
|
lid: normalizedLid,
|
|
@@ -1152,20 +1209,31 @@ exports.isPNFormat = isPNFormat;
|
|
|
1152
1209
|
* ```
|
|
1153
1210
|
*/
|
|
1154
1211
|
const toPhoneNumber = (sessionId, jid) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1155
|
-
//
|
|
1212
|
+
// Handle null/undefined input
|
|
1213
|
+
if (!jid) {
|
|
1214
|
+
return null;
|
|
1215
|
+
}
|
|
1216
|
+
// If it's a group or broadcast, return null
|
|
1217
|
+
if (jid.includes('@g.us') || jid.includes('@broadcast')) {
|
|
1218
|
+
return null;
|
|
1219
|
+
}
|
|
1220
|
+
// If already in PN format, use jidNormalizedUser to remove device ID
|
|
1156
1221
|
if ((0, exports.isPNFormat)(jid)) {
|
|
1157
|
-
|
|
1222
|
+
// Use jidNormalizedUser to normalize and remove device ID (e.g., :0, :1)
|
|
1223
|
+
const normalized = (0, baileys_1.jidNormalizedUser)(jid);
|
|
1224
|
+
return normalized || jid; // Fallback to original if normalization fails
|
|
1158
1225
|
}
|
|
1159
1226
|
// If it's an LID, try to convert
|
|
1160
1227
|
if ((0, exports.isLIDFormat)(jid)) {
|
|
1161
|
-
const
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1228
|
+
const lidResult = yield (0, exports.getPNForLID)(sessionId, jid);
|
|
1229
|
+
if (lidResult.pn) {
|
|
1230
|
+
// Use jidNormalizedUser to normalize the result and remove device ID
|
|
1231
|
+
const normalized = (0, baileys_1.jidNormalizedUser)(lidResult.pn);
|
|
1232
|
+
return normalized || lidResult.pn; // Fallback to original if normalization fails
|
|
1233
|
+
}
|
|
1166
1234
|
return null;
|
|
1167
1235
|
}
|
|
1168
|
-
// If it's just a number, format it as PN
|
|
1236
|
+
// If it's just a number, format it as PN (no device ID needed)
|
|
1169
1237
|
const phoneNumber = jid.replace(/\D/g, '');
|
|
1170
1238
|
if (phoneNumber.length >= 10) {
|
|
1171
1239
|
return `${phoneNumber}@s.whatsapp.net`;
|
|
@@ -35,6 +35,11 @@ export interface MessageReceived extends proto.IWebMessageInfo {
|
|
|
35
35
|
* Your Session ID
|
|
36
36
|
*/
|
|
37
37
|
sessionId: string;
|
|
38
|
+
/**
|
|
39
|
+
* Sender's phone number in normalized format (without device ID)
|
|
40
|
+
* @example "6281234567890@s.whatsapp.net"
|
|
41
|
+
*/
|
|
42
|
+
sender: string | null;
|
|
38
43
|
/**
|
|
39
44
|
* @param path save image location path with extension
|
|
40
45
|
* @example "./myimage.jpg"
|
|
@@ -62,18 +67,34 @@ export interface StartSessionParams {
|
|
|
62
67
|
*/
|
|
63
68
|
printQR?: boolean;
|
|
64
69
|
/**
|
|
65
|
-
* Browser type for WhatsApp connection
|
|
70
|
+
* Browser type for WhatsApp connection (determines OS version used)
|
|
66
71
|
* Options: "ubuntu" (default), "macOS", "windows", "appropriate"
|
|
67
72
|
* @default "ubuntu"
|
|
68
73
|
*/
|
|
69
74
|
browserType?: BrowserType;
|
|
70
75
|
/**
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
76
|
+
* App/device name displayed in WhatsApp's "Linked Devices"
|
|
77
|
+
*
|
|
78
|
+
* If using valid browser name (Chrome, Safari, Firefox, Edge, Opera, IE, Desktop):
|
|
79
|
+
* - Display: "BrowserName (OsName)" e.g., "Safari (Mac OS)"
|
|
80
|
+
*
|
|
81
|
+
* If using custom name:
|
|
82
|
+
* - Display: "displayBrowser (CustomName)" e.g., "Safari (My Bot App)"
|
|
83
|
+
* - Default displayBrowser is "Chrome"
|
|
84
|
+
*
|
|
85
|
+
* @example "Safari" → displays as "Safari (Mac OS)"
|
|
86
|
+
* @example "My Bot App" → displays as "Chrome (My Bot App)" or "Safari (My Bot App)" if displayBrowser is set
|
|
75
87
|
*/
|
|
76
88
|
browserName?: string;
|
|
89
|
+
/**
|
|
90
|
+
* Browser type to display when using custom browserName
|
|
91
|
+
* Only used when browserName is NOT a valid browser type
|
|
92
|
+
* Valid options: "Chrome" (default), "Safari", "Firefox", "Edge", "Opera", "IE", "Desktop"
|
|
93
|
+
*
|
|
94
|
+
* @example displayBrowser: "Safari", browserName: "My Bot" → displays as "Safari (My Bot)"
|
|
95
|
+
* @default "Chrome"
|
|
96
|
+
*/
|
|
97
|
+
displayBrowser?: "Chrome" | "Safari" | "Firefox" | "Edge" | "Opera" | "IE" | "Desktop";
|
|
77
98
|
onQRUpdated?: (qr: string) => void;
|
|
78
99
|
onConnected?: () => void;
|
|
79
100
|
onConnecting?: () => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/Types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,E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AAO,EAAE,eAAe,KAAK,IAAI,CAAC;IACvD,gBAAgB,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;CACtD;AAED,MAAM,WAAW,iCAAiC;IAChD;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,MAAM,cAAc,GAAG,eAAe,GAAG;IAC7C,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EACX,OAAO,GACP,SAAS,GACT,QAAQ,GACR,WAAW,GACX,MAAM,GACN,QAAQ,CAAC;CACZ,CAAC"}
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -116,10 +116,11 @@ await whatsapp.startSession("mysession2", {
|
|
|
116
116
|
});
|
|
117
117
|
|
|
118
118
|
// Start with custom browser configuration (v3.10.4+)
|
|
119
|
+
// Display: "Safari (Mac OS)" in WhatsApp Linked Devices
|
|
119
120
|
await whatsapp.startSession("mysession3", {
|
|
120
121
|
printQR: true,
|
|
121
|
-
browserType: "
|
|
122
|
-
browserName: "
|
|
122
|
+
browserType: "macOS", // Options: "ubuntu", "macOS", "windows", "appropriate"
|
|
123
|
+
browserName: "Safari", // Valid: Chrome, Safari, Firefox, Edge, Opera, IE, Desktop
|
|
123
124
|
onConnected: () => console.log("Connected with custom browser!"),
|
|
124
125
|
});
|
|
125
126
|
|
|
@@ -133,10 +134,11 @@ await whatsapp.startSessionWithPairingCode("mysession4", "6281234567890", {
|
|
|
133
134
|
}
|
|
134
135
|
});
|
|
135
136
|
|
|
136
|
-
// Pairing code with
|
|
137
|
+
// Pairing code with valid browser config - displays "Edge (Windows)"
|
|
138
|
+
// ⚠️ IMPORTANT: Pairing code ONLY works with valid browser configurations!
|
|
137
139
|
await whatsapp.startSessionWithPairingCode("mysession5", "6281234567890", {
|
|
138
|
-
browserType: "
|
|
139
|
-
browserName: "
|
|
140
|
+
browserType: "windows",
|
|
141
|
+
browserName: "Edge", // Must be valid: Chrome, Safari, Firefox, Edge, Opera, IE, Desktop
|
|
140
142
|
onPairingCode: (code) => console.log("Code:", code),
|
|
141
143
|
});
|
|
142
144
|
|
|
@@ -173,40 +175,125 @@ await whatsapp.reconnectAllPairingCodeSessions();
|
|
|
173
175
|
|
|
174
176
|
### Custom Browser Configuration (v3.10.4+)
|
|
175
177
|
|
|
176
|
-
|
|
178
|
+
Customize how your session appears in WhatsApp's "Linked Devices" list.
|
|
177
179
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
180
|
+
**Display Format in WhatsApp**: `browserName (OsName)` - e.g., "Safari (Mac OS)"
|
|
181
|
+
|
|
182
|
+
#### Valid browserName Values
|
|
183
|
+
|
|
184
|
+
These are recognized by WhatsApp and will display correctly:
|
|
185
|
+
|
|
186
|
+
| browserName | Description |
|
|
187
|
+
|-------------|-------------|
|
|
188
|
+
| `"Chrome"` | Google Chrome (default) |
|
|
189
|
+
| `"Safari"` | Apple Safari |
|
|
190
|
+
| `"Firefox"` | Mozilla Firefox |
|
|
191
|
+
| `"Edge"` | Microsoft Edge |
|
|
192
|
+
| `"Opera"` | Opera Browser |
|
|
193
|
+
| `"IE"` | Internet Explorer |
|
|
194
|
+
| `"Desktop"` | Generic Desktop App |
|
|
181
195
|
|
|
182
|
-
|
|
196
|
+
#### browserType Options
|
|
197
|
+
|
|
198
|
+
| browserType | OS Name Displayed | OS Version |
|
|
199
|
+
|-------------|-------------------|------------|
|
|
200
|
+
| `"ubuntu"` | Ubuntu | 22.04.4 |
|
|
201
|
+
| `"macOS"` | Mac OS | 14.4.1 |
|
|
202
|
+
| `"windows"` | Windows | 10.0.22631 |
|
|
203
|
+
| `"appropriate"` | Auto-detect | Based on platform |
|
|
204
|
+
|
|
205
|
+
#### Usage Examples
|
|
206
|
+
|
|
207
|
+
```javascript
|
|
208
|
+
// Safari on macOS → displays as "Safari (Mac OS)"
|
|
183
209
|
await whatsapp.startSession("session1", {
|
|
184
|
-
|
|
185
|
-
|
|
210
|
+
printQR: true,
|
|
211
|
+
browserType: "macOS",
|
|
212
|
+
browserName: "Safari",
|
|
186
213
|
});
|
|
187
214
|
|
|
215
|
+
// Chrome on Windows → displays as "Chrome (Windows)"
|
|
188
216
|
await whatsapp.startSession("session2", {
|
|
189
|
-
|
|
190
|
-
|
|
217
|
+
printQR: true,
|
|
218
|
+
browserType: "windows",
|
|
219
|
+
browserName: "Chrome",
|
|
191
220
|
});
|
|
192
221
|
|
|
222
|
+
// Firefox on Ubuntu → displays as "Firefox (Ubuntu)"
|
|
193
223
|
await whatsapp.startSession("session3", {
|
|
194
|
-
|
|
195
|
-
|
|
224
|
+
printQR: true,
|
|
225
|
+
browserType: "ubuntu",
|
|
226
|
+
browserName: "Firefox",
|
|
196
227
|
});
|
|
197
228
|
|
|
229
|
+
// Edge on Windows → displays as "Edge (Windows)"
|
|
198
230
|
await whatsapp.startSession("session4", {
|
|
199
|
-
|
|
200
|
-
|
|
231
|
+
printQR: true,
|
|
232
|
+
browserType: "windows",
|
|
233
|
+
browserName: "Edge",
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
// Desktop app on macOS → displays as "Desktop (Mac OS)"
|
|
237
|
+
await whatsapp.startSession("session5", {
|
|
238
|
+
printQR: true,
|
|
239
|
+
browserType: "macOS",
|
|
240
|
+
browserName: "Desktop",
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
// Custom name (fallback to Chrome) → displays as "Chrome (My Bot App)"
|
|
244
|
+
await whatsapp.startSession("session6", {
|
|
245
|
+
printQR: true,
|
|
246
|
+
browserType: "windows",
|
|
247
|
+
browserName: "My Bot App",
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
// Custom name with Safari → displays as "Safari (My Bot App)"
|
|
251
|
+
await whatsapp.startSession("session7", {
|
|
252
|
+
printQR: true,
|
|
253
|
+
browserType: "macOS",
|
|
254
|
+
browserName: "My Bot App",
|
|
255
|
+
displayBrowser: "Safari", // Choose which browser type to display
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
// Custom name with Firefox → displays as "Firefox (Device Bot)"
|
|
259
|
+
await whatsapp.startSession("session8", {
|
|
260
|
+
printQR: true,
|
|
261
|
+
browserType: "ubuntu",
|
|
262
|
+
browserName: "Device Bot",
|
|
263
|
+
displayBrowser: "Firefox",
|
|
201
264
|
});
|
|
202
265
|
```
|
|
203
266
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
|
209
|
-
|
|
267
|
+
#### displayBrowser Parameter (v3.10.5+)
|
|
268
|
+
|
|
269
|
+
When using a custom `browserName`, you can now choose which browser type to display using the `displayBrowser` parameter:
|
|
270
|
+
|
|
271
|
+
| displayBrowser | Custom Name Example | Display Result |
|
|
272
|
+
|----------------|---------------------|----------------|
|
|
273
|
+
| `"Chrome"` (default) | "My Bot" | Chrome (My Bot) |
|
|
274
|
+
| `"Safari"` | "My Bot" | Safari (My Bot) |
|
|
275
|
+
| `"Firefox"` | "My Bot" | Firefox (My Bot) |
|
|
276
|
+
| `"Edge"` | "My Bot" | Edge (My Bot) |
|
|
277
|
+
| `"Opera"` | "My Bot" | Opera (My Bot) |
|
|
278
|
+
| `"Desktop"` | "My Bot" | Desktop (My Bot) |
|
|
279
|
+
|
|
280
|
+
> **Note**: `displayBrowser` is only used when `browserName` is a custom name (not a valid browser type like Chrome, Safari, etc.).
|
|
281
|
+
|
|
282
|
+
> [!WARNING]
|
|
283
|
+
> **Custom browserName and displayBrowser are NOT supported for Pairing Code sessions!**
|
|
284
|
+
>
|
|
285
|
+
> WhatsApp server validates browser configuration strictly during pairing code authentication. You MUST use valid browser configurations for pairing code:
|
|
286
|
+
>
|
|
287
|
+
> | browserType | browserName | Display | Pairing Code |
|
|
288
|
+
> |-------------|-------------|---------|--------------|
|
|
289
|
+
> | `"windows"` | `"Chrome"` | Chrome (Windows) | ✅ Works |
|
|
290
|
+
> | `"macOS"` | `"Safari"` | Safari (Mac OS) | ✅ Works |
|
|
291
|
+
> | `"windows"` | `"Edge"` | Edge (Windows) | ✅ Works |
|
|
292
|
+
> | `"ubuntu"` | `"Firefox"` | Firefox (Ubuntu) | ✅ Works |
|
|
293
|
+
> | `"windows"` | `"My Bot"` | Chrome (My Bot) | ❌ Fails |
|
|
294
|
+
>
|
|
295
|
+
> Custom names (like "My Bot App") only work with **QR Code** authentication.
|
|
296
|
+
|
|
210
297
|
|
|
211
298
|
|
|
212
299
|
### Sending Messages
|
|
@@ -812,8 +899,7 @@ async function startPairingApp() {
|
|
|
812
899
|
const yourPhoneNumber = "6281234567890"; // Replace with your phone number
|
|
813
900
|
|
|
814
901
|
try {
|
|
815
|
-
await whatsapp.startSessionWithPairingCode(pairingSessionId, {
|
|
816
|
-
mobile: yourPhoneNumber,
|
|
902
|
+
await whatsapp.startSessionWithPairingCode(pairingSessionId, yourPhoneNumber, {
|
|
817
903
|
onConnected: () => {
|
|
818
904
|
console.log("Pairing session connected successfully!");
|
|
819
905
|
sessionStatus[pairingSessionId] = 'connected';
|