Worker build updates
This commit is contained in:
parent
45c80ca98a
commit
0cf1c3b8fd
64 changed files with 4216 additions and 3450 deletions
32
apps/bridge-worker/tasks/fetch-signal-messages.ts
Normal file
32
apps/bridge-worker/tasks/fetch-signal-messages.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import { db, getWorkerUtils } from "@link-stack/bridge-common";
|
||||
import * as signalApi from "@link-stack/signal-api";
|
||||
const { Configuration, MessagesApi } = signalApi;
|
||||
|
||||
const fetchSignalMessagesTask = async (): Promise<void> => {
|
||||
const worker = await getWorkerUtils();
|
||||
const rows = await db.selectFrom("SignalBot").selectAll().execute();
|
||||
const config = new Configuration({
|
||||
basePath: process.env.BRIDGE_SIGNAL_URL,
|
||||
});
|
||||
const messagesClient = new MessagesApi(config);
|
||||
|
||||
for (const row of rows) {
|
||||
const { id, phoneNumber: number } = row;
|
||||
const messages = await messagesClient.v1ReceiveNumberGet({ number });
|
||||
|
||||
for (const msg of messages) {
|
||||
const { envelope } = msg as any;
|
||||
const { source } = envelope;
|
||||
const message = envelope?.dataMessage?.message;
|
||||
if (source !== number && message) {
|
||||
await worker.addJob("signal/receive-signal-message", {
|
||||
token: id,
|
||||
sender: source,
|
||||
message,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default fetchSignalMessagesTask;
|
||||
Loading…
Add table
Add a link
Reference in a new issue