tambahan
This commit is contained in:
@@ -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");
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user