This commit is contained in:
bipproduction
2025-10-20 16:52:51 +08:00
parent a8fc7da20d
commit 5d28dbf041
2 changed files with 17 additions and 3 deletions

View File

@@ -35,13 +35,14 @@ const Api = new Elysia({
.use(ApiUser) .use(ApiUser)
.use(WaRoute) .use(WaRoute)
.use(WebhookRoute) .use(WebhookRoute)
.use(WaHookRoute);
const app = new Elysia() const app = new Elysia()
.use(cors()) .use(cors())
.use(Api) .use(Api)
.use(Docs) .use(Docs)
.use(Auth) .use(Auth)
.use(WaHookRoute)
.get("*", html) .get("*", html)
.listen(3000, () => { .listen(3000, () => {
console.log("Server running at http://localhost:3000"); console.log("Server running at http://localhost:3000");

View File

@@ -1,4 +1,5 @@
import Elysia, { t } from "elysia"; import Elysia, { t } from "elysia";
import { prisma } from "../lib/prisma";
const VERIFY_TOKEN = "token_yang_kamu_set_di_dashboard"; const VERIFY_TOKEN = "token_yang_kamu_set_di_dashboard";
@@ -7,14 +8,26 @@ const WaHookRoute = new Elysia({
tags: ["WhatsApp Hook"], tags: ["WhatsApp Hook"],
}) })
// ✅ Handle verifikasi Webhook (GET) // ✅ Handle verifikasi Webhook (GET)
.get("/hook", (ctx) => { .get("/hook", async(ctx) => {
const { query, set } = ctx; const { query, set } = ctx;
const mode = query["hub.mode"]; const mode = query["hub.mode"];
const challenge = query["hub.challenge"]; const challenge = query["hub.challenge"];
const verifyToken = query["hub.verify_token"];
const getToken = await prisma.webHook.findFirst({
where: {
apiToken: verifyToken || "",
},
});
if (!getToken) {
set.status = 403;
return "Verification failed";
}
if (mode === "subscribe") { if (mode === "subscribe") {
set.status = 200; set.status = 200;
return challenge; // WA butuh raw challenge string return challenge;
} }
set.status = 403; set.status = 403;