Some checks failed
Deploy Palico Bot / deploy (push) Failing after 3s
- POST /api/notifications/dm takes a user id and a text, sends it as a direct message with no active mentions, and answers 204, 400, 404 or 422. - The send logic lives in src/features/directMessages.js with its own tests; the route gets its own per-minute rate limit behind the existing API key. - Sokko TCG uses it for its opt-in Expedition alerts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
23 lines
681 B
JavaScript
23 lines
681 B
JavaScript
import { Router } from "express";
|
|
import { DirectMessageError, sendDirectMessage } from "../../features/directMessages.js";
|
|
|
|
// Messages privés envoyés pour une application de confiance (clé d'API) : `{ userId, content }`.
|
|
function notificationsRouter({ client }) {
|
|
const router = Router();
|
|
|
|
router.post("/dm", async (req, res) => {
|
|
try {
|
|
await sendDirectMessage(client, req.body);
|
|
res.status(204).end();
|
|
} catch (error) {
|
|
if (error instanceof DirectMessageError) {
|
|
return res.status(error.status).json({ error: error.message, code: error.code });
|
|
}
|
|
throw error;
|
|
}
|
|
});
|
|
|
|
return router;
|
|
}
|
|
|
|
export { notificationsRouter };
|