Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions gateway/platforms/whatsapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1381,6 +1381,8 @@ async def _build_message_event(self, data: Dict[str, Any]) -> Optional[MessageEv
message_id=data.get("messageId"),
media_urls=cached_urls,
media_types=media_types,
reply_to_message_id=data.get("quotedMessageId"),
reply_to_text=data.get("quotedText"),
)
except Exception as e:
print(f"[{self.name}] Error building event: {e}")
Expand Down
15 changes: 15 additions & 0 deletions scripts/whatsapp-bridge/bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,19 @@ function getContextInfo(messageContent) {
return {};
}

// Extract a text snippet from a quoted (replied-to) message so the gateway
// can inject reply context into the agent prompt.
function getQuotedText(contextInfo) {
const quoted = contextInfo?.quotedMessage;
if (!quoted || typeof quoted !== 'object') return null;
if (quoted.conversation) return quoted.conversation;
if (quoted.extendedTextMessage?.text) return quoted.extendedTextMessage.text;
if (quoted.imageMessage) return quoted.imageMessage.caption || '[image]';
if (quoted.videoMessage) return quoted.videoMessage.caption || '[video]';
if (quoted.documentMessage) return quoted.documentMessage.caption || quoted.documentMessage.fileName || '[document]';
return null;
}

mkdirSync(SESSION_DIR, { recursive: true });

// Build LID → phone reverse map from session files (lid-mapping-{phone}.json)
Expand Down Expand Up @@ -321,6 +334,7 @@ async function startSocket() {
const quotedParticipant = normalizeWhatsAppId(contextInfo?.participant || '') || null;
const quotedRemoteJid = normalizeWhatsAppId(contextInfo?.remoteJid || '') || null;
const hasQuotedMessage = !!contextInfo?.quotedMessage;
const quotedText = getQuotedText(contextInfo);

// Extract message body
let body = '';
Expand Down Expand Up @@ -436,6 +450,7 @@ async function startSocket() {
quotedParticipant,
quotedRemoteJid,
hasQuotedMessage,
quotedText,
botIds,
timestamp: msg.messageTimestamp,
};
Expand Down