link-stack/apps/bridge-worker/tasks/signal/receive-signal-message.ts

50 lines
989 B
TypeScript
Raw Normal View History

2024-06-05 15:12:48 +02:00
import { db, getWorkerUtils } from "@link-stack/bridge-common";
2024-04-30 13:13:49 +02:00
interface ReceiveSignalMessageTaskOptions {
2024-06-05 15:12:48 +02:00
token: string;
2024-07-18 11:08:01 +02:00
to: string;
from: string;
messageId: string;
sentAt: string;
2024-06-05 15:12:48 +02:00
message: string;
2024-07-18 11:08:01 +02:00
attachment?: string;
filename?: string;
mimeType?: string;
2024-04-30 13:13:49 +02:00
}
const receiveSignalMessageTask = async ({
2024-06-05 15:12:48 +02:00
token,
2024-07-18 11:08:01 +02:00
to,
from,
messageId,
sentAt,
2024-04-30 13:13:49 +02:00
message,
2024-07-18 11:08:01 +02:00
attachment,
filename,
mimeType,
2024-06-05 15:12:48 +02:00
}: ReceiveSignalMessageTaskOptions): Promise<void> => {
2024-07-18 11:08:01 +02:00
console.log({ token, to, from });
2024-06-05 15:12:48 +02:00
const worker = await getWorkerUtils();
const row = await db
.selectFrom("SignalBot")
.selectAll()
.where("id", "=", token)
.executeTakeFirstOrThrow();
const backendId = row.id;
const payload = {
2024-07-18 11:08:01 +02:00
to,
from,
message_id: messageId,
sent_at: sentAt,
2024-06-05 15:12:48 +02:00
message,
2024-07-18 11:08:01 +02:00
attachment,
filename,
mime_type: mimeType,
2024-06-05 15:12:48 +02:00
};
await worker.addJob("common/notify-webhooks", { backendId, payload });
};
2024-04-30 13:13:49 +02:00
export default receiveSignalMessageTask;