Skip to content

Commit 12ddf02

Browse files
committed
update v3.7.2
1 parent e888a34 commit 12ddf02

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

.DS_Store

0 Bytes
Binary file not shown.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "wa-multi-session",
3-
"version": "3.7.0",
3+
"version": "3.7.2",
44
"description": "Multi Session Whatsapp Library",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/Socket/index.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const callback: Map<string, Function> = new Map();
3030
const retryCount: Map<string, number> = new Map();
3131

3232
const P = require("pino")({
33-
level: "silent",
33+
level: "silent",
3434
});
3535

3636
export const startSession = async (
@@ -64,9 +64,11 @@ export const startSession = async (
6464
sessionId,
6565
qr: update.qr,
6666
});
67+
options.onQRUpdated?.(update.qr);
6768
}
6869
if (connection == "connecting") {
6970
callback.get(CALLBACK_KEY.ON_CONNECTING)?.(sessionId);
71+
options.onConnecting?.();
7072
}
7173
if (connection === "close") {
7274
const code = (lastDisconnect?.error as Boom)?.output?.statusCode;
@@ -77,19 +79,19 @@ export const startSession = async (
7779
}
7880
if (shouldRetry) {
7981
retryAttempt++;
80-
}
81-
if (shouldRetry) {
8282
retryCount.set(sessionId, retryAttempt);
8383
startSocket();
8484
} else {
8585
retryCount.delete(sessionId);
8686
deleteSession(sessionId);
8787
callback.get(CALLBACK_KEY.ON_DISCONNECTED)?.(sessionId);
88+
options.onDisconnected?.();
8889
}
8990
}
9091
if (connection == "open") {
9192
retryCount.delete(sessionId);
9293
callback.get(CALLBACK_KEY.ON_CONNECTED)?.(sessionId);
94+
options.onConnected?.();
9395
}
9496
}
9597
if (events["creds.update"]) {
@@ -103,6 +105,7 @@ export const startSession = async (
103105
...msg,
104106
};
105107
callback.get(CALLBACK_KEY.ON_MESSAGE_UPDATED)?.(sessionId, data);
108+
options.onMessageUpdated?.(data);
106109
}
107110
if (events["messages.upsert"]) {
108111
const msg = events["messages.upsert"]
@@ -114,6 +117,7 @@ export const startSession = async (
114117
callback.get(CALLBACK_KEY.ON_MESSAGE_RECEIVED)?.({
115118
...msg,
116119
});
120+
options.onMessageReceived?.(msg);
117121
}
118122
});
119123
return sock;
@@ -125,6 +129,10 @@ export const startSession = async (
125129
return startSocket();
126130
};
127131

132+
/**
133+
*
134+
* @deprecated Use startSession method instead
135+
*/
128136
export const startSessionWithPairingCode = async (
129137
sessionId: string,
130138
options: StartSessionWithPairingCodeParams

src/Types/index.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,17 @@ export interface StartSessionParams {
4646
/**
4747
* Print QR Code into Terminal
4848
*/
49-
printQR: boolean;
49+
printQR?: boolean;
50+
51+
// session events
52+
onQRUpdated?: (qr: string) => void;
53+
onConnected?: () => void;
54+
onConnecting?: () => void;
55+
onDisconnected?: () => void;
56+
57+
// message events
58+
onMessageReceived?: (message: MessageReceived) => void;
59+
onMessageUpdated?: (message: MessageUpdated) => void;
5060
}
5161

5262
export interface StartSessionWithPairingCodeParams {

0 commit comments

Comments
 (0)