UNPKG

n8n-nodes-zalo-nnt

Version:

Unofficial Zalo integration for n8n - Send messages, manage groups, user operations with QR login. No API key required, works via browser simulation.

78 lines (75 loc) 2.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseMentionsFromText = parseMentionsFromText; exports.getMentionSyntaxGuide = getMentionSyntaxGuide; function parseMentionsFromText(text) { if (!text || typeof text !== 'string') { return { plainText: text || '', mentions: [] }; } const mentions = []; let result = text; let offset = 0; const uidOnlyPattern = /@\[(\d+)\]/g; let match; while ((match = uidOnlyPattern.exec(text)) !== null) { const fullMatch = match[0]; const uid = match[1]; const replacement = '@user'; const originalPos = match.index; const adjustedPos = originalPos - offset; mentions.push({ uid: uid, pos: adjustedPos, len: replacement.length, }); offset += fullMatch.length - replacement.length; } result = result.replace(uidOnlyPattern, '@user'); text = result; const allPattern = /@all\b/gi; const allMentions = []; while ((match = allPattern.exec(text)) !== null) { const originalPos = match.index; const isAlreadyMentioned = mentions.some((m) => originalPos >= m.pos && originalPos < m.pos + m.len); if (!isAlreadyMentioned) { allMentions.push({ uid: '-1', pos: originalPos, len: 4, }); } } mentions.push(...allMentions); mentions.sort((a, b) => a.pos - b.pos); const finalMentions = recalculatePositions(result, mentions); return { plainText: result, mentions: finalMentions, }; } function recalculatePositions(text, mentions) { return mentions.filter((mention) => { if (mention.pos < 0 || mention.pos + mention.len > text.length) { return false; } if (!mention.uid || mention.uid.trim() === '') { return false; } return true; }); } function getMentionSyntaxGuide() { return ` Mention Syntax Guide: 1. Mention by User ID: @[uid] → Displays as "@user" Example: @[2234791809511721207] Hello! 2. Mention Everyone: @all → Mentions all group members Example: @all Please check this! Notes: - Mentions only work in GROUP chats (not 1-on-1) - You can combine multiple mentions in one message `.trim(); } //# sourceMappingURL=mentionParser.js.map