mirror of
https://github.com/agent0ai/agent-zero.git
synced 2026-07-09 17:08:29 +00:00
feat: add disconnect account option to switch WhatsApp accounts
This commit is contained in:
parent
c62695356e
commit
57c95e6f13
2 changed files with 62 additions and 0 deletions
26
plugins/_whatsapp_integration/api/disconnect.py
Normal file
26
plugins/_whatsapp_integration/api/disconnect.py
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
"""Disconnect WhatsApp account by stopping bridge and clearing session."""
|
||||
|
||||
import shutil
|
||||
|
||||
from helpers.api import ApiHandler, Request
|
||||
from helpers.errors import format_error
|
||||
from helpers import files
|
||||
|
||||
|
||||
class Disconnect(ApiHandler):
|
||||
|
||||
async def process(self, input: dict, request: Request) -> dict:
|
||||
try:
|
||||
from plugins._whatsapp_integration.helpers import bridge_manager
|
||||
|
||||
# Stop bridge first
|
||||
await bridge_manager.stop_bridge()
|
||||
|
||||
# Delete session files
|
||||
session_dir = files.get_abs_path("usr/whatsapp/sessions")
|
||||
if files.exists(session_dir):
|
||||
shutil.rmtree(session_dir, ignore_errors=True)
|
||||
|
||||
return {"success": True, "message": "Account disconnected"}
|
||||
except Exception as e:
|
||||
return {"success": False, "message": format_error(e)}
|
||||
|
|
@ -15,6 +15,9 @@
|
|||
qr_data_url: null,
|
||||
qr_poll_timer: null,
|
||||
|
||||
disconnecting: false,
|
||||
disconnect_message: '',
|
||||
|
||||
async init() {
|
||||
try {
|
||||
const { callJsonApi } = await import('/js/api.js');
|
||||
|
|
@ -79,6 +82,19 @@
|
|||
this.qr_message = String(e);
|
||||
this.qr_data_url = null;
|
||||
}
|
||||
},
|
||||
async disconnect_account() {
|
||||
if (!confirm('Disconnect this WhatsApp account? You will need to scan a new QR code to reconnect.')) return;
|
||||
this.disconnecting = true;
|
||||
this.disconnect_message = '';
|
||||
try {
|
||||
const { callJsonApi } = await import('/js/api.js');
|
||||
const res = await callJsonApi('/plugins/_whatsapp_integration/disconnect', {});
|
||||
this.disconnect_message = res.success ? 'Account disconnected' : (res.message || 'Failed');
|
||||
} catch (e) {
|
||||
this.disconnect_message = String(e);
|
||||
}
|
||||
this.disconnecting = false;
|
||||
}
|
||||
}">
|
||||
<template x-if="config">
|
||||
|
|
@ -191,6 +207,26 @@
|
|||
</div>
|
||||
</template>
|
||||
|
||||
<!-- Disconnect account (shown when enabled) -->
|
||||
<template x-if="config.enabled">
|
||||
<div class="field">
|
||||
<div class="field-label">
|
||||
<div class="field-title">WhatsApp Account</div>
|
||||
<div class="field-description">
|
||||
<span x-show="!disconnect_message">Disconnect to switch to a different WhatsApp account</span>
|
||||
<span x-show="disconnect_message" x-text="disconnect_message"
|
||||
:style="'color:' + (disconnect_message === 'Account disconnected' ? '#4caf50' : '#f44336')"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field-control">
|
||||
<button class="btn btn-field" @click="disconnect_account()" :disabled="disconnecting">
|
||||
<span x-show="!disconnecting">Disconnect</span>
|
||||
<span x-show="disconnecting">Disconnecting...</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div class="field">
|
||||
<div class="field-label">
|
||||
<div class="field-title">Bridge Port</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue