Whatsapp unlink WIP #1
This commit is contained in:
parent
12b72a727c
commit
48165db6a2
9 changed files with 120 additions and 3 deletions
|
|
@ -286,8 +286,30 @@ export default class WhatsappService extends Service {
|
|||
}
|
||||
|
||||
async unverify(botID: string): Promise<void> {
|
||||
// Step 1: Close and remove the active connection if it exists
|
||||
const connection = this.connections[botID];
|
||||
if (connection?.socket) {
|
||||
try {
|
||||
// Properly close the WebSocket connection
|
||||
await connection.socket.logout();
|
||||
} catch (error) {
|
||||
logger.warn({ botID, error }, "Error during logout, forcing disconnect");
|
||||
try {
|
||||
connection.socket.end(undefined);
|
||||
} catch (endError) {
|
||||
logger.warn({ botID, endError }, "Error ending socket connection");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Step 2: Remove from in-memory connections
|
||||
delete this.connections[botID];
|
||||
|
||||
// Step 3: Remove the bot directory (auth state, QR code, verified marker)
|
||||
const botDirectory = this.getBotDirectory(botID);
|
||||
fs.rmSync(botDirectory, { recursive: true, force: true });
|
||||
if (fs.existsSync(botDirectory)) {
|
||||
fs.rmSync(botDirectory, { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
|
||||
async register(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue