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

Delete Bot Message

We can use the sendMessage method to delete a message sent by the bot. This method has the following signature:

(property) sendMessage: (jid: string, content: AnyMessageContent, options?: MiscMessageGenerationOptions) => Promise<proto.WebMessageInfo>

app.ts

import { createBot, createProvider, createFlow, addKeyword, EVENTS } from '@builderbot/bot'
import { BaileysProvider as Provider } from '@builderbot/provider-baileys'
import { MemoryDB as Database } from '@builderbot/bot'
import { config } from 'dotenv'
config()

const PHONE_NUMBER = process.env.PHONE_NUMBER

const waitT = (ms: number) => {
    return new Promise((resolve) => {
        setTimeout(() => {
            resolve(ms)
        }, ms)
    })
}

const welcomeFlow = addKeyword<Provider, Database>(EVENTS.WELCOME)
    .addAnswer(`💡 Example delete Message`)
    .addAction(
        async (ctx, { provider, flowDynamic }) => {
            const number = ctx.key.remoteJid
            await provider.vendor.sendMessage(number, { text: `Next message is going to be deleted in 5 seconds.\n\n*${Date()}*` })
            const msg = await provider.vendor.sendMessage(number, { text: `This is the message to be deleted!!! ` })
            await waitT(5000)
            await provider.vendor.sendMessage(number, { delete: msg.key })
            await flowDynamic(`*${Date()}*\n\nMessage has been deleted!`)
        }
    )

const main = async () => {
    const adapterFlow = createFlow([welcomeFlow])
    const adapterProvider = createProvider(Provider, { usePairingCode: true, phoneNumber: PHONE_NUMBER })
    const adapterDB = new Database()
    const botResult = await createBot(
        {
            flow: adapterFlow,
            provider: adapterProvider,
            database: adapterDB,
        }
    )
}

main()
API Call Example API Call Example

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.