Skip to content

Commit 1a3329a

Browse files
committed
Add merchant research Discord channel for registration notifications
Sends new origin registrations to a dedicated merchant research channel with the origin URL displayed between the title and description. The existing notification channel continues to receive the same format as before.
1 parent fa9c641 commit 1a3329a

4 files changed

Lines changed: 37 additions & 4 deletions

File tree

apps/scan/.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ NEXT_PUBLIC_PROXY_URL=https://proxy.x402scan.com
2121
SIGNOZ_INGESTION_KEY=
2222
OTEL_SERVICE_NAME=
2323
DISCORD_NOTIFICATIONS_WEBHOOK_URL=
24+
DISCORD_MERCHANT_RESEARCH_WEBHOOK_URL=

apps/scan/src/env.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export const env = createEnv({
4141
RESOURCE_SEARCH_API_KEY: z.string().optional(),
4242
STRIPE_SECRET_KEY: z.string(),
4343
DISCORD_NOTIFICATIONS_WEBHOOK_URL: z.url().optional(),
44+
DISCORD_MERCHANT_RESEARCH_WEBHOOK_URL: z.url().optional(),
4445
DISCORD_TELEMETRY_WEBHOOK_URL: z.string().optional(),
4546
X402_PAYEE_ADDRESS: z.string().optional(),
4647
AGENTCASH_URL: z.string().optional(),

apps/scan/src/lib/discord-notifications.ts

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,25 @@ interface DiscordConfig {
2020

2121
export function notifyNewServer(notification: NewServerNotification) {
2222
scheduleDiscordNotification({
23+
webhookUrl: env.DISCORD_NOTIFICATIONS_WEBHOOK_URL,
2324
username: NEW_SERVER_USERNAME,
2425
embed: config => buildNewServerEmbed(notification, config),
2526
});
27+
28+
scheduleDiscordNotification({
29+
webhookUrl: env.DISCORD_MERCHANT_RESEARCH_WEBHOOK_URL,
30+
username: NEW_SERVER_USERNAME,
31+
embed: config => buildMerchantResearchEmbed(notification, config),
32+
});
2633
}
2734

2835
function scheduleDiscordNotification(options: {
36+
webhookUrl: string | undefined;
2937
username: string;
3038
embed: (config: DiscordConfig) => DiscordEmbed;
3139
}) {
3240
try {
33-
const config = getDiscordConfig();
41+
const config = getDiscordConfig(options.webhookUrl);
3442
if (!config) return;
3543

3644
const sendNotification = async () => {
@@ -55,9 +63,9 @@ function scheduleDiscordNotification(options: {
5563
}
5664
}
5765

58-
function getDiscordConfig(): DiscordConfig | null {
59-
const webhookUrl = env.DISCORD_NOTIFICATIONS_WEBHOOK_URL;
60-
66+
function getDiscordConfig(
67+
webhookUrl: string | undefined
68+
): DiscordConfig | null {
6169
if (process.env.VERCEL_ENV !== 'production' || !webhookUrl) return null;
6270

6371
return {
@@ -115,6 +123,28 @@ function buildNewServerEmbed(
115123
};
116124
}
117125

126+
function buildMerchantResearchEmbed(
127+
notification: NewServerNotification,
128+
config: DiscordConfig
129+
) {
130+
const domain = domainFromOrigin(notification.origin);
131+
const title = notification.title?.trim();
132+
const name = title && title.length > 0 ? title : domain;
133+
const description = truncateDescription(notification.description);
134+
const lines = [
135+
`[**${escapeMarkdown(name)}**](${serverUrl(config.appUrl, notification.originId)})`,
136+
`\`${notification.origin}\``,
137+
];
138+
139+
if (description) {
140+
lines.push(escapeMarkdown(description));
141+
}
142+
143+
return {
144+
description: lines.join('\n'),
145+
};
146+
}
147+
118148
function serverUrl(appUrl: string, originId: string) {
119149
return `${appUrl}/server/${encodeURIComponent(originId)}`;
120150
}

turbo.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
"OPENROUTER_API_KEY",
126126
"FREEPIK_API_KEY",
127127
"DISCORD_TELEMETRY_WEBHOOK_URL",
128+
"DISCORD_MERCHANT_RESEARCH_WEBHOOK_URL",
128129
"X402_PAYEE_ADDRESS",
129130
"SOLANA_RPC_*",
130131
"BASE_RPC_*"

0 commit comments

Comments
 (0)