Recipes · Modularize

Edit this page on GitHub

Modularize

How to modularize flows

A medida que nuestros proyectos crezcan, necesitaremos implementar una mejor manera de mantener el proyecto, en este caso es muy recomendable implementar una vista de módulo.

En el siguiente ejemplo mostraremos cómo hemos migrado los módulos a un directorio, así como el proveedor y la base de datos.

  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()

Un ejemplo del andamio que puede utilizar en su proyecto. O una estructura de carpetas más amigable para el usuario.

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.