This commit is contained in:
bipproduction
2025-11-19 16:54:36 +08:00
parent 1c7b8e7761
commit 1febcde510
2 changed files with 15 additions and 5 deletions

View File

@@ -140,12 +140,12 @@ function EditView({ webhook }: { webhook: Partial<WebHook> | null }) {
} }
return ( return (
<Stack style={{ backgroundColor: "#191919" }} p="xl"> <Stack style={{ backgroundColor: "#191919" }} p="xl" >
<Stack <Stack
gap="md" gap="md"
w={"100%"} w={"100%"}
mx="auto" mx="auto"
bg="rgba(45,45,45,0.6)" bg={enabled? "" : "rgba(47, 34, 34, 0.6)"}
p="xl" p="xl"
style={{ style={{
borderRadius: "20px", borderRadius: "20px",

View File

@@ -9,8 +9,11 @@ import { prisma } from '../prisma';
type HookData = type HookData =
| { eventType: "qr"; qr: string } | { eventType: "qr"; qr: string }
| { eventType: "start" }
| { eventType: "ready" } | { eventType: "ready" }
| { eventType: "disconnected"; reason?: string } | { eventType: "disconnected"; reason?: string }
| { eventType: "reconnect" }
| { eventType: "auth_failure"; msg: string }
| { eventType: "message" } & Partial<WAWebJS.Message>; | { eventType: "message" } & Partial<WAWebJS.Message>;
@@ -20,7 +23,7 @@ async function handleHook(data: HookData) {
await Promise.allSettled( await Promise.allSettled(
webHooks.map(async (hook) => { webHooks.map(async (hook) => {
try { try {
log(`🌐 Mengirim webhook ke ${hook.url}`); log(`🌐 Mengirim webhook ke ${hook.name} ${hook.url}`);
let res: Response = {} as Response; let res: Response = {} as Response;
res = await fetch(hook.url, { res = await fetch(hook.url, {
@@ -33,9 +36,11 @@ async function handleHook(data: HookData) {
}); });
const json = await res.text(); const json = await res.text();
logger.info(`[RESPONSE] ${hook.url}: ${json}`); logger.info(`[RESPONSE] ${hook.name} ${hook.url}: ${json}`);
} catch (err) { } catch (err) {
logger.error(`[ERROR] ${hook.url}:`); logger.error(`[ERROR] ${hook.name} ${hook.url}:`);
logger.error(`[ERROR] ${hook.name}: ${err}`);
} }
}) })
) )
@@ -115,6 +120,8 @@ async function startClient() {
await destroyClient(); await destroyClient();
log('🚀 Memulai WhatsApp client...'); log('🚀 Memulai WhatsApp client...');
handleHook({ eventType: "start" });
const client = new Client({ const client = new Client({
authStrategy: new LocalAuth({ authStrategy: new LocalAuth({
dataPath: process.env.WWEBJS_AUTH || path.join(process.cwd(), '.wwebjs_auth') dataPath: process.env.WWEBJS_AUTH || path.join(process.cwd(), '.wwebjs_auth')
@@ -161,6 +168,7 @@ async function startClient() {
client.on('auth_failure', (msg) => { client.on('auth_failure', (msg) => {
log('❌ Autentikasi gagal:', msg); log('❌ Autentikasi gagal:', msg);
state.ready = false; state.ready = false;
handleHook({ eventType: "auth_failure", msg });
}); });
client.on('disconnected', async (reason) => { client.on('disconnected', async (reason) => {
@@ -174,6 +182,7 @@ async function startClient() {
log('⏳ Mencoba reconnect dalam 5 detik...'); log('⏳ Mencoba reconnect dalam 5 detik...');
state.reconnectTimeout = setTimeout(async () => { state.reconnectTimeout = setTimeout(async () => {
handleHook({ eventType: "reconnect" });
await startClient(); await startClient();
}, 5000); }, 5000);
}); });
@@ -191,6 +200,7 @@ async function startClient() {
state.isReconnecting = false; state.isReconnecting = false;
await startClient(); await startClient();
}, 10000); }, 10000);
handleHook({ eventType: "reconnect" });
} finally { } finally {
state.isStarting = false; state.isStarting = false;
} }