πŸš€ Β‘Nuevo! builderbot cloud para No-code Β‘PruΓ©balo gratis!

Modularize Flows

Issue

My application grew so large that I was having trouble maintaining it and the code was becoming spaghetti code.


Possible Solution

As our projects grow we will need to implement a better way to maintain the project, in this case it is highly recommended to implement a module view.

In the following example we will show how we have migrated the modules to a directory, as well as the provider and the database.

  import { createBot } from '@builderbot/bot';
  import { flow } from "./flow";
  import { database } from "./database";
  import { provider } from "./provider";
  import { ai } from "./services/ai";

  const main = async () => {
  await createBot({
          flow,
          provider,
          database,
      },
          extensions: {
          ai // Dependency AI 
      })

  provider.initHttpServer(3000)
}
main()

An example of the scaffolding you can use in your project. Or a more user friendly folder structure.

structure

src
β”œβ”€β”€ app.ts
β”œβ”€β”€ database
β”‚   └── index.ts
β”œβ”€β”€ flow
β”‚   β”œβ”€β”€ index.ts
β”‚   └── welcome.flow.ts
β”‚   └── bye.flow.ts
β”‚   └── media.flow.ts
β”œβ”€β”€ provider
β”‚   └── index.ts
└── services
    └── ai.ts

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.