Update group name
This commit is contained in:
parent
75c7f3ff76
commit
5b89bfce7c
1 changed files with 15 additions and 12 deletions
|
|
@ -46,8 +46,11 @@ const sendSignalMessageTask = async ({
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Check if 'to' is a group ID (UUID format, group.base64 format, or base64) vs phone number
|
// Check if 'to' is a group ID (UUID format, group.base64 format, or base64) vs phone number
|
||||||
const isUUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(to);
|
const isUUID =
|
||||||
const isGroupPrefix = to.startsWith('group.');
|
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(
|
||||||
|
to,
|
||||||
|
);
|
||||||
|
const isGroupPrefix = to.startsWith("group.");
|
||||||
const isBase64 = /^[A-Za-z0-9+/]+=*$/.test(to) && to.length > 20; // Base64 internal_id
|
const isBase64 = /^[A-Za-z0-9+/]+=*$/.test(to) && to.length > 20; // Base64 internal_id
|
||||||
const isGroupId = isUUID || isGroupPrefix || isBase64;
|
const isGroupId = isUUID || isGroupPrefix || isBase64;
|
||||||
const enableAutoGroups = process.env.BRIDGE_SIGNAL_AUTO_GROUPS === "true";
|
const enableAutoGroups = process.env.BRIDGE_SIGNAL_AUTO_GROUPS === "true";
|
||||||
|
|
@ -62,7 +65,7 @@ const sendSignalMessageTask = async ({
|
||||||
// If sending to a phone number and auto-groups is enabled, create a group first
|
// If sending to a phone number and auto-groups is enabled, create a group first
|
||||||
if (enableAutoGroups && !isGroupId && to && conversationId) {
|
if (enableAutoGroups && !isGroupId && to && conversationId) {
|
||||||
try {
|
try {
|
||||||
const groupName = `Support request: ${conversationId}`;
|
const groupName = `DPN Support Request: ${conversationId}`;
|
||||||
const createGroupResponse = await groupsClient.v1GroupsNumberPost({
|
const createGroupResponse = await groupsClient.v1GroupsNumberPost({
|
||||||
number: bot.phoneNumber,
|
number: bot.phoneNumber,
|
||||||
data: {
|
data: {
|
||||||
|
|
@ -76,15 +79,15 @@ const sendSignalMessageTask = async ({
|
||||||
// The createGroupResponse.id already contains the full group identifier (group.BASE64)
|
// The createGroupResponse.id already contains the full group identifier (group.BASE64)
|
||||||
finalTo = createGroupResponse.id;
|
finalTo = createGroupResponse.id;
|
||||||
groupCreated = true;
|
groupCreated = true;
|
||||||
|
|
||||||
// Fetch the group details to get the actual internalId
|
// Fetch the group details to get the actual internalId
|
||||||
let internalId: string | undefined;
|
let internalId: string | undefined;
|
||||||
try {
|
try {
|
||||||
const groups = await groupsClient.v1GroupsNumberGet({
|
const groups = await groupsClient.v1GroupsNumberGet({
|
||||||
number: bot.phoneNumber,
|
number: bot.phoneNumber,
|
||||||
});
|
});
|
||||||
|
|
||||||
const createdGroup = groups.find(g => g.id === finalTo);
|
const createdGroup = groups.find((g) => g.id === finalTo);
|
||||||
if (createdGroup && createdGroup.internalId) {
|
if (createdGroup && createdGroup.internalId) {
|
||||||
internalId = createdGroup.internalId;
|
internalId = createdGroup.internalId;
|
||||||
console.log(
|
console.log(
|
||||||
|
|
@ -92,7 +95,7 @@ const sendSignalMessageTask = async ({
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
// Fallback: extract base64 part from ID
|
// Fallback: extract base64 part from ID
|
||||||
if (finalTo.startsWith('group.')) {
|
if (finalTo.startsWith("group.")) {
|
||||||
internalId = finalTo.substring(6);
|
internalId = finalTo.substring(6);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -101,7 +104,7 @@ const sendSignalMessageTask = async ({
|
||||||
`[send-signal-message] Could not fetch group details, using ID base64 part`,
|
`[send-signal-message] Could not fetch group details, using ID base64 part`,
|
||||||
);
|
);
|
||||||
// Fallback: extract base64 part from ID
|
// Fallback: extract base64 part from ID
|
||||||
if (finalTo.startsWith('group.')) {
|
if (finalTo.startsWith("group.")) {
|
||||||
internalId = finalTo.substring(6);
|
internalId = finalTo.substring(6);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -143,7 +146,7 @@ const sendSignalMessageTask = async ({
|
||||||
originalTo: to,
|
originalTo: to,
|
||||||
recipientChanged: to !== finalTo,
|
recipientChanged: to !== finalTo,
|
||||||
groupCreated,
|
groupCreated,
|
||||||
isGroupRecipient: finalTo.startsWith('group.'),
|
isGroupRecipient: finalTo.startsWith("group."),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Build the message data with optional quote parameters
|
// Build the message data with optional quote parameters
|
||||||
|
|
@ -152,11 +155,11 @@ const sendSignalMessageTask = async ({
|
||||||
recipients: [finalTo],
|
recipients: [finalTo],
|
||||||
message,
|
message,
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log(`[send-signal-message] Message data being sent:`, {
|
console.log(`[send-signal-message] Message data being sent:`, {
|
||||||
number,
|
number,
|
||||||
recipients: [finalTo],
|
recipients: [finalTo],
|
||||||
message: message.substring(0, 50) + '...',
|
message: message.substring(0, 50) + "...",
|
||||||
hasQuoteParams: !!(quoteMessage && quoteAuthor && quoteTimestamp),
|
hasQuoteParams: !!(quoteMessage && quoteAuthor && quoteTimestamp),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -195,7 +198,7 @@ const sendSignalMessageTask = async ({
|
||||||
messageDetails: {
|
messageDetails: {
|
||||||
fromNumber: number,
|
fromNumber: number,
|
||||||
toRecipients: [finalTo],
|
toRecipients: [finalTo],
|
||||||
hasQuote: !!(quoteMessage),
|
hasQuote: !!quoteMessage,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue