chore(bot): added new fallback option

This commit is contained in:
Leifer Mendez
2022-12-02 15:22:13 +01:00
parent 7d41699207
commit aa2417af12
5 changed files with 21 additions and 20 deletions

View File

@@ -4,7 +4,7 @@
- [ ] __(doc)__ Video explicacion de github action - [ ] __(doc)__ Video explicacion de github action
### @bot-whatsapp/bot ### @bot-whatsapp/bot
- [ ] agregar export package - [X] agregar export package
- [X] Posibilidad de en el capture meter todo un nuevo CTX de FLOW .addAnswer('Marca la opcion',{capture:true, join:CTX}) - [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] .addKeyword('1') no funciona con 1 caracter
- [X] sensitivy viene activado por defecto - [X] sensitivy viene activado por defecto
@@ -12,6 +12,7 @@
- [ ] colocar mensaje esperando conectando whatsapp (provider) - [ ] colocar mensaje esperando conectando whatsapp (provider)
- [ ] Cuando Envian Sticket devuelve mensaje raro - [ ] Cuando Envian Sticket devuelve mensaje raro
- [ ] createDatabase validar implementacion de funciones - [ ] createDatabase validar implementacion de funciones
- [ ] limitar caracteres de mensajes
### @bot-whatsapp/database ### @bot-whatsapp/database
- [X] agregar export package - [X] agregar export package
@@ -29,4 +30,8 @@
- [ ] Meta adapter - [ ] Meta adapter
### @bot-whatsapp/cli ### @bot-whatsapp/cli
- [ ] Hacer comando para crear `example-app` - [X] Hacer comando para crear `example-app`
### @bot-whatsapp/create-bot
- [ ]

View File

@@ -67,13 +67,13 @@ class CoreClass {
this.databaseClass.save(ctxByNumber) this.databaseClass.save(ctxByNumber)
} }
//Si se tiene un callback se ejecuta // 📄 [options: callback]: Si se tiene un callback se ejecuta
if (refToContinue && prevMsg?.options?.callback) { if (refToContinue && prevMsg?.options?.callback) {
const indexFlow = this.flowClass.findIndexByRef(refToContinue?.ref) const indexFlow = this.flowClass.findIndexByRef(refToContinue?.ref)
this.flowClass.allCallbacks[indexFlow].callback(messageInComming) this.flowClass.allCallbacks[indexFlow].callback(messageInComming)
} }
//Si se tiene anidaciones de flows, si tienes anidados obligatoriamente capture:true // 📄🤘(tiene return) [options: nested(array)]: Si se tiene flujos hijos los implementa
if (prevMsg?.options?.nested?.length) { if (prevMsg?.options?.nested?.length) {
const nestedRef = prevMsg.options.nested const nestedRef = prevMsg.options.nested
const flowStandalone = nestedRef.map((f) => ({ const flowStandalone = nestedRef.map((f) => ({
@@ -85,13 +85,19 @@ class CoreClass {
return return
} }
//Consultamos si se espera respuesta por parte de cliente "Ejemplo: Dime tu nombre" // 📄🤘(tiene return) [options: capture (boolean)]: Si se tiene option boolean
if (!prevMsg?.options?.nested?.length && prevMsg?.options?.capture) { if (!prevMsg?.options?.nested?.length) {
msgToSend = this.flowClass.find(refToContinue?.ref, true) || [] const typeCapture = typeof prevMsg?.options?.capture
} else { const valueCapture = prevMsg?.options?.capture
msgToSend = this.flowClass.find(body) || []
if (['string', 'boolean'].includes(typeCapture) && valueCapture) {
msgToSend = this.flowClass.find(refToContinue?.ref, true) || []
this.sendFlow(msgToSend, from)
return
}
} }
msgToSend = this.flowClass.find(body) || []
this.sendFlow(msgToSend, from) this.sendFlow(msgToSend, from)
} }

View File

@@ -1,6 +1,5 @@
const { generateRef } = require('../../utils/hash') const { generateRef } = require('../../utils/hash')
const { toJson } = require('./toJson') const { toJson } = require('./toJson')
const { toSerialize } = require('./toSerialize')
/** /**
* *
* @param answer string * @param answer string
@@ -79,6 +78,7 @@ const addAnswer =
} }
} }
/// Retornar contexto no colocar nada más abajo de esto
const ctx = ctxAnswer() const ctx = ctxAnswer()
return { return {

View File

@@ -5,11 +5,6 @@ const {
addKeyword, addKeyword,
} = require('@bot-whatsapp/bot') } = require('@bot-whatsapp/bot')
/**
* ATENCION: Si vas a usar el provider whatsapp-web.js
* recuerda ejecutar npm i whatsapp-web.js@latest
*/
const WebWhatsappProvider = require('@bot-whatsapp/provider/web-whatsapp') const WebWhatsappProvider = require('@bot-whatsapp/provider/web-whatsapp')
const MockAdapter = require('@bot-whatsapp/database/mock') const MockAdapter = require('@bot-whatsapp/database/mock')

View File

@@ -6,11 +6,6 @@ const {
addChild, addChild,
} = require('@bot-whatsapp/bot') } = require('@bot-whatsapp/bot')
/**
* ATENCION: Si vas a usar el provider whatsapp-web.js
* recuerda ejecutar npm i whatsapp-web.js@latest
*/
const WebWhatsappProvider = require('@bot-whatsapp/provider/web-whatsapp') const WebWhatsappProvider = require('@bot-whatsapp/provider/web-whatsapp')
const MockAdapter = require('@bot-whatsapp/database/mock') const MockAdapter = require('@bot-whatsapp/database/mock')