PR to support email notifications for new accounts.
+65
Diff
round #1
+2
settings.toml.example
+2
settings.toml.example
+13
src/handlers/pdsSubscriber.ts
+13
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
+
if (message.active == true) {
45
+
await queue.add(() =>
46
+
sendNewAccountNotification(config.notifyEmails, {
47
+
did: message.did,
48
+
pds: config.host
49
+
}).catch((err) => {
50
+
logger.error({ err }, "Error sending new account notification email")
51
+
})
52
+
);
53
+
}
54
+
}
42
55
await queue.add(() =>
43
56
handleNewIdentityEvent(
44
57
db,
+49
src/mailer.ts
+49
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
+
logger.info(`Sending new account notification for ${did} on ${pds}...`)
89
+
90
+
const subject = `New account created on ${pds} - ${did}`;
91
+
let infoText = [
92
+
`A new account has been detected on ${pds}.`,
93
+
``,
94
+
`DID: ${did}`,
95
+
`PDS: ${pds}`
96
+
];
97
+
const text = infoText.join("\n");
98
+
99
+
if (resend) {
100
+
await resend.emails.send({
101
+
from: senderEmail,
102
+
to: emails,
103
+
subject,
104
+
text,
105
+
});
106
+
} else {
107
+
if (transporter) {
108
+
await transporter.sendMail({
109
+
from: senderEmail,
110
+
to: emails.join(", "),
111
+
subject,
112
+
text,
113
+
});
114
+
} else {
115
+
logger.error(
116
+
{
117
+
error: "No transporter available",
118
+
},
119
+
"Error sending email",
120
+
);
121
+
}
122
+
}
123
+
}
124
+
76
125
export const sendLabelNotification = async (
77
126
emails: string[],
78
127
params: {
History
2 rounds
1 comment
expand 1 comment
pull request successfully merged
tophhie.cloud
submitted
#0
Looks great to me! Thank you!