From 659c41f7135c709fd0381d28143975f02fc6ad3b Mon Sep 17 00:00:00 2001 From: gunshiz Date: Fri, 3 Jul 2026 17:08:39 +0700 Subject: [PATCH] feat: add enhanced logging for TikTok webhook authorization, environment variables, and message delivery status --- app/api/webhooks/tiktok/route.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/api/webhooks/tiktok/route.ts b/app/api/webhooks/tiktok/route.ts index 52e50e7..7879222 100644 --- a/app/api/webhooks/tiktok/route.ts +++ b/app/api/webhooks/tiktok/route.ts @@ -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); } -} +} \ No newline at end of file