Build Instagram DM bots with media, quick replies, reactions, and story replies.
Building for Facebook Messenger? Use the Messenger adapter instead. It connects through the Messenger Platform API and uses a Facebook Page access token.
Create a new bot
Scaffold a Next.js bot with the Instagram adapter using create-chat-sdk:
pnpm create chat-sdk@latest my-bot --adapter instagram memory -yThe generated app uses the Memory state adapter for local development. To add the adapter to an existing app, start at Install.
Install
pnpm add @chat-adapter/instagram @chat-adapter/state-memoryQuick start
The adapter auto-detects INSTAGRAM_ACCESS_TOKEN, INSTAGRAM_APP_SECRET, INSTAGRAM_VERIFY_TOKEN, INSTAGRAM_ACCOUNT_ID, and the optional INSTAGRAM_API_VERSION from the environment.
The memory state adapter keeps subscriptions and locks in process memory, which suits local development. Use Redis or PostgreSQL in production.
Platform setup
This adapter uses Instagram API with Instagram Login and
graph.instagram.com. It does not require a Facebook Page. The connected
Instagram account must be a public professional Business or Creator account;
personal and private accounts cannot use the Messaging API.
Create a Meta app
- Open the Meta App Dashboard and click Create App.
- For the use case, select Other, then click Next.
- Select the Business app type, then click Next.
- Enter the app name and contact email and finish creating the app. Connecting a verified business is required before publishing, but can be completed later under App settings > Basic.
- In the new app dashboard, find the Instagram product and click Set up.
Meta automatically adds API setup with Instagram login. Do not select
API setup with Facebook login for this adapter, because that setup uses
Facebook or Page tokens and graph.facebook.com.
Get credentials
Generate an access token for the account the bot will use:
- In the left menu, open Instagram > API setup with Instagram login.
- Under Generate access tokens, click Add account and sign in to the public Instagram professional account the bot will use.
- Once the account appears, click Generate token, sign in again, and copy
the token to
INSTAGRAM_ACCESS_TOKEN.
Tokens generated in the App Dashboard are long-lived and valid for 60 days. They are suitable for development and for accounts you own or manage. Refresh or rotate the token before it expires.
For an app that connects other businesses' accounts, configure Instagram business login and request these scopes in the login flow:
instagram_business_basicinstagram_business_manage_messages
Business Login returns a one-hour token. Exchange it server-side for a
60-day token through https://graph.instagram.com/access_token.
Next, find the Instagram professional account ID. It is not the app ID or the app-scoped user ID. Query the professional account associated with the token:
Copy the returned data[0].user_id value to INSTAGRAM_ACCOUNT_ID.
Set the remaining secrets:
- In App settings > Basic, copy the Meta app's App Secret to
INSTAGRAM_APP_SECRET. Meta uses this secret to sign webhook requests. - Choose your own random string for
INSTAGRAM_VERIFY_TOKEN. This value is only shared with Meta during webhook verification.
Configure webhooks
Deploy the GET and POST route shown above to a public HTTPS URL first, then:
- Return to Instagram > API setup with Instagram login.
- Under Configure webhooks, click Configure.
- Set Callback URL to
https://your-domain.com/api/webhooks/instagram. - Set Verify token to the same value as
INSTAGRAM_VERIFY_TOKEN, then click Save. - Click Manage and keep these fields enabled:
messages,message_reactions,messaging_postbacks, andmessaging_seen.
Configuring the callback does not subscribe an Instagram account by itself. Subscribe the account represented by the access token:
To confirm the messages webhook works, send the professional account a DM
from another Instagram account.
Prepare for production
Standard Access works for professional accounts you own or have added to the
App Dashboard. To connect accounts you do not own, complete Business
Verification and App Review for Advanced Access to
instagram_business_basic and instagram_business_manage_messages.
Request the Human Agent feature only if real support agents will use the
seven-day response window.
See Meta's current app creation guide, Business Login guide, and webhook subscription guide for dashboard changes and production review requirements.
Configuration
| Prop | Type | Default | Description |
|---|---|---|---|
accessToken? | string | Instagram access token for the Messaging API. Auto-detected from `INSTAGRAM_ACCESS_TOKEN`. | |
appSecret? | string | Meta app secret for `X-Hub-Signature-256` verification. Auto-detected from `INSTAGRAM_APP_SECRET`. | |
verifyToken? | string | Webhook verification secret. Auto-detected from `INSTAGRAM_VERIFY_TOKEN`. | |
accountId? | string | Instagram professional account ID. Auto-detected from `INSTAGRAM_ACCOUNT_ID`. | |
apiVersion? | string | "v26.0" | Optional Meta Graph API version override. Auto-detected from `INSTAGRAM_API_VERSION`. |
userName? | string | "bot" | Bot username. Defaults to the connected Instagram account username after initialization. |
logger? | Logger | ConsoleLogger | Logger used for adapter diagnostics. |
Environment variables
| Variable | Required | Description |
|---|---|---|
INSTAGRAM_ACCESS_TOKEN | Yes | Instagram access token for the Messaging API |
INSTAGRAM_APP_SECRET | Yes | Meta app secret used to verify webhook signatures |
INSTAGRAM_VERIFY_TOKEN | Yes | Your chosen secret for the webhook verification handshake |
INSTAGRAM_ACCOUNT_ID | Yes | Instagram professional account ID |
INSTAGRAM_API_VERSION | No | Graph API version override. Defaults to v26.0 |
Webhooks
The route handles two kinds of request from Meta:
- GET verification handshake: Meta sends a
hub.verify_tokenchallenge that must matchINSTAGRAM_VERIFY_TOKEN. - POST event delivery: incoming messages, quick-reply taps, reactions, and postbacks, signed with
X-Hub-Signature-256and verified againstINSTAGRAM_APP_SECRET.
Supported messaging
- Send and receive Instagram direct messages.
- Send images, video, audio, and files using binary data or publicly accessible HTTPS URLs.
- Render supported card buttons as Instagram quick replies. Quick-reply taps are delivered to action handlers.
- Send typing indicators while work is in progress.
- Receive reaction events through
onReaction. - Receive replies to Instagram stories as direct messages. The original webhook remains available on
message.rawwhen story-specific context is needed.
Instagram's standard messaging window lasts 24 hours after the user's most recent message. sendHumanAgentMessage uses the HUMAN_AGENT tag for human-support replies within seven days, but Meta does not allow it for automated messages and may require approval.
Thread IDs
Example: instagram:17841400000000000:1234567890.
accountId is the bot's Instagram professional account ID. userId is the user's ID as Meta sends it in the webhook's sender.id.
Limitations
Instagram does not expose message editing, so streamed responses are buffered and sent as one message when the stream completes.
Feature support
Messaging
| Feature | Supported |
|---|---|
| Post message | |
| Message replies | |
| Edit message | |
| Delete message | |
| File uploads | Uploads and HTTPS URLs |
| Streaming | Buffered |
| Scheduled messages |
Rich content
| Feature | Supported |
|---|---|
| Card format | Generic / Button Templates |
| Buttons | Quick replies / postbacks |
| Link buttons | web_url |
| Select menus | |
| Tables | |
| Charts | |
| Fields | |
| Images in cards | |
| Modals |
Conversations
| Feature | Supported |
|---|---|
| Slash commands | |
| Mentions | |
| Add reactions | |
| Remove reactions | |
| Typing indicator | |
| Mark as read | |
| Message edit events | |
| Message delete events | |
| DMs | |
| Ephemeral messages | |
| User lookup | |
| Parent subject | |
| Native client | |
| Custom API endpoint |
Message history
| Feature | Supported |
|---|---|
| Fetch messages | Cached sent only |
| Fetch single message | Cached |
| Fetch thread info | |
| Fetch channel messages | Cached |
| List threads | |
| Fetch channel info | |
| Post channel message |