Files
simplex-chat/apps/simplex-support-bot/test/__mocks__/simplex-chat.js
T
sh 8841c73fb2 support bot, simplex-chat-nodejs: fix bot command parsing (#6964)
ciBotCommand's regex was unanchored, so a customer message like
"follow/read blog posts?" parsed as a /read command and the Grok
handler silently dropped the message. Anchor the regex with ^ so a
command requires `/` at the start of the (trimmed) message.

In the support bot, filter customer command parsing by the registered
keyword set: any unknown `/word` from a customer (e.g. /help) is now
routed as plain text instead of being silently dropped by Grok. This
also makes /grok when Grok is disabled behave consistently as text,
removing the previous ad-hoc workaround.
2026-05-12 09:52:50 +01:00

37 lines
968 B
JavaScript

// Mock for simplex-chat — prevents native addon from loading
function ciContentText(chatItem) {
const c = chatItem.content
if (c.type === "sndMsgContent" || c.type === "rcvMsgContent") return c.msgContent.text
return undefined
}
function ciBotCommand(chatItem) {
const text = ciContentText(chatItem)?.trim()
if (text) {
const r = text.match(/^\/([^\s]+)(.*)/)
if (r && r.length >= 3) return {keyword: r[1], params: r[2].trim()}
}
return undefined
}
function contactAddressStr(link) {
return link.connShortLink || link.connFullLink
}
// Mirrors core.ChatAPIError so isChatNotFound's instanceof check passes when
// MockChatApi throws. Tests should construct these directly.
class ChatAPIError extends Error {
constructor(message, chatError) {
super(message)
this.chatError = chatError
}
}
module.exports = {
api: {ChatApi: {}},
bot: {},
core: {ChatAPIError},
util: {ciContentText, ciBotCommand, contactAddressStr},
}