link-stack/apps/bridge-worker/tasks/whatsapp/send-whatsapp-message.ts

33 lines
792 B
TypeScript
Raw Normal View History

2024-06-05 08:52:41 +02:00
import { db } from "@link-stack/bridge-common";
2024-04-30 13:13:49 +02:00
interface SendWhatsappMessageTaskOptions {
2024-05-16 18:22:10 +02:00
token: string;
recipient: string;
2024-04-30 13:13:49 +02:00
message: any;
}
const sendWhatsappMessageTask = async ({
message,
2024-05-16 18:22:10 +02:00
recipient,
token,
}: SendWhatsappMessageTaskOptions): Promise<void> => {
const bot = await db
.selectFrom("WhatsappBot")
.selectAll()
.where("token", "=", token)
.executeTakeFirstOrThrow();
const url = `${process.env.BRIDGE_WHATSAPP_URL}/api/bots/${bot.id}/send`;
const params = { message, phoneNumber: recipient };
console.log({ params });
const result = await fetch(url, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(params),
});
console.log({ result });
};
2024-04-30 13:13:49 +02:00
export default sendWhatsappMessageTask;