Sensitive case

This commit is contained in:
Leifer Mendez
2022-11-24 14:52:57 +01:00
parent 14fbae3c86
commit b6a21b9c12
2 changed files with 22 additions and 4 deletions

View File

@@ -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

View File

@@ -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
}