BuilderBot Documentation

repository·builderbot·Indexed 25 days ago

https://github.com/codigoencasa/builderbot

An open-source library for building automated conversation flows, primarily focused on WhatsApp but remaining provider-agnostic. BuilderBot allows developers to automate responses and manage customer interactions through triggers. It includes a multi-tenant bot manager (@builderbot/manager) with a REST API, a Chatwoot integration plugin, and multiple providers including Email, Facebook Messenger, and Baileys.

Tokens
81.6K
Snippets
204
Records
392
Agent score
83%

What's inside BuilderBot

  1. Overview of BuilderBot capabilities

    builderbot

    BuilderBot is a library designed to build automated conversation flows. Key features include:

    • Provider-agnostic WhatsApp conversation flows.
    • Automated responses for frequently asked questions.
    • Automatic message receiving and responding.
    • Customer interaction tracking.
    • Extensible functionality via triggers.
  2. Understand the architecture of @builderbot/provider-voice-whatsapp

    builderbot

    The @builderbot/provider-voice-whatsapp provider uses a specialized architecture to handle voice calls via the Meta Graph API. It manages real-time audio using RTCPeerConnection and processes audio streams through several components:

    • MetaCallClient: Manages call lifecycle (pre_accept, accept, end) via Graph API.
    • Audio Processing: Uses RTCAudioSink to receive inbound Opus frames as PCM and RTCAudioSource to push TTS PCM back to the caller.
    • Speech Processing: Employs a SilenceSegmenter for utterance boundaries, an ISttAdapter (defaulting to OpenAI Whisper) for Speech-to-Text, and an ITtsAdapter (defaulting to OpenAI TTS) for Text-to-Speech.
    • Webhook Server: A polka HTTP server handles Meta hub verification (GET /webhook) and inbound call events (POST /webhook).
  3. Quickstart with create-builderbot

    builderbot

    To start a new BuilderBot project, use the create-builderbot CLI tool. This will scaffold a new project allowing you to build automated conversation flows that are agnostic to the WhatsApp provider, set up automated FAQ responses, and manage customer interactions.

    npm create builderbot@latest
  4. Configure the GupshupProvider

    builderbot

    Initialize the GupshupProvider using createProvider from @builderbot/bot. You must provide an apiKey, srcName, and phoneNumber. You can also configure detailed logging for inbound messages, status updates, and outbound errors.

    import { createProvider } from '@builderbot/bot'
    import { GupshupProvider } from '@builderbot/provider-gupshup'
    
    const adapterProvider = createProvider(GupshupProvider, {
        apiKey: 'YOUR_API_KEY',
        srcName: 'YOUR_APP_NAME',
        phoneNumber: 'YOUR_SOURCE_NUMBER',
        logs: {
            inbound: false,
            status: 'failed',
            outboundErrors: true,
            rawOnFailed: false,
        },
    })
  5. Configure the Facebook Messenger Provider

    builderbot

    Initialize the FacebookMessengerProvider by passing a configuration object to createProvider. You must provide a Facebook Page Access Token, Page ID, and a Verify Token. You can optionally specify the Facebook Graph API version and the port for the webhook server.

    import { createBot, createProvider, createFlow } from '@builderbot/bot'
    import { FacebookMessengerProvider } from '@builderbot/provider-facebook-messenger'
    
    const main = async () => {
        const provider = createProvider(FacebookMessengerProvider, {
            accessToken: 'YOUR_PAGE_ACCESS_TOKEN',
            pageId: 'YOUR_PAGE_ID',
            verifyToken: 'YOUR_VERIFY_TOKEN',
            version: 'v19.0', // optional, defaults to v19.0
            port: 3000, // optional, defaults to 3000,
        })
    
        await createBot({
            flow: createFlow([]),
            provider,
            database: // your database adapter
        })
    }
    
    main()
  6. Setup the TikTok Organic Comments Starter

    builderbot

    To set up the base-ts-tiktok-memory example, you must first build the TikTok provider from the monorepo root and then install dependencies within the starter application directory. This starter is designed for polling TikTok videos and replying publicly to comments.

    # From the monorepo root, build the provider
    pnpm --filter @builderbot/provider-tiktok build
    
    # Navigate to the starter and install dependencies
    cd starters/apps/base-ts-tiktok-memory
    pnpm install
  7. Configure Redirect URI and Webhooks

    builderbot

    Set your Redirect URI in the GHL Marketplace to point to your server's OAuth callback endpoint.

    Examples:

    • Production: https://your-domain.com/oauth/callback
    • Local development: http://localhost:3000/oauth/callback

    Webhook Setup:

    1. Use your server's webhook URL (e.g., https://your-domain.com/webhook). For local testing, use an ngrok URL.
    2. In GHL, go to Settings > Integrations > Webhooks and add a webhook.
    3. Required Event: InboundMessage (requires conversations/message.readonly scope) to receive incoming messages.
    4. Recommended Events: OutboundMessage and ConversationUnreadUpdate.