tambahannya

This commit is contained in:
bipproduction
2025-10-23 10:12:19 +08:00
parent 3dfb6963fc
commit b85fa6801b
2 changed files with 7 additions and 7 deletions

View File

@@ -109,3 +109,4 @@
{"level":30,"time":"2025-10-22T13:59:59.249Z","pid":98844,"hostname":"air-malik","msg":"WA API started"} {"level":30,"time":"2025-10-22T13:59:59.249Z","pid":98844,"hostname":"air-malik","msg":"WA API started"}
{"level":30,"time":"2025-10-22T14:00:02.944Z","pid":98844,"hostname":"air-malik","msg":"WA API started"} {"level":30,"time":"2025-10-22T14:00:02.944Z","pid":98844,"hostname":"air-malik","msg":"WA API started"}
{"level":30,"time":"2025-10-22T14:00:14.934Z","pid":98844,"hostname":"air-malik","msg":"WA API started"} {"level":30,"time":"2025-10-22T14:00:14.934Z","pid":98844,"hostname":"air-malik","msg":"WA API started"}
{"level":30,"time":"2025-10-23T02:08:17.603Z","pid":98844,"hostname":"air-malik","msg":"WA API started"}

View File

@@ -2,7 +2,7 @@ import Elysia, { t } from "elysia";
import { prisma } from "../lib/prisma"; import { prisma } from "../lib/prisma";
import type { WAHookMessage } from "types/wa_messages"; import type { WAHookMessage } from "types/wa_messages";
import _ from "lodash"; import _ from "lodash";
import { Whatsapp, whatsappApiInit } from "../lib/wa-api/wa-api";
import type { GetParams, PostData } from "whatsapp-api-js/types"; import type { GetParams, PostData } from "whatsapp-api-js/types";
import { logger } from "../lib/logger"; import { logger } from "../lib/logger";
@@ -10,14 +10,13 @@ import { logger } from "../lib/logger";
import { WhatsAppClient, WhatsAppMessageType } from 'whatsapp-client-sdk'; import { WhatsAppClient, WhatsAppMessageType } from 'whatsapp-client-sdk';
const client = new WhatsAppClient({ const client = new WhatsAppClient({
accessToken: process.env.WA_TOKEN!, accessToken: process.env.WA_TOKEN!,
phoneNumberId: process.env.WA_PHONE_NUMBER_ID!, phoneNumberId: process.env.WA_PHONE_NUMBER_ID!,
webhookVerifyToken: process.env.WA_WEBHOOK_TOKEN! webhookVerifyToken: process.env.WA_WEBHOOK_TOKEN!
}); });
async function fetchWithTimeout(input: RequestInfo, init: RequestInit, timeoutMs = 120_000) { async function fetchWithTimeout(input: RequestInfo, init: RequestInit, timeoutMs = 120_000) {
const controller = new AbortController() const controller = new AbortController()
const id = setTimeout(() => controller.abort(), timeoutMs) const id = setTimeout(() => controller.abort(), timeoutMs)
@@ -52,7 +51,6 @@ const WaHookRoute = new Elysia({
}) })
// ✅ Handle verifikasi Webhook (GET) // ✅ Handle verifikasi Webhook (GET)
.get("/hook", async (ctx) => { .get("/hook", async (ctx) => {
Whatsapp.get(ctx.query as GetParams)
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"];
@@ -92,11 +90,12 @@ const WaHookRoute = new Elysia({
// ✅ Handle incoming message (POST) // ✅ Handle incoming message (POST)
.post("/hook", async ({ body }) => { .post("/hook", async ({ body }) => {
Whatsapp.post(body as PostData)
logger.info("[POST] Incoming WhatsApp Webhook:", body) logger.info("[POST] Incoming WhatsApp Webhook:", body)
const webhook = client.parseWebhook(body) const webhook = client.parseWebhook(body)
logger.info(`[POST] Message Type: ${webhook[0]?.type}`)
if (webhook[0]?.type === WhatsAppMessageType.TEXT) { if (webhook[0]?.type === WhatsAppMessageType.TEXT) {
const message = webhook[0]?.text const message = webhook[0]?.text
const from = webhook[0]?.from const from = webhook[0]?.from
@@ -108,7 +107,7 @@ const WaHookRoute = new Elysia({
name, name,
} }
logger.info(`[POST] Incoming WhatsApp Webhook: ${JSON.stringify(dataMessage)}`) logger.info(`[POST] Message: ${JSON.stringify(dataMessage)}`)
} }
// const create = await prisma.waHook.create({ // const create = await prisma.waHook.create({