Skip to content

Commit

Permalink
feat(bot): ✨ feat
Browse files Browse the repository at this point in the history
  • Loading branch information
leifermendez committed Mar 4, 2023
1 parent 9f02ed5 commit d3f86db
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/bot/core/core.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ class CoreClass {
let fallBackFlag = false
if (this.generalArgs.blackList.includes(from)) return
if (!body) return
if (!body.length) return

let prevMsg = await this.databaseClass.getPrevByNumber(from)
const refToContinue = this.flowClass.findBySerialize(prevMsg?.refSerialize)
Expand Down Expand Up @@ -302,8 +301,12 @@ class CoreClass {
*/
sendProviderAndSave = async (numberOrId, ctxMessage) => {
const { answer } = ctxMessage
await this.providerClass.sendMessage(numberOrId, answer, ctxMessage)
await this.databaseClass.save({ ...ctxMessage, from: numberOrId })

if (answer && answer.length && answer !== '__call_action__') {
await this.providerClass.sendMessage(numberOrId, answer, ctxMessage)
await this.databaseClass.save({ ...ctxMessage, from: numberOrId })
}

return
}

Expand Down
3 changes: 3 additions & 0 deletions packages/bot/io/methods/addAction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const addAction = () => async () => {}

module.exports = { addAction }
2 changes: 2 additions & 0 deletions packages/bot/io/methods/addAnswer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { flatObject } = require('../../utils/flattener')
const { generateRef } = require('../../utils/hash')
const { addAction } = require('./addAction')
const { addChild } = require('./addChild')
const { toJson } = require('./toJson')
/**
Expand Down Expand Up @@ -98,6 +99,7 @@ const addAnswer =
ctx,
ref: ctx.ref,
addAnswer: addAnswer(ctx),
addAction: (cb = () => null) => addAnswer(ctx)('__call_action__', null, cb),
toJson: toJson(ctx),
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/bot/io/methods/addKeyword.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const addKeyword = (keyword, options) => {
ctx,
ref: ctx.ref,
addAnswer: addAnswer(ctx),
addAction: (cb = () => null) => addAnswer(ctx)('__call_action__', null, cb),
toJson: toJson(ctx),
}
}
Expand Down

0 comments on commit d3f86db

Please # to comment.