Forward conversation to human
Issue
I need to be able to stop the bot to continue the conversation with one person but still allow other people to see it.
Possible Solution
In this example let's imagine that the bot number is ADMIN_NUMBER
the idea is that if a user writes me the bot will answer this is correct, but
I want to pause the bot for that user, what I do is write to my own number from the whatsapp with a phrase Mute +34000000
assuming that the number
of the user I want to pause is +34000000
and the logic I perform is to clean characters to only get
34000000
and check if it exists in a blackList if it is not found I add it in this way the bot stops responding to that
user and I can continue talking to the person and when I want to reactivate the bot for this person I write again Mute +34000000
and if it is found it removes it from the blacklist is basically a switch.
import { createBot, createProvider, createFlow, addKeyword, utils } from '@builderbot/bot'
import { MemoryDB as Database } from '@builderbot/bot'
import { BaileysProvider as Provider } from '@builderbot/provider-baileys'
import { numberClean } from './utils'
const PORT = process.env.PORT ?? 3008
const ADMIN_NUMBER = process.env.ADMIN_NUMBER
const blackListFlow = addKeyword<Provider, Database>('mute')
.addAction(async (ctx, { blacklist, flowDynamic }) => {
if (ctx.from === ADMIN_NUMBER) {
const toMute = numberClean(ctx.body) //Mute +34000000 message incoming
const check = blacklist.checkIf(toMute)
if (!check) {
blacklist.add(toMute)
await flowDynamic(`❌ ${toMute} muted`)
return
}
blacklist.remove(toMute)
await flowDynamic(`🆗 ${toMute} unmuted`)
return
}
})
const fullSamplesFlow = addKeyword<Provider, Database>(['samples', utils.setEvent('SAMPLES')])
.addAnswer(`💪 I'll send you a lot files...`)
const main = async () => {
const adapterFlow = createFlow([fullSamplesFlow, blackListFlow])
const adapterProvider = createProvider(Provider)
const adapterDB = new Database()
const { httpServer } = await createBot({
flow: adapterFlow,
provider: adapterProvider,
database: adapterDB,
})
httpServer(+PORT)
}
main()