Skip to main content
The Instagram provider enables building chatbots for Instagram Direct Messages, allowing automated conversations with your Instagram followers.

Features

  • Direct message support
  • Text messaging
  • Media sharing
  • Story replies
  • Quick replies
  • Webhook integration
  • Business account integration

Prerequisites

1

Instagram Business Account

Convert your Instagram account to a Business account
2

Link Facebook Page

Link your Instagram Business account to a Facebook Page
3

Create Facebook App

Set up a Facebook App in Meta Developer Portal
4

Get Credentials

Obtain:
  • Page Access Token
  • Instagram Account ID
  • Verify Token

Installation

npm install @builderbot/bot @builderbot/provider-instagram

Configuration

Basic Setup

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

const provider = createProvider(InstagramProvider, {
  pageAccessToken: 'YOUR_PAGE_ACCESS_TOKEN',
  instagramAccountId: 'YOUR_INSTAGRAM_ACCOUNT_ID',
  verifyToken: 'YOUR_VERIFY_TOKEN',
  port: 3000
})

const { handleCtx, httpServer } = await createBot({
  flow: adapterFlow,
  provider: provider,
  database: new MemoryDB(),
})

httpServer(3000)

Environment Variables

IG_PAGE_ACCESS_TOKEN=your_page_access_token
IG_ACCOUNT_ID=your_instagram_account_id
IG_VERIFY_TOKEN=your_verify_token
PORT=3000

Basic Usage

Sending Text Messages

import { addKeyword } from '@builderbot/bot'

const welcomeFlow = addKeyword(['hi', 'hello'])
  .addAnswer('Hello! Thanks for messaging us on Instagram')
  .addAnswer('How can we help?')

Sending Media

const mediaFlow = addKeyword('product')
  .addAnswer('Check out our latest product:', {
    media: 'https://example.com/product.jpg'
  })

Story Replies

Handle replies to your Instagram Stories:
const storyReplyFlow = addKeyword('STORY_REPLY')
  .addAction(async (ctx, { flowDynamic }) => {
    await flowDynamic('Thanks for replying to our story!')
  })

Webhook Configuration

Webhook Endpoints

GET  /webhook - Webhook verification
POST /webhook - Receive messages

Meta Developer Setup

  1. Go to your Facebook App Dashboard
  2. Add Instagram product
  3. Configure webhook URL: https://your-domain.com/webhook
  4. Enter verify token
  5. Subscribe to messaging events

Best Practices

  • Use Instagram Business account
  • Link to Facebook Page
  • Verify business details
  • Follow Instagram policies
  • Respect 24-hour messaging window
  • Use quick replies for engagement
  • Avoid spam behavior
  • Monitor message quality scores

Further Resources

Build docs developers (and LLMs) love