mirror of
https://github.com/agent0ai/agent-zero.git
synced 2026-12-04 09:28:56 +00:00
Accepted WhatsApp senders could persistently relax their own tool policy and toggle instance-wide plugins using ordinary chat authorization. Add a separate admin_numbers allowlist, empty by default, and derive administrative access from the normalized sender of each inbound message. Keep allowed-number and group checks in force. Require administration at the WhatsApp plugin-toggle and tool-policy mutation boundaries while preserving read-only menus and ordinary chat controls. Gate built-in profile creation and browser-runtime changes before shared command execution. Use the shared argument parser for profile creation checks and preserve existing profile selection and custom overrides. Expose the administrator list in settings and document the new defaults. Add regressions for denied writes, real policy persistence and runtime decisions, normalized sender identities, revocation, administrative commands, and independent frontend access-list editing. Validation: - Conda framework: 165 tests and 62 subtests passed. - Docker framework: 12 focused tests and 32 subtests passed. - Node bridge and configuration store: all 4 tests passed. - WebUI: administrator field renders, parses and clears independently. - JavaScript syntax and git diff checks passed. - Restarted the bound Docker instance and verified HTTP 200. Live WhatsApp delivery was not exercised. Synthetic events and disposable policy files cover the authorization paths without changing live access lists or sending test messages to WhatsApp users.
571 lines
25 KiB
HTML
571 lines
25 KiB
HTML
<html>
|
|
|
|
<head>
|
|
<title>WhatsApp Integration</title>
|
|
<script type="module">
|
|
import { store } from "/plugins/_whatsapp_integration/webui/whatsapp-config-store.js";
|
|
</script>
|
|
</head>
|
|
|
|
<body>
|
|
<div x-data x-init="$store.whatsappConfig.init(config, context)" x-destroy="$store.whatsappConfig.cleanup()">
|
|
<template x-if="config">
|
|
<div class="wa-page">
|
|
<div class="section-title">WhatsApp</div>
|
|
|
|
<template x-if="config.enabled && $store.whatsappConfig.hasMeaningfulConfig()">
|
|
<div class="wa-summary-card">
|
|
<div class="wa-summary-copy">
|
|
<div class="wa-summary-title">Current setup</div>
|
|
<div class="wa-summary-subtitle"
|
|
x-text="$store.whatsappConfig.modeSummary() + ' · ' + $store.whatsappConfig.projectSummary()">
|
|
</div>
|
|
</div>
|
|
<span class="wa-status-pill" :class="'tone-' + $store.whatsappConfig.statusTone()"
|
|
x-text="$store.whatsappConfig.statusLabel()"></span>
|
|
</div>
|
|
</template>
|
|
|
|
<div class="wa-wizard-card">
|
|
<div class="wa-step-header">
|
|
<div class="wa-step-copy">
|
|
<div class="wa-step-title" x-text="$store.whatsappConfig.currentStepMeta().title"></div>
|
|
<div class="wa-step-description"
|
|
x-text="$store.whatsappConfig.currentStepMeta().description"></div>
|
|
</div>
|
|
<div class="wa-step-dots" aria-hidden="true">
|
|
<template x-for="(step, idx) in $store.whatsappConfig.steps" :key="step.title">
|
|
<button type="button" class="wa-step-dot"
|
|
:class="{ 'is-active': $store.whatsappConfig.currentStep === idx }"
|
|
@click="$store.whatsappConfig.setStep(idx)"></button>
|
|
</template>
|
|
</div>
|
|
</div>
|
|
|
|
<template x-if="$store.whatsappConfig.currentStep === 0">
|
|
<div class="wa-step-panel">
|
|
|
|
<div class="wa-pairing-row">
|
|
<div class="wa-qr-panel">
|
|
<div class="wa-qr-status">Scan to link WhatsApp</div>
|
|
<div class="wa-qr-content">
|
|
<button type="button" class="btn btn-field"
|
|
x-show="!$store.whatsappConfig.qrVisible"
|
|
@click="$store.whatsappConfig.showQr()">Show QR code</button>
|
|
<template x-if="$store.whatsappConfig.qrVisible">
|
|
<div>
|
|
<template x-if="$store.whatsappConfig.qrStatus === 'waiting_scan' && $store.whatsappConfig.qrDataUrl">
|
|
<img :src="$store.whatsappConfig.qrDataUrl" alt="WhatsApp pairing QR code"
|
|
class="wa-qr-image" />
|
|
</template>
|
|
<div role="status" class="wa-qr-message"
|
|
x-show="$store.whatsappConfig.qrStatus !== 'waiting_scan'"
|
|
x-text="$store.whatsappConfig.qrMessage"></div>
|
|
<button type="button" class="btn btn-field"
|
|
x-show="$store.whatsappConfig.qrStatus === 'error'"
|
|
@click="$store.whatsappConfig.showQr()">Try again</button>
|
|
</div>
|
|
</template>
|
|
</div>
|
|
<button type="button" class="btn btn-field" x-show="$store.whatsappConfig.qrVisible"
|
|
@click="$store.whatsappConfig.hideQr()"
|
|
x-text="$store.whatsappConfig.qrStatus === 'connected' ? 'Close' : 'Hide QR code'"></button>
|
|
</div>
|
|
<div class="wa-pairing-instructions">
|
|
<div class="wa-qr-status">Link your account</div>
|
|
<ol class="wa-pairing-steps">
|
|
<li>Click <strong>Show QR code</strong>.</li>
|
|
<li>Open WhatsApp on your phone and go to <strong>Settings → Linked devices</strong> (Android: <strong>⋮ → Linked devices</strong>).</li>
|
|
<li>Tap <strong>Link a device</strong> and scan the code.</li>
|
|
</ol>
|
|
<p class="wa-qr-help">The QR code refreshes automatically while it is open.</p>
|
|
<p class="wa-qr-help">Choose who can reach your agent below, then finish setup to save.</p>
|
|
<button type="button" class="btn btn-field" x-show="config.enabled"
|
|
@click="$store.whatsappConfig.disconnectAccount()"
|
|
:disabled="$store.whatsappConfig.disconnecting"
|
|
x-text="$store.whatsappConfig.disconnecting ? 'Disconnecting...' : 'Disconnect account'"></button>
|
|
<div role="status" class="wa-qr-help" x-show="$store.whatsappConfig.disconnectMessage"
|
|
x-text="$store.whatsappConfig.disconnectMessage"></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="field">
|
|
<div class="field-label">
|
|
<div class="field-title">Mode</div>
|
|
<div class="field-description">
|
|
<span x-show="config.mode === 'self-chat'">
|
|
Use your own number. You can message yourself to talk to the agent.
|
|
</span>
|
|
<span x-show="config.mode !== 'self-chat'">
|
|
Use a separate number dedicated to Agent Zero conversations.
|
|
</span>
|
|
</div>
|
|
</div>
|
|
<div class="field-control">
|
|
<select x-model="config.mode">
|
|
<option value="self-chat">Personal number (self-chat)</option>
|
|
<option value="dedicated">Separate number (dedicated)</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="wa-mode-note">
|
|
<strong>Good to know:</strong> Self-chat uses your own number. Dedicated is better for
|
|
shared or public access. You can pair now or come back to it later.
|
|
</div>
|
|
|
|
<div class="wa-warning" x-show="$store.whatsappConfig.accessWarning()">
|
|
<div class="wa-warning-title">
|
|
<span aria-hidden="true">⚠</span>
|
|
<span>Warning</span>
|
|
</div>
|
|
<div class="wa-warning-body" x-text="$store.whatsappConfig.accessWarning()"></div>
|
|
</div>
|
|
|
|
<div class="field">
|
|
<div class="field-label">
|
|
<div class="field-title">Allowed numbers</div>
|
|
<div class="field-description">Comma-separated phone numbers. Punctuation and +
|
|
prefixes are okay. Leave empty only if you want open access.</div>
|
|
</div>
|
|
<div class="field-control">
|
|
<input type="text" :value="$store.whatsappConfig.allowedText()"
|
|
@input="$store.whatsappConfig.setAllowed($event.target.value)"
|
|
placeholder="+1 (415) 555-1234, +44 7911 123456" />
|
|
</div>
|
|
</div>
|
|
|
|
<div class="field">
|
|
<div class="field-label">
|
|
<div class="field-title">Administrator numbers</div>
|
|
<div class="field-description">Allowed senders who may change plugins and tool
|
|
permissions, create profiles, or switch the browser runtime. Leave empty to
|
|
grant nobody administrative access.</div>
|
|
</div>
|
|
<div class="field-control">
|
|
<input type="text" aria-label="Administrator numbers" :value="$store.whatsappConfig.adminText()"
|
|
@input="$store.whatsappConfig.setAdmins($event.target.value)"
|
|
placeholder="+1 (415) 555-1234" />
|
|
</div>
|
|
</div>
|
|
|
|
<div class="field">
|
|
<div class="field-label">
|
|
<div class="field-title">Allow groups</div>
|
|
<div class="field-description">Reply in group chats when mentioned or replied to.
|
|
</div>
|
|
</div>
|
|
<div class="field-control">
|
|
<label class="toggle">
|
|
<input type="checkbox" x-model="config.allow_group" />
|
|
<span class="toggler"></span>
|
|
</label>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<template x-if="$store.whatsappConfig.currentStep === 1">
|
|
<div class="wa-step-panel">
|
|
<div class="field">
|
|
<div class="field-label">
|
|
<div class="field-title">Enable WhatsApp</div>
|
|
<div class="field-description">Receive messages from your linked account after saving.</div>
|
|
</div>
|
|
<div class="field-control">
|
|
<label class="toggle">
|
|
<input type="checkbox"
|
|
aria-label="Enable WhatsApp"
|
|
x-model="config.enabled"
|
|
@change="$store.whatsappConfig.onEnabledChange()" />
|
|
<span class="toggler"></span>
|
|
</label>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="field">
|
|
<div class="field-label">
|
|
<div class="field-title">Project</div>
|
|
<div class="field-description">Optional project to activate for WhatsApp
|
|
conversations.</div>
|
|
</div>
|
|
<div class="field-control">
|
|
<select :value="config.project" @change="config.project = $event.target.value">
|
|
<option value="">No project</option>
|
|
<template x-for="proj in $store.whatsappConfig.projects" :key="$store.whatsappConfig.projectOptionValue(proj)">
|
|
<option :value="$store.whatsappConfig.projectOptionValue(proj)"
|
|
x-text="$store.whatsappConfig.projectOptionLabel(proj)"
|
|
:selected="config.project === $store.whatsappConfig.projectOptionValue(proj)">
|
|
</option>
|
|
</template>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="field">
|
|
<div class="field-label">
|
|
<div class="field-title">Agent instructions</div>
|
|
<div class="field-description">Extra guidance for how the agent should reply in
|
|
WhatsApp chats.</div>
|
|
</div>
|
|
<div class="field-control">
|
|
<textarea x-model="config.agent_instructions" rows="3"
|
|
placeholder="Reply briefly and naturally, like a mobile conversation."></textarea>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<div class="wa-test-panel">
|
|
<div class="wa-test-copy">
|
|
<div class="wa-test-title">Check the connection</div>
|
|
<div class="wa-test-description">We will check whether the local WhatsApp bridge is up and
|
|
connected.</div>
|
|
</div>
|
|
<button class="btn btn-field" @click="$store.whatsappConfig.testConnection()"
|
|
:disabled="$store.whatsappConfig.testing">
|
|
<span x-text="$store.whatsappConfig.testButtonLabel()"></span>
|
|
</button>
|
|
</div>
|
|
|
|
<template x-if="$store.whatsappConfig.testResults">
|
|
<div class="wa-results" :class="{ 'is-error': !$store.whatsappConfig.testResults.success }">
|
|
<template x-for="result in $store.whatsappConfig.testResults.results"
|
|
:key="result.test + result.message">
|
|
<div class="wa-result-row">
|
|
<span class="wa-result-icon" x-text="result.ok ? '✓' : '✗'"></span>
|
|
<div class="wa-result-copy">
|
|
<div class="wa-result-title" x-text="result.test"></div>
|
|
<div class="wa-result-message" x-text="result.message"></div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</div>
|
|
</template>
|
|
|
|
<template x-if="$store.whatsappConfig.currentStep > 0">
|
|
<div class="settings-advanced-section" x-data="{ advOpen: false }">
|
|
<button type="button" class="settings-advanced-toggle"
|
|
:aria-expanded="advOpen" @click="advOpen = !advOpen">
|
|
<x-icon class="settings-advanced-toggle-icon"
|
|
:style="advOpen ? 'transform:rotate(90deg)' : ''" name="chevron_right"></x-icon>
|
|
<span>Advanced</span>
|
|
</button>
|
|
<div class="settings-advanced-body" x-show="advOpen" x-transition.opacity style="display: none;">
|
|
<div class="field-description">
|
|
These settings are here when you need them, but the defaults are fine for most
|
|
setups.
|
|
</div>
|
|
|
|
<div class="field">
|
|
<div class="field-label">
|
|
<div class="field-title">Bridge port</div>
|
|
<div class="field-description">Local port for the WhatsApp bridge HTTP server.
|
|
</div>
|
|
</div>
|
|
<div class="field-control">
|
|
<input type="number" x-model.number="config.bridge_port" placeholder="3100" />
|
|
</div>
|
|
</div>
|
|
|
|
<div class="field">
|
|
<div class="field-label">
|
|
<div class="field-title">Poll interval (seconds)</div>
|
|
<div class="field-description">How often to check for new messages. The minimum
|
|
is 2 seconds.</div>
|
|
</div>
|
|
<div class="field-control">
|
|
<input type="number" x-model.number="config.poll_interval_seconds" min="2"
|
|
placeholder="3" />
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</div>
|
|
|
|
<style>
|
|
.wa-page {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 0.9rem;
|
|
}
|
|
|
|
.wa-summary-card,
|
|
.wa-wizard-card {
|
|
border-radius: 0.5rem;
|
|
}
|
|
|
|
.wa-summary-title,
|
|
.wa-step-title,
|
|
.wa-test-title {
|
|
font-weight: 700;
|
|
}
|
|
|
|
.wa-summary-subtitle,
|
|
.wa-step-description,
|
|
.wa-note,
|
|
.wa-mode-note,
|
|
.wa-test-description,
|
|
.wa-result-message {
|
|
color: var(--color-text-secondary);
|
|
line-height: 1.5;
|
|
}
|
|
|
|
.wa-summary-card {
|
|
padding: 1rem;
|
|
border: 1px solid var(--color-border);
|
|
display: flex;
|
|
justify-content: space-between;
|
|
gap: 1rem;
|
|
align-items: center;
|
|
}
|
|
|
|
.wa-step-header {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
gap: 1rem;
|
|
align-items: flex-start;
|
|
margin-bottom: 1rem;
|
|
}
|
|
|
|
.wa-step-dots {
|
|
display: flex;
|
|
gap: 0.5rem;
|
|
flex-wrap: wrap;
|
|
justify-content: flex-end;
|
|
align-items: center;
|
|
}
|
|
|
|
.wa-step-dot {
|
|
width: 0.85rem;
|
|
height: 0.85rem;
|
|
border-radius: 999px;
|
|
border: 1px solid var(--color-border);
|
|
background: transparent;
|
|
cursor: pointer;
|
|
padding: 0;
|
|
}
|
|
|
|
.wa-step-dot.is-active {
|
|
background: rgba(59, 130, 246, 0.9);
|
|
border-color: rgba(59, 130, 246, 0.9);
|
|
}
|
|
|
|
.wa-step-panel {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 0.2rem;
|
|
}
|
|
|
|
.wa-note {
|
|
margin-bottom: 0.9rem;
|
|
padding: 0.8rem 0.9rem;
|
|
border-radius: 12px;
|
|
font-size: var(--font-size-small);
|
|
}
|
|
|
|
.wa-note {
|
|
background: color-mix(in srgb, var(--color-background) 88%, white 12%);
|
|
}
|
|
|
|
.wa-warning {
|
|
margin: 0.5rem 0 1.25rem;
|
|
padding: 0.75rem 0.9rem;
|
|
border-radius: 10px;
|
|
border: 1px solid rgba(255, 170, 0, 0.45);
|
|
background: rgba(255, 170, 0, 0.12);
|
|
color: var(--color-warning-text);
|
|
font-size: var(--font-size-small);
|
|
}
|
|
|
|
.wa-warning-title {
|
|
font-weight: 600;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.5rem;
|
|
}
|
|
|
|
.wa-warning-body {
|
|
margin-top: 0.25rem;
|
|
line-height: 1.45;
|
|
}
|
|
|
|
.wa-mode-note {
|
|
margin-top: -0.2rem;
|
|
margin-bottom: 0.9rem;
|
|
font-size: var(--font-size-small);
|
|
}
|
|
|
|
.wa-pairing-row {
|
|
display: grid;
|
|
grid-template-columns: minmax(16rem, 18rem) minmax(0, 1fr);
|
|
gap: 1rem;
|
|
align-items: stretch;
|
|
margin-bottom: 1rem;
|
|
}
|
|
|
|
.wa-qr-panel,
|
|
.wa-pairing-instructions {
|
|
padding: 1rem;
|
|
border-radius: 0.5rem;
|
|
background: color-mix(in srgb, var(--color-background) 90%, white 10%);
|
|
}
|
|
|
|
.wa-qr-panel {
|
|
text-align: center;
|
|
}
|
|
|
|
.wa-qr-content {
|
|
min-height: 150px;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
margin-bottom: 0.8rem;
|
|
overflow-wrap: anywhere;
|
|
}
|
|
|
|
.wa-qr-status {
|
|
font-weight: 700;
|
|
margin-bottom: 0.5rem;
|
|
}
|
|
|
|
.wa-pairing-steps {
|
|
margin: 0;
|
|
padding-left: 1.15rem;
|
|
color: var(--color-text-secondary);
|
|
line-height: 1.55;
|
|
}
|
|
|
|
.wa-qr-message,
|
|
.wa-qr-help {
|
|
color: var(--color-text-secondary);
|
|
line-height: 1.5;
|
|
}
|
|
|
|
.wa-qr-help {
|
|
font-size: var(--font-size-small);
|
|
margin-top: 0.8rem;
|
|
}
|
|
|
|
.wa-qr-image {
|
|
display: block;
|
|
width: 256px;
|
|
height: auto;
|
|
max-width: 100%;
|
|
border-radius: 0.5rem;
|
|
background: white;
|
|
}
|
|
|
|
.wa-test-panel {
|
|
margin-top: 1rem;
|
|
padding: var(--spacing-xs) 0;
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
gap: 1rem;
|
|
}
|
|
|
|
.wa-test-copy,
|
|
.wa-result-copy {
|
|
min-width: 0;
|
|
}
|
|
|
|
.wa-results {
|
|
margin-top: 0.9rem;
|
|
border-radius: 14px;
|
|
border: 1px solid color-mix(in srgb, #22c55e 28%, var(--color-border) 72%);
|
|
background: color-mix(in srgb, #22c55e 8%, var(--color-background) 92%);
|
|
padding: 0.35rem 0.9rem;
|
|
}
|
|
|
|
.wa-results.is-error {
|
|
border-color: color-mix(in srgb, #ef4444 28%, var(--color-border) 72%);
|
|
background: color-mix(in srgb, #ef4444 8%, var(--color-background) 92%);
|
|
}
|
|
|
|
.wa-result-row {
|
|
display: flex;
|
|
align-items: flex-start;
|
|
gap: 0.8rem;
|
|
padding: 0.7rem 0;
|
|
}
|
|
|
|
.wa-result-row+.wa-result-row {
|
|
border-top: 1px solid color-mix(in srgb, var(--color-border) 85%, white 15%);
|
|
}
|
|
|
|
.wa-result-icon {
|
|
width: 1.25rem;
|
|
font-weight: 800;
|
|
line-height: 1.3;
|
|
}
|
|
|
|
.wa-result-title {
|
|
font-weight: 700;
|
|
margin-bottom: 0.18rem;
|
|
}
|
|
|
|
.wa-status-pill {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
min-width: 5.25rem;
|
|
padding: 0.35rem 0.7rem;
|
|
border-radius: 999px;
|
|
font-size: 0.8rem;
|
|
font-weight: 700;
|
|
}
|
|
|
|
.wa-status-pill.tone-success {
|
|
background: rgba(34, 197, 94, 0.14);
|
|
color: #7ee7a4;
|
|
}
|
|
|
|
.wa-status-pill.tone-ready {
|
|
background: rgba(59, 130, 246, 0.16);
|
|
color: #93c5fd;
|
|
}
|
|
|
|
.wa-status-pill.tone-warning {
|
|
background: rgba(245, 158, 11, 0.16);
|
|
color: #fcd34d;
|
|
}
|
|
|
|
.wa-status-pill.tone-muted {
|
|
background: rgba(148, 163, 184, 0.14);
|
|
color: #cbd5e1;
|
|
}
|
|
|
|
@media (max-width: 640px) {
|
|
.wa-pairing-row {
|
|
grid-template-columns: minmax(0, 1fr);
|
|
}
|
|
|
|
|
|
.wa-summary-card,
|
|
.wa-step-header,
|
|
.wa-test-panel {
|
|
flex-direction: column;
|
|
align-items: stretch;
|
|
}
|
|
|
|
.wa-step-dots {
|
|
width: 100%;
|
|
justify-content: space-between;
|
|
}
|
|
|
|
.wa-status-pill {
|
|
min-width: 0;
|
|
align-self: flex-start;
|
|
}
|
|
}
|
|
</style>
|
|
</body>
|
|
|
|
</html>
|