tambahannya

This commit is contained in:
bipproduction
2025-10-27 14:41:17 +08:00
parent 38c29d2af0
commit 42333587c6
9 changed files with 441 additions and 211 deletions

View File

@@ -1,4 +1,4 @@
import Elysia from "elysia";
import Elysia, { t } from "elysia";
import { startClient, getState } from "../lib/wa/wa_service";
import _ from "lodash";
@@ -48,5 +48,36 @@ const WaRoute = new Elysia({
state: _.omit(state, "client"),
};
})
.post("send-text", async ({body}) => {
const state = getState();
if (!state.ready) {
return {
message: "WhatsApp route not ready",
};
}
const client = state.client;
if (!client) {
return {
message: "WhatsApp client not ready",
};
}
const chat = await client.getChatById(`${body.number}@c.us`);
await chat.sendMessage(body.text);
return {
message: "WhatsApp route ready",
};
},{
body: t.Object({
number: t.String(),
text: t.String(),
}),
detail: {
description: "Send text to WhatsApp",
tags: ["WhatsApp"],
}
})
export default WaRoute;