Standardize bridge send/receive params
This commit is contained in:
parent
69abe9bee1
commit
c32c26088f
23 changed files with 7042 additions and 1276 deletions
|
|
@ -2,13 +2,13 @@ import { db } from "@link-stack/bridge-common";
|
|||
|
||||
interface SendWhatsappMessageTaskOptions {
|
||||
token: string;
|
||||
recipient: string;
|
||||
to: string;
|
||||
message: any;
|
||||
}
|
||||
|
||||
const sendWhatsappMessageTask = async ({
|
||||
message,
|
||||
recipient,
|
||||
to,
|
||||
token,
|
||||
}: SendWhatsappMessageTaskOptions): Promise<void> => {
|
||||
const bot = await db
|
||||
|
|
@ -18,15 +18,18 @@ const sendWhatsappMessageTask = async ({
|
|||
.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 });
|
||||
const params = { message, phoneNumber: to };
|
||||
try {
|
||||
const result = await fetch(url, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(params),
|
||||
});
|
||||
console.log({ result });
|
||||
} catch (error) {
|
||||
console.error({ error });
|
||||
throw new Error("Failed to send message");
|
||||
}
|
||||
};
|
||||
|
||||
export default sendWhatsappMessageTask;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue