diff --git a/TODO.md b/TODO.md index 945e273..248d436 100644 --- a/TODO.md +++ b/TODO.md @@ -1,6 +1,6 @@ - [ ] Cuando Envian Sticket devuelve mensaje raro -- [ ] Posibilidad de en el capture meter todo un nuevo CTX de FLOW .addAnswer('Marca la opcion',{capture:true, join:CTX}) -- [ ] .addKeyword('1') no funciona con 1 caracter -- [ ] sensitivy viene activado por defecto +- [X] Posibilidad de en el capture meter todo un nuevo CTX de FLOW .addAnswer('Marca la opcion',{capture:true, join:CTX}) +- [X] .addKeyword('1') no funciona con 1 caracter +- [X] sensitivy viene activado por defecto - [ ] colocar mensaje esperando conectando whatsapp (provider) - [ ] fallback respuesta en hijo \ No newline at end of file diff --git a/packages/bot/io/flow.class.js b/packages/bot/io/flow.class.js index bb0d79d..5ed8eb4 100644 --- a/packages/bot/io/flow.class.js +++ b/packages/bot/io/flow.class.js @@ -26,8 +26,24 @@ class FlowClass { let refSymbol = null overFlow = overFlow ?? this.flowSerialize + const mapSensitiveString = (str, flag = false) => { + if (!flag && Array.isArray(str)) { + return str.map((c) => c.toLowerCase()) + } + + if (!flag && typeof str === 'string') { + return str.toLowerCase() + } + + return str + } + const findIn = (keyOrWord, symbol = false, flow = overFlow) => { + const sensitive = refSymbol?.options?.sensitive || false capture = refSymbol?.options?.capture || false + + keyOrWord = mapSensitiveString(keyOrWord, sensitive) + if (capture) return messages if (symbol) { @@ -35,7 +51,9 @@ class FlowClass { if (refSymbol?.answer) messages.push(refSymbol) if (refSymbol?.ref) findIn(refSymbol.ref, true) } else { - refSymbol = flow.find((c) => c.keyword.includes(keyOrWord)) + refSymbol = flow.find((c) => + mapSensitiveString(c.keyword, sensitive).includes(keyOrWord) + ) if (refSymbol?.ref) findIn(refSymbol.ref, true) return messages }