Whatsapp service updates
This commit is contained in:
parent
e22a8e8d98
commit
3da103c010
16 changed files with 151 additions and 36 deletions
|
|
@ -1,12 +1,22 @@
|
|||
// import { db, getWorkerUtils } from "bridge-common";
|
||||
import { db, getWorkerUtils } from "bridge-common";
|
||||
|
||||
interface ReceiveWhatsappMessageTaskOptions {
|
||||
token;
|
||||
message: any;
|
||||
}
|
||||
|
||||
const receiveWhatsappMessageTask = async ({
|
||||
token,
|
||||
message,
|
||||
}: ReceiveWhatsappMessageTaskOptions): Promise<void> => {};
|
||||
}: ReceiveWhatsappMessageTaskOptions): Promise<void> => {
|
||||
const bot = await db
|
||||
.selectFrom("WhatsappBot")
|
||||
.selectAll()
|
||||
.where((eb) => eb.or([eb("token", "=", token), eb("id", "=", token)]))
|
||||
.executeTakeFirstOrThrow();
|
||||
|
||||
console.log(bot);
|
||||
};
|
||||
|
||||
export default receiveWhatsappMessageTask;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,32 @@
|
|||
// import { db, getWorkerUtils } from "bridge-common";
|
||||
import { db } from "bridge-common";
|
||||
|
||||
interface SendWhatsappMessageTaskOptions {
|
||||
token: string;
|
||||
recipient: string;
|
||||
message: any;
|
||||
}
|
||||
|
||||
const sendWhatsappMessageTask = async ({
|
||||
message,
|
||||
}: SendWhatsappMessageTaskOptions): Promise<void> => {};
|
||||
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 });
|
||||
};
|
||||
|
||||
export default sendWhatsappMessageTask;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue