🚀 ¡Nuevo! builderbot cloud para No-code ¡Pruébalo gratis!

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()

Guides

My first chatbot

Learn how build your first chatbot in few minutes

Read more

Concepts

Understand the essential concepts for building bots

Read more

Add Functions

The key to learning how to write flows is add-functions.

Read more

Plugins

Unlimitate and start implementing the community plugins.

Read more

Resources

Modularize

Learn how to modularise flows so that you can have a more maintainable bot.

Send Message

How to send a message via HTTP to start conversations, you can send multimedia as well.

Dockerizer

A good practice is to dockerise your bots to make them more maintainable and effective.

Events

Learning about events will make us more fluent when creating chatbots.