Skip to content

Commit d8532c9

Browse files
committed
refactor(notifications): migrate callers from sendSlackWebhook to SlackProvider
Updates the autumn webhook and auth sign-up notification to use the SlackProvider class directly, and drops the removed destination types (discord, teams, telegram, google_chat) from the alarm schema.
1 parent 05d344d commit d8532c9

3 files changed

Lines changed: 35 additions & 39 deletions

File tree

apps/api/src/routes/webhooks/autumn.ts

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { and, db, eq, gt } from "@databuddy/db";
22
import { usageAlertLog, user } from "@databuddy/db/schema";
33
import { UsageAlertEmail, UsageLimitEmail } from "@databuddy/email";
4-
import { sendSlackWebhook } from "@databuddy/notifications";
4+
import { SlackProvider } from "@databuddy/notifications";
55
import { cacheable } from "@databuddy/redis";
66
import { createId } from "@databuddy/shared/utils/ids";
77
import { Elysia } from "elysia";
@@ -269,24 +269,26 @@ function handleProductsUpdated(data: ProductsUpdatedData): WebhookResult {
269269
) {
270270
const info = SCENARIO_LABELS[scenario];
271271

272-
sendSlackWebhook(SLACK_URL, {
273-
title: info.title,
274-
message: `Customer ${info.verb} *${updated_product.name ?? updated_product.id}*.`,
275-
priority: info.priority,
276-
metadata: {
277-
scenario,
278-
product: updated_product.name ?? updated_product.id,
279-
customerId: customer.id ?? "—",
280-
email: customer.email ?? "—",
281-
name: customer.name ?? "—",
282-
env: customer.env,
283-
},
284-
}).catch((error) => {
285-
useLogger().error(
286-
error instanceof Error ? error : new Error(String(error)),
287-
{ autumn: { slack: true, customerId: customer.id } }
288-
);
289-
});
272+
new SlackProvider({ webhookUrl: SLACK_URL })
273+
.send({
274+
title: info.title,
275+
message: `Customer ${info.verb} *${updated_product.name ?? updated_product.id}*.`,
276+
priority: info.priority,
277+
metadata: {
278+
scenario,
279+
product: updated_product.name ?? updated_product.id,
280+
customerId: customer.id ?? "—",
281+
email: customer.email ?? "—",
282+
name: customer.name ?? "—",
283+
env: customer.env,
284+
},
285+
})
286+
.catch((error) => {
287+
useLogger().error(
288+
error instanceof Error ? error : new Error(String(error)),
289+
{ autumn: { slack: true, customerId: customer.id } }
290+
);
291+
});
290292
}
291293

292294
return { success: true, message: `Processed ${scenario}` };

packages/auth/src/auth.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ import {
1212
ResetPasswordEmail,
1313
VerificationEmail,
1414
} from "@databuddy/email";
15-
import {
16-
type NotificationResult,
17-
sendSlackWebhook,
18-
} from "@databuddy/notifications";
15+
import { SlackProvider } from "@databuddy/notifications";
1916
import { getRedisCache, rateLimit } from "@databuddy/redis";
2017
import { createId } from "@databuddy/shared/utils/ids";
2118
import { drizzleAdapter } from "better-auth/adapters/drizzle";
@@ -66,18 +63,19 @@ function notifySignUpSlackAction(input: {
6663
return;
6764
}
6865

69-
sendSlackWebhook(SLACK_WEBHOOK_URL, {
70-
title: "New sign-up",
71-
message: "A new user created an account.",
72-
priority: "normal",
73-
metadata: {
74-
email: input.email,
75-
name: input.name ?? "—",
76-
userId: input.userId,
77-
organizationId: input.organizationId,
78-
},
79-
})
80-
.then((result: NotificationResult) => {
66+
new SlackProvider({ webhookUrl: SLACK_WEBHOOK_URL })
67+
.send({
68+
title: "New sign-up",
69+
message: "A new user created an account.",
70+
priority: "normal",
71+
metadata: {
72+
email: input.email,
73+
name: input.name ?? "—",
74+
userId: input.userId,
75+
organizationId: input.organizationId,
76+
},
77+
})
78+
.then((result) => {
8179
if (!result.success) {
8280
console.error(
8381
"Failed to send Slack notification for sign-up:",

packages/db/src/drizzle/schema.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,12 +1636,8 @@ export type AlarmTriggerTypeValue = (typeof alarmTriggerTypeValues)[number];
16361636

16371637
export const alarmDestinationTypeValues = [
16381638
"slack",
1639-
"discord",
16401639
"email",
16411640
"webhook",
1642-
"teams",
1643-
"telegram",
1644-
"google_chat",
16451641
] as const;
16461642
export type AlarmDestinationTypeValue =
16471643
(typeof alarmDestinationTypeValues)[number];

0 commit comments

Comments
 (0)