Tutorials · Migrate from bot-whatsapp
Edit this page on GitHubMigrating 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
- Name Change: From bot-whatsapp to builderbot
- Enhanced Language Support: Now includes TypeScript in addition to JavaScript
- 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@latestInstall Your Preferred Provider
Choose and install the provider you're using:
pnpm install @builderbot/provider-baileys@latestUpdate 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 builderbotUpdate 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
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.