Why BuilderBot?
BuilderBot is the framework for the creation of ChatBots focused on low-frequency communication channels, whatsapp, telegram, etc. We implement an architecture focused on improving the developer experience and the reuse of logic at all times, if you need to create chatbots for whatsapp quickly, without limits and easy connection between different providers then BuilderBot is for you.
The library is based on three key components for its correct functioning: the Flow, in charge of building the context of the conversation and offering a friendly interface to the developer; the Provider, which acts as a connector allowing to easily switch between WhatsApp providers without the risk of affecting other parts of the bot; and the Database, which in line with this connector philosophy, facilitates changing the data persistence layer without the need to rewrite the workflow.
Flow
Refers to creating structured sequences of interactions, as in building conversation flows. Two key methods are addKeyword and addAnswer, which allow keywords to be associated with specific responses, providing options for customizing the conversation flow.
Keywords are the words you will use to start the flow, you can use a single word or a list of words. Example "hello", "good morning".
import { addKeyword } from '@builderbot/bot'
addKeyword(['hello','hi']).addAnswer('Ey! welcome')
Some examples of how to use the addKeyword in which you can place the keyword or a list of keywords that will be used to start a conversational flow
// Example with single keyword
addKeyword('hello').addAnswer('Ey! welcome')
// Example with multi keywords
addKeyword(['hello','hi']).addAnswer('Ey! welcome')
For a quick understanding of the operation we have prepared a basic example of how to implement
Provider
It is a key piece used to deliver the message to the chosen supplier. In a case you are building a bot for whatsapp you should use an adapter like Meta, Twilio, Baileys, etc or even if you want to connect to Telegram.
import { addKeyword, MemoryDB, createProvider, createFlow } from '@builderbot/bot'
import { BaileysProvider } from '@builderbot/provider-baileys'
// ...stuff code...
const main = async () => {
await createBot({
database: new MemoryDB(),
provider: createProvider(BaileysProvider),
flow: createFlow([flowDemo])
})
}
main()
Database
Just as providers can be easily exchanged between adapters, we can do the same with the database. Now the important thing to understand is how it works. The main purpose of the database inside the bot is to provide the bot with a record of the different events that have occurred between different conversations.
It is ready to implement adapters from Mongo, MySQL, Postgres, among others.
import { addKeyword, MemoryDB, createProvider, createFlow } from '@builderbot/bot'
import { BaileysProvider } from '@builderbot/provider-baileys'
// ...stuff code...
const main = async () => {
await createBot({
database: new MemoryDB(),
provider: createProvider(BaileysProvider),
flow: createFlow([flowDemo])
})
}
main()