Implement email alert system with WhatsApp notifications

- Added alerts processing logic in src/alerts.py to analyze threads and send WhatsApp alerts based on configured time frames.
- Created FastAPI application in src/app.py to manage threads, display configurations, and trigger alert processing.
- Developed database models and utility functions in src/database.py for managing threads and messages.
- Integrated Twilio API for sending WhatsApp messages in src/whatsapp_sender.py.
- Implemented Zoho email client in src/zoho_client.py to fetch emails and check for replies.
- Added configuration management for email settings and alert parameters.
- Established auto-processing loop for periodic email syncing and alert generation.
This commit is contained in:
bolade
2025-08-11 17:34:35 +01:00
parent ca7df9d598
commit d553d6f31e
13 changed files with 879 additions and 150 deletions
+3
View File
@@ -13,6 +13,9 @@
<nav>
<a href="/">Threads</a>
<a href="/config">Config</a>
<form action="/sync_emails" method="post" style="display:inline-block; margin-left:12px;">
<button type="submit">Process Emails</button>
</form>
</nav>
</div>
</header>
+9
View File
@@ -47,6 +47,15 @@
</div>
</div>
<h3 class="mt-2">WhatsApp</h3>
<div class="row">
<div class="col">
<label>Send To (WhatsApp E.164, no spaces)<br>
<input type="text" name="whatsapp_to" placeholder="+15551234567" value="{{ cfg.whatsapp_to or '' }}" />
</label>
</div>
</div>
<h3 class="mt-2">Processing</h3>
<div class="row">
<div class="col">
+3 -1
View File
@@ -23,8 +23,10 @@
<strong>Actionable:</strong>
{% if ai.actionable %}<span class="badge warn">Yes</span>{% else %}<span class="badge success">No</span>{% endif %}
</p>
<p><strong>Summary:</strong> {{ ai.summary }}</p>
<p><strong>Summary:</strong> {{ ai.summary or thread.ai_summary }}</p>
<p class="muted">Confidence: {{ ai.confidence }} • Model: {{ ai.model }}</p>
<p class="muted">Last stored: {{ thread.last_analyzed_at }}</p>
<p class="muted">Last alert level sent: {{ thread.last_alert_level_sent }} at {{ thread.last_alert_sent_at }}</p>
</div>
</div>
</div>
+25
View File
@@ -4,6 +4,29 @@
<div class="col">
<h2>Threads{% if account %} for {{ account }}{% endif %}</h2>
<p class="muted">Latest updated threads. Click an ID to view details and AI analysis.</p>
{% if status %}
<div class="muted" style="margin-top:6px;">
{% if status.sync_in_progress %}
<span class="badge brand">Syncing…</span>
{% else %}
{% if status.last_sync_status == 'ok' %}
<span class="badge success">Last sync OK</span>
{% elif status.last_sync_status == 'error' %}
<span class="badge warn">Last sync error</span>
{% else %}
<span class="badge">Idle</span>
{% endif %}
{% endif %}
<span style="margin-left:8px;">Last Sync: {{ status.last_sync_at or 'never' }}</span>
<span style="margin-left:8px;">Items: {{ status.last_sync_count }}</span>
{% if status.last_sync_error %}
<div class="muted">Error: {{ status.last_sync_error }}</div>
{% endif %}
{% if status.auto_process %}
<div class="muted">Auto process enabled (every {{ status.interval }}m)</div>
{% endif %}
</div>
{% endif %}
</div>
</div>
@@ -13,6 +36,7 @@
<tr>
<th>ID</th>
<th>Subject</th>
<th>AI Summary</th>
<th>Account</th>
<th>Msgs</th>
<th>Requires Reply</th>
@@ -24,6 +48,7 @@
<tr>
<td><a href="/thread/{{ t.id }}">{{ t.id }}</a></td>
<td>{{ t.subject }}</td>
<td class="muted">{{ t.ai_summary or '' }}</td>
<td><span class="badge">{{ t.account_email }}</span></td>
<td><span class="badge brand">{{ t.messages|length }}</span></td>
<td>