Repository navigation
Conversation
…stence - Add Agent.serve_whatsapp() and Server.serve_whatsapp() - Implement SQLiteSessionStore with WAL mode, session timeout, and message idempotency - Implement WhatsAppServer with HMAC-SHA256 signature verification and background task processing - Implement MetaWhatsAppClient with message chunking and read receipts - Implement MetaDiscoveryClient for automated Phone Number ID discovery and 3-tier webhook sync (adapted from WAVoice) - Add 17 unit and integration tests covering security, idempotency, session isolation, and auto-discovery
|
LMK if you need any help in testing the PR via Meta a/c. Happy to hop on a call as well. |
|
@amitbhakt Thanks for your PR and for your willingness! We're dealing with some deadlines involving https://github.com/idiap/dialfork and having an audio version for it (that's why we pushed and released some versions of sdialog today and in the past days involving the audio capability of the package). I'm gonna get back to you and your PR soon, just sending this comment to let you know :) And sure, we can schedule a quick call if needed, no problem with that :D |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #135 +/- ##
==========================================
+ Coverage 44.85% 46.04% +1.19%
==========================================
Files 84 90 +6
Lines 10207 10683 +476
==========================================
+ Hits 4578 4919 +341
- Misses 5629 5764 +135
🚀 New features to boost your workflow:
|
Summary
Adds native Meta WhatsApp Cloud API serving capabilities to SDialog agents via
Agent.serve_whatsapp()andServer.serve_whatsapp(), as requested in #133.This implementation allows users to deploy and converse with SDialog agents directly over WhatsApp with production-grade reliability, multi-user session isolation, and zero-friction automated onboarding.
Closes #133
Key Features & Architecture
1. Developer Interface
Mirrors SDialog's existing
Agent.serve()idiom:Parameters fall back to standard environment variables (
WHATSAPP_PHONE_NUMBER_ID,WHATSAPP_ACCESS_TOKEN,WHATSAPP_APP_SECRET,WHATSAPP_VERIFY_TOKEN).2. Multi-User Session Isolation via SQLite
wa_id) has isolated state stored in a local SQLite database (whatsapp_sessions.db).PRAGMA journal_mode = WAL;) with a 5000ms busy timeout to prevent database locks under concurrent traffic.session_timeout, default 30 mins) or manual reset via slash commands (/reset,/clear,/restart).Agent.get_state()/Agent.set_state()API contract, with an internal message history bridge for immediate use.3. Webhook Architecture & Meta SLA Compliance
BackgroundTask+asyncio.to_thread._user_locks[wa_id]) so messages from the same user are processed in chronological order (handling "double-texting"), while different users run concurrently.4. Security & Edge Case Handling
X-Hub-Signature-256using constant-time comparison (hmac.compare_digest) on raw payload bytes; rejects spoofed requests with HTTP 401.wamid(WhatsApp Message ID) in aprocessed_messagestable to safely suppress duplicate webhook retries from Meta without re-invoking the LLM.sent,delivered,read) safely without crashing.5. Automated Onboarding (Adapted from WAVoice)
debug_token) to discoverapp_idandwaba_id.phone_number_idso users don't need to look up internal Meta IDs manually.tunnel=True.Provenance & Attribution
The auto-discovery and 3-tier webhook synchronization logic is adapted from WAVoice (Bhakt, 2026, DOI: 10.5281/zenodo.23537489), released under the MIT License, with full SPDX attribution headers included in
src/sdialog/whatsapp/discovery.py.Verification & Testing
tests/test_whatsapp.pywith 17 tests covering config validation, SQLite session persistence, TTL expiration, idempotency, HMAC validation, multi-user isolation, text chunking, and auto-discovery.tests/test_server.pycontinue to pass (47/47 tests total).