Recipes · Modularize

Edit this page on GitHub

Modularize

How to modularize flows

À medida que nossos projetos crescem, precisaremos implementar uma maneira melhor de manter o projeto, neste caso, é altamente recomendável implementar uma visão de Módulo.

No exemplo a seguir, mostraremos como migramos os módulos para um diretório, bem como o Provedor e o banco de dados.

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

Um exemplo dos andaimes que pode utilizar no seu projecto. Ou uma estrutura de pastas mais amigável.

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.