More groups WIP
This commit is contained in:
parent
f20cd5a53c
commit
7be5cb1478
8 changed files with 488 additions and 261 deletions
|
|
@ -58,14 +58,44 @@ const processMessage = async ({
|
|||
|
||||
const { attachments } = dataMessage;
|
||||
const rawTimestamp = dataMessage?.timestamp;
|
||||
|
||||
// Debug logging for group detection
|
||||
console.log(`[fetch-signal-messages] Processing message:`, {
|
||||
sourceUuid,
|
||||
source,
|
||||
rawTimestamp,
|
||||
hasGroupV2: !!dataMessage?.groupV2,
|
||||
hasGroupContext: !!dataMessage?.groupContext,
|
||||
hasGroupInfo: !!dataMessage?.groupInfo,
|
||||
isGroup,
|
||||
groupV2Id: dataMessage?.groupV2?.id,
|
||||
groupContextType: dataMessage?.groupContext?.type,
|
||||
groupInfoType: dataMessage?.groupInfo?.type,
|
||||
});
|
||||
const timestamp = new Date(rawTimestamp);
|
||||
|
||||
const formattedAttachments = await fetchAttachments(attachments);
|
||||
const primaryAttachment = formattedAttachments[0] ?? {};
|
||||
const additionalAttachments = formattedAttachments.slice(1);
|
||||
|
||||
// Extract group ID if this is a group message
|
||||
const groupId = dataMessage?.groupV2?.id || dataMessage?.groupContext?.id || dataMessage?.groupInfo?.groupId;
|
||||
|
||||
// IMPORTANT: Always use phoneNumber as 'to' for compatibility with Zammad
|
||||
// The group ID will be passed via the isGroup flag and potentially in metadata
|
||||
const toRecipient = phoneNumber;
|
||||
|
||||
console.log(`[fetch-signal-messages] Setting recipient:`, {
|
||||
isGroup,
|
||||
groupId,
|
||||
phoneNumber,
|
||||
toRecipient,
|
||||
note: 'Using phoneNumber as to for Zammad compatibility',
|
||||
});
|
||||
|
||||
const primaryMessage = {
|
||||
token: id,
|
||||
to: phoneNumber,
|
||||
to: toRecipient,
|
||||
from: source,
|
||||
messageId: `${sourceUuid}-${rawTimestamp}`,
|
||||
message: dataMessage?.message,
|
||||
|
|
@ -74,6 +104,8 @@ const processMessage = async ({
|
|||
filename: primaryAttachment.filename,
|
||||
mimeType: primaryAttachment.mimeType,
|
||||
isGroup,
|
||||
// Include groupId if this is a group message
|
||||
...(isGroup && groupId ? { groupId } : {}),
|
||||
};
|
||||
const formattedMessages = [primaryMessage];
|
||||
|
||||
|
|
@ -125,6 +157,8 @@ const fetchSignalMessagesTask = async ({
|
|||
number: phoneNumber,
|
||||
});
|
||||
|
||||
console.log(`[fetch-signal-messages] Fetching messages for bot ${id} (${phoneNumber})`);
|
||||
|
||||
for (const message of messages) {
|
||||
const formattedMessages = await processMessage({
|
||||
id,
|
||||
|
|
@ -133,6 +167,15 @@ const fetchSignalMessagesTask = async ({
|
|||
});
|
||||
for (const formattedMessage of formattedMessages) {
|
||||
if (formattedMessage.to !== formattedMessage.from) {
|
||||
console.log(`[fetch-signal-messages] Creating job for message:`, {
|
||||
messageId: formattedMessage.messageId,
|
||||
from: formattedMessage.from,
|
||||
to: formattedMessage.to,
|
||||
isGroup: formattedMessage.isGroup,
|
||||
hasMessage: !!formattedMessage.message,
|
||||
hasAttachment: !!formattedMessage.attachment,
|
||||
});
|
||||
|
||||
await worker.addJob(
|
||||
"signal/receive-signal-message",
|
||||
formattedMessage,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue