Whatsapp unlink WIP #1

This commit is contained in:
Darren Clarke 2025-11-09 11:12:04 +01:00
parent 12b72a727c
commit 48165db6a2
9 changed files with 120 additions and 3 deletions

View file

@ -0,0 +1 @@
export { relinkBot as POST } from "@link-stack/bridge-ui";

View file

@ -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(

View file

@ -182,7 +182,7 @@ const sendSignalMessageTask = async ({
{
number,
recipients: [finalTo],
message: message.substring(0, 50) + "...",
messageLength: message?.length,
hasQuoteParams: !!(quoteMessage && quoteAuthor && quoteTimestamp),
},
"Message data being sent",
@ -197,7 +197,7 @@ const sendSignalMessageTask = async ({
logger.debug(
{
quoteAuthor,
quoteMessage: quoteMessage.substring(0, 50) + "...",
quoteMessageLength: quoteMessage?.length,
quoteTimestamp,
},
"Including quote in message",

View file

@ -0,0 +1 @@
export { relinkBot as POST } from "@link-stack/bridge-ui";