PDS Admin tool make it easier to moderate your PDS with labels
43
fork

Configure Feed

Select the types of activity you want to include in your feed.

Added email notifications for new accounts

authored by

Chris Greenacre and committed by tangled.org d5aa8d03 8de0b2f3

+61
+2
settings.toml.example
··· 12 12 backfillAccounts = true 13 13 # Listens for new accounts 14 14 listenForNewAccounts = true 15 + # Send notification for new accounts 16 + notifyOnNewAccounts = false 15 17 16 18 # Another PDS you want to watch 17 19 # [pds.your-pds-two]
+11
src/handlers/pdsSubscriber.ts
··· 6 6 import { FirehoseSubscription } from "@atcute/firehose"; 7 7 import { ComAtprotoSyncSubscribeRepos } from "@atcute/atproto"; 8 8 import { handleNewIdentityEvent } from "./handleNewIdentityEvent.js"; 9 + import { sendNewAccountNotification } from "../mailer.js"; 9 10 10 11 export const pdsSubscriber = ( 11 12 config: PDSConfig, ··· 39 40 }, 40 41 "Identity event", 41 42 ); 43 + if (config.notifyOnNewAccounts) { 44 + await queue.add(() => 45 + sendNewAccountNotification(config.notifyEmails, { 46 + did: message.did, 47 + pds: config.host 48 + }).catch((err) => { 49 + logger.error({ err }, "Error sending new account notification email") 50 + }) 51 + ); 52 + } 42 53 await queue.add(() => 43 54 handleNewIdentityEvent( 44 55 db,
+47
src/mailer.ts
··· 73 73 return info.join("\n"); 74 74 } 75 75 76 + export const sendNewAccountNotification = async ( 77 + emails: string[], 78 + params: { 79 + did: string; 80 + pds: string; 81 + } 82 + ) => { 83 + const { 84 + did, 85 + pds 86 + } = params; 87 + 88 + const subject = `New account created on ${pds} - ${did}`; 89 + let infoText = [ 90 + `A new account has been detected on ${pds}.`, 91 + ``, 92 + `DID: ${did}`, 93 + `PDS: ${pds}` 94 + ]; 95 + const emailText = infoText.join("\n"); 96 + 97 + if (resend) { 98 + await resend.emails.send({ 99 + from: senderEmail, 100 + to: emails, 101 + subject, 102 + emailText, 103 + }); 104 + } else { 105 + if (transporter) { 106 + await transporter.sendMail({ 107 + from: senderEmail, 108 + to: emails.join(", "), 109 + subject, 110 + emailText, 111 + }); 112 + } else { 113 + logger.error( 114 + { 115 + error: "No transporter available", 116 + }, 117 + "Error sending email", 118 + ); 119 + } 120 + } 121 + } 122 + 76 123 export const sendLabelNotification = async ( 77 124 emails: string[], 78 125 params: {
+1
src/types/settings.ts
··· 7 7 pdsAdminPassword?: string; 8 8 backfillAccounts: boolean; 9 9 listenForNewAccounts: boolean; 10 + notifyOnNewAccounts: boolean; 10 11 } 11 12 12 13 export type LabelAction = "notify" | "takedown";