send discord notification when someone joins the waitlist
This commit is contained in:
parent
ab004235f6
commit
5e0c2ae643
@ -3,6 +3,7 @@ import { z } from "zod";
|
||||
|
||||
import appLogger from "../../../integrations/logger";
|
||||
import { addSubscriber } from "../../../integrations/mailchimp";
|
||||
import { executeWebhook } from "../../../integrations/discord";
|
||||
|
||||
const logger = appLogger.child({ mutation: "join-waitlist" });
|
||||
|
||||
@ -10,9 +11,14 @@ const bodySchema = z.object({
|
||||
email: z.string().email(),
|
||||
});
|
||||
|
||||
export default resolver.pipe(resolver.zod(bodySchema), async ({ email }, ctx) => {
|
||||
export default resolver.pipe(resolver.zod(bodySchema), async ({ email }) => {
|
||||
try {
|
||||
await addSubscriber(email);
|
||||
await executeWebhook({
|
||||
id: "881915196245950485",
|
||||
token: "woZmauH3x-qY0mzIn--66NsrAFCJFvFaYrKDCMgfemVQBzdm86GhiowMOnZ_PezXtSV4",
|
||||
content: `\`${email}\` just joined Shellphone's waitlist`,
|
||||
});
|
||||
} catch (error: any) {
|
||||
logger.error(error.response?.data);
|
||||
|
||||
|
13
integrations/discord.ts
Normal file
13
integrations/discord.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import got from "got";
|
||||
|
||||
type Params = {
|
||||
id: string;
|
||||
token: string;
|
||||
content: string;
|
||||
};
|
||||
|
||||
export function executeWebhook({ id, token, content }: Params) {
|
||||
const url = `https://discord.com/api/webhooks/${id}/${token}`;
|
||||
return got.post(url, { json: { content } });
|
||||
// https://discord.com/api/webhooks/881915196245950485/woZmauH3x-qY0mzIn--66NsrAFCJFvFaYrKDCMgfemVQBzdm86GhiowMOnZ_PezXtSV4
|
||||
}
|
Loading…
Reference in New Issue
Block a user