feat(02-03): WhatsApp adapter with business-function scoping and router registration
- Register whatsapp_router in gateway main.py (GET + POST /whatsapp/webhook) - Implement is_clearly_off_topic() tier 1 keyword scoping gate - Implement build_off_topic_reply() canned redirect message builder - Full webhook handler: verify -> normalize -> tenant -> rate limit -> dedup -> scope -> media -> dispatch - Outbound delivery via send_whatsapp_message() and send_whatsapp_media() - Media download from Meta API and storage in MinIO with tenant-prefixed keys - 14 new passing scoping tests
This commit is contained in:
@@ -2,20 +2,23 @@
|
||||
Channel Gateway — FastAPI application.
|
||||
|
||||
Mounts the slack-bolt AsyncApp as a sub-application at /slack/events.
|
||||
All other channels will be added as additional sub-applications in Phase 2.
|
||||
Registers the WhatsApp webhook router at /whatsapp/webhook.
|
||||
|
||||
Port: 8001
|
||||
|
||||
Endpoints:
|
||||
POST /slack/events — Slack Events API webhook (handled by slack-bolt)
|
||||
GET /health — Health check
|
||||
POST /slack/events — Slack Events API webhook (handled by slack-bolt)
|
||||
GET /whatsapp/webhook — WhatsApp hub challenge verification
|
||||
POST /whatsapp/webhook — WhatsApp inbound message webhook
|
||||
GET /health — Health check
|
||||
|
||||
Startup sequence:
|
||||
1. Create Redis connection
|
||||
2. Create slack-bolt AsyncApp (signing_secret=...)
|
||||
3. Register Slack event handlers
|
||||
4. Mount slack-bolt request handler at /slack/events
|
||||
5. Expose /health
|
||||
5. Include WhatsApp router
|
||||
6. Expose /health
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -28,6 +31,7 @@ from slack_bolt.adapter.fastapi.async_handler import AsyncSlackRequestHandler
|
||||
from slack_bolt.async_app import AsyncApp
|
||||
|
||||
from gateway.channels.slack import register_slack_handlers
|
||||
from gateway.channels.whatsapp import whatsapp_router
|
||||
from shared.config import settings
|
||||
from shared.db import async_session_factory
|
||||
|
||||
@@ -79,6 +83,11 @@ register_slack_handlers(
|
||||
# ---------------------------------------------------------------------------
|
||||
slack_handler = AsyncSlackRequestHandler(slack_app)
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Register channel routers
|
||||
# ---------------------------------------------------------------------------
|
||||
app.include_router(whatsapp_router)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Routes
|
||||
|
||||
Reference in New Issue
Block a user