Add Signal auto-group creation
This commit is contained in:
parent
a83907b4be
commit
c8ccee7ada
7 changed files with 393 additions and 8 deletions
|
|
@ -1,4 +1,6 @@
|
|||
import { db, getWorkerUtils } from "@link-stack/bridge-common";
|
||||
import * as signalApi from "@link-stack/signal-api";
|
||||
const { Configuration, GroupsApi } = signalApi;
|
||||
|
||||
interface ReceiveSignalMessageTaskOptions {
|
||||
token: string;
|
||||
|
|
@ -10,6 +12,7 @@ interface ReceiveSignalMessageTaskOptions {
|
|||
attachment?: string;
|
||||
filename?: string;
|
||||
mimeType?: string;
|
||||
isGroup?: boolean;
|
||||
}
|
||||
|
||||
const receiveSignalMessageTask = async ({
|
||||
|
|
@ -22,6 +25,7 @@ const receiveSignalMessageTask = async ({
|
|||
attachment,
|
||||
filename,
|
||||
mimeType,
|
||||
isGroup,
|
||||
}: ReceiveSignalMessageTaskOptions): Promise<void> => {
|
||||
const worker = await getWorkerUtils();
|
||||
const row = await db
|
||||
|
|
@ -31,8 +35,43 @@ const receiveSignalMessageTask = async ({
|
|||
.executeTakeFirstOrThrow();
|
||||
|
||||
const backendId = row.id;
|
||||
let finalTo = to;
|
||||
|
||||
// Check if auto-group creation is enabled and this is NOT already a group message
|
||||
const enableAutoGroups = process.env.BRIDGE_SIGNAL_AUTO_GROUPS === "true";
|
||||
|
||||
if (enableAutoGroups && !isGroup && from && to) {
|
||||
try {
|
||||
const config = new Configuration({
|
||||
basePath: process.env.BRIDGE_SIGNAL_URL,
|
||||
});
|
||||
const groupsClient = new GroupsApi(config);
|
||||
|
||||
// Create new group for this conversation
|
||||
const groupName = `Support: ${from}`;
|
||||
const createGroupResponse = await groupsClient.v1GroupsNumberPost({
|
||||
number: row.phoneNumber,
|
||||
data: {
|
||||
name: groupName,
|
||||
members: [from],
|
||||
description: "Private support conversation",
|
||||
},
|
||||
});
|
||||
|
||||
if (createGroupResponse.id) {
|
||||
finalTo = createGroupResponse.id;
|
||||
console.log(
|
||||
`Created new Signal group ${finalTo} for conversation with ${from}`,
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error creating Signal group:", error);
|
||||
// Continue with original 'to' if group creation fails
|
||||
}
|
||||
}
|
||||
|
||||
const payload = {
|
||||
to,
|
||||
to: finalTo,
|
||||
from,
|
||||
message_id: messageId,
|
||||
sent_at: sentAt,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue