@@ -30,7 +30,7 @@ const callback: Map<string, Function> = new Map();
30
30
const retryCount : Map < string , number > = new Map ( ) ;
31
31
32
32
const P = require ( "pino" ) ( {
33
- level : "silent" ,
33
+ level : "silent" ,
34
34
} ) ;
35
35
36
36
export const startSession = async (
@@ -64,9 +64,11 @@ export const startSession = async (
64
64
sessionId,
65
65
qr : update . qr ,
66
66
} ) ;
67
+ options . onQRUpdated ?.( update . qr ) ;
67
68
}
68
69
if ( connection == "connecting" ) {
69
70
callback . get ( CALLBACK_KEY . ON_CONNECTING ) ?.( sessionId ) ;
71
+ options . onConnecting ?.( ) ;
70
72
}
71
73
if ( connection === "close" ) {
72
74
const code = ( lastDisconnect ?. error as Boom ) ?. output ?. statusCode ;
@@ -77,19 +79,19 @@ export const startSession = async (
77
79
}
78
80
if ( shouldRetry ) {
79
81
retryAttempt ++ ;
80
- }
81
- if ( shouldRetry ) {
82
82
retryCount . set ( sessionId , retryAttempt ) ;
83
83
startSocket ( ) ;
84
84
} else {
85
85
retryCount . delete ( sessionId ) ;
86
86
deleteSession ( sessionId ) ;
87
87
callback . get ( CALLBACK_KEY . ON_DISCONNECTED ) ?.( sessionId ) ;
88
+ options . onDisconnected ?.( ) ;
88
89
}
89
90
}
90
91
if ( connection == "open" ) {
91
92
retryCount . delete ( sessionId ) ;
92
93
callback . get ( CALLBACK_KEY . ON_CONNECTED ) ?.( sessionId ) ;
94
+ options . onConnected ?.( ) ;
93
95
}
94
96
}
95
97
if ( events [ "creds.update" ] ) {
@@ -103,6 +105,7 @@ export const startSession = async (
103
105
...msg ,
104
106
} ;
105
107
callback . get ( CALLBACK_KEY . ON_MESSAGE_UPDATED ) ?.( sessionId , data ) ;
108
+ options . onMessageUpdated ?.( data ) ;
106
109
}
107
110
if ( events [ "messages.upsert" ] ) {
108
111
const msg = events [ "messages.upsert" ]
@@ -114,6 +117,7 @@ export const startSession = async (
114
117
callback . get ( CALLBACK_KEY . ON_MESSAGE_RECEIVED ) ?.( {
115
118
...msg ,
116
119
} ) ;
120
+ options . onMessageReceived ?.( msg ) ;
117
121
}
118
122
} ) ;
119
123
return sock ;
@@ -125,6 +129,10 @@ export const startSession = async (
125
129
return startSocket ( ) ;
126
130
} ;
127
131
132
+ /**
133
+ *
134
+ * @deprecated Use startSession method instead
135
+ */
128
136
export const startSessionWithPairingCode = async (
129
137
sessionId : string ,
130
138
options : StartSessionWithPairingCodeParams
0 commit comments