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

Migrating from bot-whatsapp to builderbot: A Simple Guide

builderbot is the next evolution of bot-whatsapp, maintaining 99% compatibility while introducing significant improvements. This guide will walk you through the straightforward migration process.

Key Differences

  1. Name Change: From bot-whatsapp to builderbot
  2. Enhanced Language Support: Now includes TypeScript in addition to JavaScript
  3. Improved Features: New functionalities while maintaining familiar concepts

Easy Migration Steps

Update Dependencies

First, install the latest builderbot core:

npm install @builderbot/bot@latest
# or
pnpm add @builderbot/bot@latest

Install Your Preferred Provider

Choose and install the provider you're using:

pnpm install @builderbot/provider-baileys@latest

Update Imports

Modify your imports to use builderbot:

// Old
const { createBot, createProvider, createFlow, addKeyword } = require('@bot-whatsapp/bot')

// New
const { createBot, createProvider, createFlow, addKeyword, MemoryDB } = require('@builderbot/bot')

Update Provider

Change the provider import and initialization:

// Old
const WebWhatsappProvider = require('@bot-whatsapp/provider/web-whatsapp')

// New
const { BaileysProvider } = require('@builderbot/bot')

// When initializing:
const adapterProvider = createProvider(BaileysProvider)
adapterProvider.initHttpServer(3000) // New feature in builderbot

Update Database

Update your database adapter:

// Old
const MockAdapter = require('@bot-whatsapp/database/mock')
const adapterDB = new MockAdapter()

// New
const { MemoryDB } = require('@builderbot/bot')
const adapterDB = new MemoryDB()

Review and Update Flows

While most of your flows will work as-is, consider using new features like addAction for more complex logic:

const infoFlow = addKeyword('info')
    .addAction(async (ctx, { flowDynamix }) => {
        await flowDynamix(`Welcome ${ctx.name}`)
    })

Code Comparison

Here's a side-by-side comparison of a basic bot setup in bot-whatsapp and builderbot:

const { createBot, createProvider, createFlow, addKeyword } = require('@bot-whatsapp/bot')

const BaileysProvider = require('@bot-whatsapp/provider/baileys')
const MockAdapter = require('@bot-whatsapp/database/mock')

const flowPrincipal = addKeyword(['hola', 'alo'])
    .addAnswer(['Hola, bienvenido a mi tienda', '¿Como puedo ayudarte?'])
    .addAnswer(['Tengo:', 'Zapatos', 'Bolsos', 'etc ...'])

const main = async () => {
    const adapterDB = new MockAdapter()
    const adapterFlow = createFlow([flowPrincipal])
    const adapterProvider = createProvider(BaileysProvider)
    createBot({
        flow: adapterFlow,
        provider: adapterProvider,
        database: adapterDB,
    })
}

main()

Final Considerations

  • Migration should be relatively straightforward due to high compatibility
  • Take advantage of new builderbot features, especially if you opt to use TypeScript
  • Maintain your existing development practices and patterns, as they remain valid

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.