Skip to main content

Overview

The createBot function creates and initializes a bot instance with the specified provider, database, and conversation flows.

Function Signature

const createBot = async <P extends ProviderClass = any, D extends MemoryDB = any>(
  { flow, database, provider }: { 
    flow: FlowClass; 
    database: D; 
    provider: P 
  },
  args?: Omit<GeneralArgs, 'listEvents'>
): Promise<CoreClass<P, D>>

Parameters

flow
FlowClass
required
The conversation flow instance created with createFlow(). Contains all the conversation logic and flows for your bot.
database
MemoryDB
required
The database adapter instance for storing conversation state and user data.
provider
ProviderClass
required
The messaging platform provider instance created with createProvider().
args
object
Optional configuration arguments for the bot instance.

Return Value

bot
Promise<CoreClass<P, D>>
Returns a Promise that resolves to the initialized bot instance with full functionality.

Usage Examples

import { createBot, createFlow, createProvider, MemoryDB } from '@builderbot/bot'
import { BaileysProvider } from '@builderbot/provider-baileys'

const main = async () => {
  const adapterDB = new MemoryDB()
  const adapterFlow = createFlow([])
  const adapterProvider = createProvider(BaileysProvider)

  const bot = await createBot({
    flow: adapterFlow,
    database: adapterDB,
    provider: adapterProvider
  })

  // Bot is now ready
}

main()

With Custom Configuration

import { createBot, createFlow, createProvider, MemoryDB } from '@builderbot/bot'
import { BaileysProvider } from '@builderbot/provider-baileys'

const main = async () => {
  const adapterDB = new MemoryDB()
  const adapterFlow = createFlow([])
  const adapterProvider = createProvider(BaileysProvider)

  const bot = await createBot(
    {
      flow: adapterFlow,
      database: adapterDB,
      provider: adapterProvider
    },
    {
      blackList: ['+1234567890'],
      delay: 1000,
      globalState: {
        apiKey: process.env.API_KEY,
        adminNumbers: ['+1987654321']
      },
      queue: {
        timeout: 60000,
        concurrencyLimit: 20
      }
    }
  )

  // Bot is now ready with custom configuration
}

main()

Build docs developers (and LLMs) love