mirror of
https://github.com/cheveguerra/bot-whatsapp.git
synced 2026-04-18 11:39:15 +00:00
io improvement
This commit is contained in:
28
packages/io/methods/addAnswer.js
Normal file
28
packages/io/methods/addAnswer.js
Normal file
@@ -0,0 +1,28 @@
|
||||
const { generateRef } = require('../utils')
|
||||
|
||||
const addAnswer = (inCtx) => (message, options) => {
|
||||
const lastCtx = inCtx.hasOwnProperty('ctx') ? inCtx.ctx : inCtx
|
||||
const ctxAnswer = () => {
|
||||
const ref = generateRef()
|
||||
/**
|
||||
* Se guarda en db
|
||||
*/
|
||||
|
||||
return { ...lastCtx, ref, message }
|
||||
}
|
||||
|
||||
const ctx = ctxAnswer()
|
||||
|
||||
return {
|
||||
ctx,
|
||||
ref: ctx.ref,
|
||||
addAnswer: addAnswer(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { addAnswer }
|
||||
|
||||
// await inout
|
||||
// .addKeyword('hola')
|
||||
// .addAnswer('Bienvenido a tu tienda 🥲')
|
||||
// .addAnswer('escribe *catalogo* o *ofertas*')
|
||||
32
packages/io/methods/addKeyword.js
Normal file
32
packages/io/methods/addKeyword.js
Normal file
@@ -0,0 +1,32 @@
|
||||
const { generateRef } = require('../utils')
|
||||
const { addAnswer } = require('./addAnswer')
|
||||
/**
|
||||
* addKeyword:
|
||||
* Es necesario que genere id|hash
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {*} message `string | string[]`
|
||||
* @param {*} options {sensitivy:boolean} defaulta false
|
||||
*/
|
||||
const addKeyword = (message, options) => {
|
||||
const ctxAddKeyword = () => {
|
||||
const ref = generateRef()
|
||||
/**
|
||||
* Se guarda en db
|
||||
*/
|
||||
|
||||
return { ref, keyword: message }
|
||||
}
|
||||
|
||||
const ctx = ctxAddKeyword()
|
||||
|
||||
return {
|
||||
ctx,
|
||||
ref: ctx.ref,
|
||||
addAnswer: addAnswer(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { addKeyword }
|
||||
4
packages/io/methods/index.js
Normal file
4
packages/io/methods/index.js
Normal file
@@ -0,0 +1,4 @@
|
||||
const { addAnswer } = require('./addAnswer')
|
||||
const { addKeyword } = require('./addKeyword')
|
||||
|
||||
module.exports = { addAnswer, addKeyword }
|
||||
Reference in New Issue
Block a user