feat: add enhanced logging for TikTok webhook authorization, environment variables, and message delivery status

This commit is contained in:
2026-07-03 17:08:39 +07:00 Unverified
parent 179b8b2e30
commit 659c41f713
+13 -1
View File
@@ -6,6 +6,7 @@ export async function POST(req: Request) {
if (process.env.TIKTOK_WEBHOOK_SECRET) {
const { searchParams } = new URL(req.url);
if (searchParams.get("secret") !== process.env.TIKTOK_WEBHOOK_SECRET) {
console.error("[TikTok Webhook] Unauthorized request: invalid or missing secret query parameter.");
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
}
@@ -127,6 +128,16 @@ async function sendDiscordNotification(content: string, embed?: any) {
const token = process.env.DISCORD_BOT_TOKEN;
const channelId = process.env.DISCORD_CHANNEL_ID;
if (!token) {
console.error("[TikTok Webhook] Missing DISCORD_BOT_TOKEN");
return;
}
if (!channelId) {
console.error("[TikTok Webhook] Missing DISCORD_CHANNEL_ID environment variable. Please add it to your .env file.");
return;
}
try {
const res = await fetch(`https://discord.com/api/v10/channels/${channelId}/messages`, {
method: "POST",
@@ -143,8 +154,9 @@ async function sendDiscordNotification(content: string, embed?: any) {
if (!res.ok) {
console.error("[TikTok Webhook] Failed to send Discord message:", await res.text());
} else {
console.log("[TikTok Webhook] Successfully sent Discord message");
}
} catch (error) {
console.error("[TikTok Webhook] Error sending Discord message:", error);
}
}
}