app: email and WhatsApp's backend (APP-1.0-PLAN §8)
The church's one set of settings from Accounts (messaging.get; the SMTP password and WAWP token sealed with the link's secret, kept encrypted in AppSetting messaging_settings), fetched when the App links to Accounts, on Accounts' signed messaging.changed, once a day and on the admin's Fetch again. messages-send (every minute): the outbox by email (nodemailer) and WhatsApp (WAWP), STOP checked before every WhatsApp (the member and anyone with the same number), email instead for what a member asked for (never announcements), retries after 2, 4, 8 and 16 minutes, a reminder never after its slot started, nothing more than 3 days late. announcement-sends and devotional-sends queue "Also send it" at the publish time and today's devotional at each member's time. Members' choices (NotificationSettings), news consent kept from Accounts, MessageCount for the heartbeat's messages, the admin's Email and WhatsApp API with Send a test. Migration messaging (checked on PostgreSQL 18). 110 backend tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -8,16 +8,18 @@
|
||||
* GET /feed/v1/events?updatedSince= the App's events (crosscode.event-feed/1), public
|
||||
* POST /feed/v1/changed a sibling's events changed: fetch them now (signed)
|
||||
*
|
||||
* To come: Accounts' "the messaging settings changed" (§8).
|
||||
* POST /accounts/v1/messaging-changed Accounts: the church's email or WhatsApp settings changed:
|
||||
* fetch them again (signed, APP-1.0-PLAN §8)
|
||||
*/
|
||||
import express from 'express';
|
||||
import { CHURCH_PATHS, churchChangedSchema, eventChangedSchema, FEED_PATHS, LINK_PATHS } from '@crosscode/contracts';
|
||||
import { CHURCH_PATHS, churchChangedSchema, eventChangedSchema, FEED_PATHS, IDENTITY_REQUEST_SCHEMA, LINK_PATHS, MESSAGING_CHANGED_PATH, messagingChangedSchema } from '@crosscode/contracts';
|
||||
import { LINK_HEADERS, verify } from '@crosscode/contracts/signing';
|
||||
import type { Ctx } from '../context.js';
|
||||
import { churchChanged } from '../church/profile.js';
|
||||
import { acceptConnect, acceptDisconnect, LinkError } from './connect.js';
|
||||
import { buildFeed, publishOn, syncLink } from '../events/feed.js';
|
||||
import { enabledModules } from '../modules.js';
|
||||
import { fetchMessagingSoon } from '../messaging/settings.js';
|
||||
|
||||
export function linksRouter(ctx: Ctx) {
|
||||
const r = express.Router();
|
||||
@@ -108,5 +110,18 @@ export function linksRouter(ctx: Ctx) {
|
||||
return fail(res, e);
|
||||
}
|
||||
});
|
||||
|
||||
r.post(MESSAGING_CHANGED_PATH.replace(/^\/api/, ''), raw, async (req, res) => {
|
||||
try {
|
||||
const got = await signedBy(req, res, true);
|
||||
if (!got) return undefined;
|
||||
if (!messagingChangedSchema.safeParse(got.body).success) return say(res, 400, 'INVALID_REQUEST', 'That isn\'t a messaging.changed message.');
|
||||
// Fetched after answering: Accounts doesn't wait for it (the send job tries again if it fails).
|
||||
fetchMessagingSoon(ctx);
|
||||
return res.json({ schema: IDENTITY_REQUEST_SCHEMA, ok: true });
|
||||
} catch (e) {
|
||||
return fail(res, e);
|
||||
}
|
||||
});
|
||||
return r;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user