Resend broadcasts: segment sync, one-call mass email, batch sends, contact pruning - #273
Merged
Conversation
…ls, contact pruning - New api/broadcasts/ blueprint + services/broadcasts_service.py (all routes volunteer.admin-gated), porting scripts/sync_resend_audience.py loaders: profiles, volunteers (type/event/selected), leads, Slack members, and contact_submissions filtered by inquiryType (+ receiveUpdates opt-in) - Segment sync runs as a daemon thread with redis status/lock (idempotent, create-only — never re-subscribes unsubscribed contacts); preview endpoint returns per-source counts + a contact-quota guardrail (RESEND_MARKETING_CONTACT_LIMIT, default 1000 = current free tier) - Broadcast create/send with server-enforced unsubscribe footer and a from-address allowlist (RESEND_BROADCAST_FROM / _FROM_DOMAINS, defaulting to notify.ohack.dev — notifs.ohack.org verification is partially failed) - POST /admin/broadcasts/batch-send: pre-personalized messages via resend.Batch.send in chunks of 100 (transactional quota), replacing the frontend's one-request-per-recipient loop; QR messages rejected per-recipient - Contact management for quota reclaim: full inventory endpoint + background prune job (modes: unsubscribed / emails / all) deleting GLOBAL contacts - userlist() in common/utils/slack.py is now redis-cached (10 min) above the rate limiter so varying active_days filters reuse one crawl; clear_slack_cache() clears the new prefix - Segment/contact/broadcast ops require RESEND_API_KEY (no send-only-key fallback); everything is ENVIRONMENT=test-gated and Slack-audited - Tests: api/broadcasts/tests/test_broadcasts_service.py (36 cases) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
New
api/broadcasts/blueprint +services/broadcasts_service.pypowering the admin Email tab (frontend PR: opportunity-hack/frontend-ohack.dev — "Admin Email tab" branchfeat/admin-email-broadcasts). Replaces one-HTTP-request-per-recipient mass emails with Resend segments + broadcasts, and adds a Batch path for personalized sends.Routes (all
volunteer.admin-gated, under/api/admin/broadcasts):GET segments/POST preview(dry-run per-source counts) /POST segments/sync+GET segments/<id>/sync-statusGET|POST ''(list / create broadcast — draft by default,send:true/scheduled_at),GET <id>,POST <id>/sendPOST batch-send—resend.Batch.sendin chunks of 100 on the transactional quotaGET contacts/POST contacts/prune+GET contacts/prune-status— quota reclaim (we're at 2,154/1,000 marketing contacts)Recipient sources (ported from
scripts/sync_resend_audience.py): registered users, volunteers (type/event/approved-only), leads, Slack members (activity-windowed; deleted/disabled always excluded), andcontact_submissionsfiltered byinquiryType(+ optionalreceiveUpdatesopt-in-only).Load-bearing details
{{{RESEND_UNSUBSCRIBE_URL}}}enforced server-side; from-address is allowlisted viaRESEND_BROADCAST_FROM(_DOMAINS)defaulting tonotify.ohack.dev(notifs.ohack.orgverification ispartially_failed).RESEND_API_KEY(no send-only-key fallback — it 401s).userlist()(common/utils/slack.py) is now redis-cached 10 min above the rate limiter;clear_slack_cache()clears the new prefix.ENVIRONMENT=test-gated (simulated: true) andsend_slack_audited.New env vars:
RESEND_BROADCAST_FROM,RESEND_BROADCAST_FROM_DOMAINS,RESEND_MARKETING_CONTACT_LIMIT(all have safe defaults).Test plan
api/broadcasts/tests/test_broadcasts_service.py— 36 cases (loaders/dedupe, sync lock/stall/simulation, from-address allowlist, unsubscribe footer, batch-send ordering/QR rejection, prune modes) — 49 passed incl. slack tests🤖 Generated with Claude Code