Skip to main content

Overview

The createProvider function creates an instance of a messaging platform provider (WhatsApp, Telegram, etc.) that handles the communication layer for your bot.

Function Signature

const createProvider = <T = ProviderClass, K = typeof ProviderClass.prototype.globalVendorArgs>(
  providerClass: new (args: K) => T,
  args: K = null
): T

Parameters

providerClass
ProviderClass
required
The provider class to instantiate. Import from provider-specific packages like @builderbot/provider-baileys, @builderbot/provider-twilio, etc.
args
object
Provider-specific configuration arguments. Each provider has its own configuration options.

Return Value

provider
T
Returns an instance of the specified provider class, configured and ready to use.

Usage Examples

Baileys Provider (WhatsApp)

import { createProvider } from '@builderbot/bot'
import { BaileysProvider } from '@builderbot/provider-baileys'

const adapterProvider = createProvider(BaileysProvider)

With Custom Configuration

import { createProvider } from '@builderbot/bot'
import { BaileysProvider } from '@builderbot/provider-baileys'

const adapterProvider = createProvider(BaileysProvider, {
  name: 'my-whatsapp-bot',
  writeMyself: 'none'
})

Twilio Provider

import { createProvider } from '@builderbot/bot'
import { TwilioProvider } from '@builderbot/provider-twilio'

const adapterProvider = createProvider(TwilioProvider, {
  accountSid: process.env.TWILIO_ACCOUNT_SID,
  authToken: process.env.TWILIO_AUTH_TOKEN,
  vendorNumber: process.env.TWILIO_PHONE_NUMBER,
  port: 3000
})

Meta Provider (WhatsApp Business API)

import { createProvider } from '@builderbot/bot'
import { MetaProvider } from '@builderbot/provider-meta'

const adapterProvider = createProvider(MetaProvider, {
  jwtToken: process.env.META_JWT_TOKEN,
  numberId: process.env.META_NUMBER_ID,
  verifyToken: process.env.META_VERIFY_TOKEN,
  version: 'v21.0',
  port: 3000
})

Available Providers

BuildBot supports multiple messaging platforms:
  • BaileysProvider - WhatsApp (via Baileys library)
  • TwilioProvider - WhatsApp, SMS (via Twilio)
  • MetaProvider - WhatsApp Business API
  • TelegramProvider - Telegram
  • DiscordProvider - Discord
Each provider has its own specific configuration options. Refer to the provider-specific documentation for detailed configuration.

Notes

  • The provider handles all platform-specific communication details
  • Provider configuration varies by platform - check provider-specific docs
  • Some providers require webhooks and external connectivity
  • The args parameter can be null for providers with default configurations

Build docs developers (and LLMs) love