mirror of
https://github.com/cheveguerra/bot-whatsapp.git
synced 2026-04-17 19:26:23 +00:00
add answer options
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
- [x] addKeyword
|
||||
- [x] addAnswer
|
||||
- [x] addKeyword: Opciones
|
||||
- [ ] addAnswer: Opciones
|
||||
- [x] addAnswer: Opciones, media, buttons
|
||||
- [ ] Retornar SQL
|
||||
- [ ] Retornar JSON
|
||||
- [ ] Recibir JSON
|
||||
|
||||
@@ -1,6 +1,17 @@
|
||||
const { generateRef } = require('../utils')
|
||||
|
||||
/**
|
||||
*
|
||||
* @param answer string
|
||||
* @param options {media:string, buttons:[]}
|
||||
* @returns
|
||||
*/
|
||||
const addAnswer = (inCtx) => (answer, options) => {
|
||||
const getAnswerOptions = () => ({
|
||||
media: typeof options?.media === 'string' ? `${options?.media}` : null,
|
||||
buttons: Array.isArray(options?.buttons) ? options.buttons : [],
|
||||
})
|
||||
|
||||
const lastCtx = inCtx.hasOwnProperty('ctx') ? inCtx.ctx : inCtx
|
||||
const ctxAnswer = () => {
|
||||
const ref = generateRef()
|
||||
@@ -8,7 +19,12 @@ const addAnswer = (inCtx) => (answer, options) => {
|
||||
* Se guarda en db
|
||||
*/
|
||||
|
||||
return { ...lastCtx, ref, answer }
|
||||
const options = {
|
||||
answer: getAnswerOptions(),
|
||||
keyword: {},
|
||||
}
|
||||
|
||||
return { ...lastCtx, ref, answer, options }
|
||||
}
|
||||
|
||||
const ctx = ctxAnswer()
|
||||
@@ -21,8 +37,3 @@ const addAnswer = (inCtx) => (answer, options) => {
|
||||
}
|
||||
|
||||
module.exports = { addAnswer }
|
||||
|
||||
// await inout
|
||||
// .addKeyword('hola')
|
||||
// .addAnswer('Bienvenido a tu tienda 🥲')
|
||||
// .addAnswer('escribe *catalogo* o *ofertas*')
|
||||
|
||||
@@ -53,4 +53,26 @@ test('Debere probar las poptions', () => {
|
||||
assert.is(MAIN_CTX.ctx.options.sensitive, false)
|
||||
})
|
||||
|
||||
test('Debere probar las addAnswer', () => {
|
||||
const MOCK_OPT = {
|
||||
media: 'http://image.mock/mock.png',
|
||||
buttons: [1],
|
||||
}
|
||||
const MAIN_CTX = addKeyword('hola').addAnswer('etc', MOCK_OPT)
|
||||
|
||||
assert.is(MAIN_CTX.ctx.options.answer.media, MOCK_OPT.media)
|
||||
assert.is(MAIN_CTX.ctx.options.answer.buttons.length, 1)
|
||||
})
|
||||
|
||||
test('Debere probar error las addAnswer', () => {
|
||||
const MOCK_OPT = {
|
||||
media: { a: 1, b: [] },
|
||||
buttons: 'test',
|
||||
}
|
||||
const MAIN_CTX = addKeyword('hola').addAnswer('etc', MOCK_OPT)
|
||||
|
||||
assert.is(MAIN_CTX.ctx.options.answer.media, null)
|
||||
assert.is(MAIN_CTX.ctx.options.answer.buttons.length, 0)
|
||||
})
|
||||
|
||||
test.run()
|
||||
|
||||
Reference in New Issue
Block a user