|
|
|
@ -49,8 +49,6 @@ const createWhatsApp = async phone => {
|
|
|
|
const waVersion = version.join('.') + ', ' + (isLatest ? 'latest' : 'out');
|
|
|
|
const waVersion = version.join('.') + ', ' + (isLatest ? 'latest' : 'out');
|
|
|
|
|
|
|
|
|
|
|
|
const stop = () => {
|
|
|
|
const stop = () => {
|
|
|
|
waSocket.logout(() => '实例已停止');
|
|
|
|
|
|
|
|
waEmitter.off('request.' + whatsAppNo + '.send.message', sendMessageHandler);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fs.rm(authStateFolder, { recursive: true, force: true }, (err) => {
|
|
|
|
fs.rm(authStateFolder, { recursive: true, force: true }, (err) => {
|
|
|
|
if (err) {
|
|
|
|
if (err) {
|
|
|
|
@ -67,6 +65,8 @@ const createWhatsApp = async phone => {
|
|
|
|
console.log('Successfully deleted storeFilename file: ', storeFilename);
|
|
|
|
console.log('Successfully deleted storeFilename file: ', storeFilename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
waEmitter.emit('request.' + whatsAppNo + '.stop', {});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const start = () => {
|
|
|
|
const start = () => {
|
|
|
|
@ -310,12 +310,21 @@ const createWhatsApp = async phone => {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const stopHandler = () => {
|
|
|
|
|
|
|
|
waSocket.ev.off('messages.upsert', handleMessagesUpsert);
|
|
|
|
|
|
|
|
waSocket.ev.off('messages.update', handleMessagesUpdate);
|
|
|
|
|
|
|
|
waSocket.ev.off('creds.update', handleCredsUpdate);
|
|
|
|
|
|
|
|
waSocket.logout(() => '实例已停止');
|
|
|
|
|
|
|
|
waEmitter.off('request.' + whatsAppNo + '.send.message', sendMessageHandler);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
waSocket.ev.on('connection.update', async update => {
|
|
|
|
waSocket.ev.on('connection.update', async update => {
|
|
|
|
|
|
|
|
|
|
|
|
const { connection, lastDisconnect, qr } = update;
|
|
|
|
const { connection, lastDisconnect, qr } = update;
|
|
|
|
|
|
|
|
|
|
|
|
if (connection === 'close') {
|
|
|
|
if (connection === 'close') {
|
|
|
|
waEmitter.off('request.' + whatsAppNo + '.send.message', sendMessageHandler);
|
|
|
|
waEmitter.off('request.' + whatsAppNo + '.send.message', sendMessageHandler);
|
|
|
|
|
|
|
|
waEmitter.off('request.' + whatsAppNo + '.stop', stopHandler);
|
|
|
|
if((lastDisconnect?.error)?.output?.statusCode !== DisconnectReason.loggedOut) {
|
|
|
|
if((lastDisconnect?.error)?.output?.statusCode !== DisconnectReason.loggedOut) {
|
|
|
|
start();
|
|
|
|
start();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
@ -339,6 +348,7 @@ const createWhatsApp = async phone => {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
waEmitter.on('request.' + whatsAppNo + '.send.message', sendMessageHandler);
|
|
|
|
waEmitter.on('request.' + whatsAppNo + '.send.message', sendMessageHandler);
|
|
|
|
|
|
|
|
waEmitter.on('request.' + whatsAppNo + '.stop', stopHandler);
|
|
|
|
} else if (qr !== undefined) {
|
|
|
|
} else if (qr !== undefined) {
|
|
|
|
// WebSocket 创建成功等待扫码,如果没有扫码会更新 qr
|
|
|
|
// WebSocket 创建成功等待扫码,如果没有扫码会更新 qr
|
|
|
|
// 第一次一分钟,后面是 20 秒更新一次
|
|
|
|
// 第一次一分钟,后面是 20 秒更新一次
|
|
|
|
|