feat(notifications): follow modes, milestone alerts, notification enhancements
Follow Modes (neutral / pocket_veto / pocket_boost):
- Alembic migration 0013 adds follow_mode column to follows table
- FollowButton rewritten as mode-aware dropdown for bills; simple toggle for members/topics
- PATCH /api/follows/{id}/mode endpoint with validation
- Dispatcher filters pocket_veto follows (suppress new_document/new_amendment events)
- Dispatcher adds ntfy Actions header for pocket_boost follows
Change-driven (milestone) Alerts:
- New notification_utils.py with shared emit helpers and 30-min dedup
- congress_poller emits bill_updated events on milestone action text
- llm_processor replaced with shared emit util (also notifies member/topic followers)
Notification Enhancements:
- ntfy priority levels (high for bill_updated, default for others)
- Quiet hours (UTC): dispatcher holds events outside allowed window
- Digest mode (daily/weekly): send_notification_digest Celery beat task
- Notification history endpoint + Recent Alerts UI section
- Enriched following page (bill titles, member photos/details via sub-components)
- Follow mode test buttons in admin settings panel
Infrastructure:
- nginx: switch upstream blocks to set $variable proxy_pass so Docker DNS
re-resolves upstream IPs after container rebuilds (valid=10s)
- TROUBLESHOOTING.md documenting common Docker/nginx/postgres gotchas
Authored-By: Jack Levy
This commit is contained in:
@@ -103,8 +103,16 @@ def process_document_with_llm(self, document_id: int):
|
||||
|
||||
logger.info(f"{brief_type.capitalize()} brief {db_brief.id} created for bill {doc.bill_id} using {brief.llm_provider}/{brief.llm_model}")
|
||||
|
||||
# Emit notification events for users who follow this bill
|
||||
_emit_notification_events(db, bill, doc.bill_id, brief_type, brief.summary)
|
||||
# Emit notification events for bill followers, sponsor followers, and topic followers
|
||||
from app.workers.notification_utils import (
|
||||
emit_bill_notification,
|
||||
emit_member_follow_notifications,
|
||||
emit_topic_follow_notifications,
|
||||
)
|
||||
event_type = "new_amendment" if brief_type == "amendment" else "new_document"
|
||||
emit_bill_notification(db, bill, event_type, brief.summary)
|
||||
emit_member_follow_notifications(db, bill, event_type, brief.summary)
|
||||
emit_topic_follow_notifications(db, bill, event_type, brief.summary, brief.topic_tags or [])
|
||||
|
||||
# Trigger news fetch now that we have topic tags
|
||||
from app.workers.news_fetcher import fetch_news_for_bill
|
||||
@@ -120,34 +128,6 @@ def process_document_with_llm(self, document_id: int):
|
||||
db.close()
|
||||
|
||||
|
||||
def _emit_notification_events(db, bill, bill_id: str, brief_type: str, summary: str | None) -> None:
|
||||
"""Create a NotificationEvent row for every user following this bill."""
|
||||
from app.models.follow import Follow
|
||||
from app.models.notification import NotificationEvent
|
||||
from app.config import settings
|
||||
|
||||
followers = db.query(Follow).filter_by(follow_type="bill", follow_value=bill_id).all()
|
||||
if not followers:
|
||||
return
|
||||
|
||||
base_url = (settings.PUBLIC_URL or settings.LOCAL_URL).rstrip("/")
|
||||
payload = {
|
||||
"bill_title": bill.short_title or bill.title or "",
|
||||
"bill_label": f"{bill.bill_type.upper()} {bill.bill_number}",
|
||||
"brief_summary": (summary or "")[:300],
|
||||
"bill_url": f"{base_url}/bills/{bill_id}",
|
||||
}
|
||||
event_type = "new_amendment" if brief_type == "amendment" else "new_document"
|
||||
|
||||
for follow in followers:
|
||||
db.add(NotificationEvent(
|
||||
user_id=follow.user_id,
|
||||
bill_id=bill_id,
|
||||
event_type=event_type,
|
||||
payload=payload,
|
||||
))
|
||||
db.commit()
|
||||
|
||||
|
||||
@celery_app.task(bind=True, name="app.workers.llm_processor.backfill_brief_citations")
|
||||
def backfill_brief_citations(self):
|
||||
|
||||
Reference in New Issue
Block a user