Dialogflow Instagram Integration: 3 Ways to Connect a Bot
A Dialogflow Instagram integration has to be built through Meta's Instagram Messaging API, because Dialogflow has no native connector. A no-code tool, a middleware flow, or your own webhook relays each DM to detectIntent and sends the answer back.
- Neither Dialogflow ES nor CX has an Instagram connector, so every route ends in a call to detectIntent plus a call to Meta's Send API.
- Meta App Review for the messaging permission is usually the slowest step, so start it before you build the full bot.
- Use the sender's IGSID as the Dialogflow session ID so context and CX pages persist across messages.
- Replies only work inside the 24-hour window after the user's last message, and one text message is capped at 1000 bytes.
- Verify X-Hub-Signature-256 on every POST, and ignore echo events, or your bot will answer itself.
Why is there no Dialogflow Instagram integration?
The Dialogflow console lists one-click integrations such as Messenger, Telegram, Slack and Twilio, but Instagram is not among them. Instagram DMs are delivered only through Meta's Instagram Messaging API, which requires your own Meta app, permissions and review.
So the pattern is always the same. Meta posts a webhook to a server you control, the server calls Dialogflow's detectIntent with the user's text, and the server sends the answer back with the Send API. The three routes differ only in who runs that server.
| Route | Who runs the relay | Typical effort | Dialogflow compatibility | Best for |
|---|---|---|---|---|
| 1. No-code platform (ManyChat, Chatfuel, Botpress, Landbot, Voiceflow) | The platform | Hours | Usually replaces Dialogflow; some can call it through an HTTP request step | Marketers and small businesses |
| 2. Middleware (Make, n8n, Zapier, Pipedream) | The automation tool | Half a day to 2 days | Calls detectIntent through an HTTP module with a Google token | Existing Dialogflow agents, light traffic |
| 3. Custom webhook | Your own server | 2 to 5 days plus review | Full: ES or CX, any region, fulfillment logic | Developers, strict data control |
What do you need before connecting Dialogflow to Instagram DMs?
These prerequisites apply to routes 2 and 3. The platforms in route 1 handle most of them for you.
- Convert the Instagram account to a Professional account (Business or Creator) in the app settings.
- Link it to a Facebook Page, or use the newer Instagram Login flow, which does not need a Page.
- In the Instagram app, open Settings, then Messages and story replies, then Message controls, and turn on 'Allow access to messages' for connected tools.
- Create a Meta developer app, add the Instagram product, and note the app ID and app secret.
- Complete Meta Business verification and App Review for the messaging permission: instagram_manage_messages with Facebook Login, or instagram_business_manage_messages with Instagram Login.
- Create a Google Cloud project with a Dialogflow agent and a service account holding the Dialogflow API Client role.
How do I build an Instagram chatbot without coding?
ManyChat, Chatfuel, Botpress, Landbot and Voiceflow connect to Instagram through their own approved Meta apps. You authorize your account, build flows visually and go live without your own App Review.
The trade-off is that most of them replace Dialogflow instead of wrapping it. ManyChat versus Dialogflow is not a like-for-like choice: ManyChat is a marketing tool with Instagram built in, while Dialogflow is an NLU engine with no channel. If you must keep a Dialogflow agent, pick a tool with an HTTP step, such as Botpress or ManyChat's external request block.
Make, n8n and Zapier sit in between. They can receive Meta's webhook, but you still need your own Meta app, so review still applies. A typical scenario has four modules:
- Webhook trigger: give Meta this URL as the callback. Meta's GET verification must return hub.challenge, so use a webhook node that can respond with a custom body.
- Filter: continue only if the event has message.text and is not message.is_echo.
- HTTP request to Dialogflow: POST to the detectIntent URL with an OAuth bearer token from the service account. Tokens expire after about an hour, so use the tool's Google credential feature instead of pasting a token.
- HTTP request to Meta: POST the reply text to the Send API with the sender ID as recipient.
How do I build an Instagram chatbot with a webhook and Dialogflow?
Set the callback URL and verify token in the app dashboard, subscribe to the 'messages' webhook field, handle the GET handshake, validate each POST, call detectIntent with the sender ID as the session, and reply. The example uses Flask and Dialogflow CX. For ES, swap the client and the session path. Confirm the current Graph API version and permission names in Meta's docs before publishing.
import os, hmac, hashlib, requests
from flask import Flask, request, abort
from google.cloud.dialogflowcx_v3 import SessionsClient
from google.cloud.dialogflowcx_v3.types import (
DetectIntentRequest, QueryInput, TextInput)
from google.api_core.client_options import ClientOptions
app = Flask(__name__)
VERIFY_TOKEN = os.environ["VERIFY_TOKEN"]
APP_SECRET = os.environ["APP_SECRET"].encode()
IG_TOKEN = os.environ["IG_ACCESS_TOKEN"] # long-lived
PROJECT, LOCATION, AGENT = "my-project", "us-central1", "AGENT_ID"
GRAPH = "https://graph.instagram.com/v23.0/me/messages" # check current version
# Global agents use dialogflow.googleapis.com (no prefix);
# regional agents use <location>-dialogflow.googleapis.com.
ENDPOINT = ("dialogflow.googleapis.com" if LOCATION == "global"
else f"{LOCATION}-dialogflow.googleapis.com")
client = SessionsClient(client_options=ClientOptions(api_endpoint=ENDPOINT))
@app.get("/webhook")
def verify():
if (request.args.get("hub.mode") == "subscribe" and
request.args.get("hub.verify_token") == VERIFY_TOKEN):
return request.args["hub.challenge"], 200
abort(403)
@app.post("/webhook")
def receive():
raw = request.get_data()
sig = request.headers.get("X-Hub-Signature-256", "")
expected = "sha256=" + hmac.new(APP_SECRET, raw, hashlib.sha256).hexdigest()
if not hmac.compare_digest(sig, expected):
abort(403)
for entry in request.json.get("entry", []):
for ev in entry.get("messaging", []):
msg = ev.get("message", {})
if msg.get("is_echo") or "text" not in msg:
continue
sender = ev["sender"]["id"] # IGSID
reply = ask_dialogflow(sender, msg["text"])
send(sender, reply)
return "ok", 200 # answer fast, Meta retries on failure
def ask_dialogflow(session_id, text):
path = client.session_path(PROJECT, LOCATION, AGENT, session_id)
req = DetectIntentRequest(session=path, query_input=QueryInput(
text=TextInput(text=text), language_code="en"))
resp = client.detect_intent(request=req)
texts = [t for m in resp.query_result.response_messages
for t in m.text.text]
return " ".join(texts) or "Sorry, I did not get that."
def send(recipient, text):
text = text.encode()[:1000].decode(errors="ignore") # 1000 byte cap
r = requests.post(GRAPH, json={
"recipient": {"id": recipient},
"message": {"text": text}},
headers={"Authorization": f"Bearer {IG_TOKEN}"}, timeout=10)
r.raise_for_status()How do Dialogflow auth, regions and sessions work here?
Authenticate with a service account. Use its JSON key only for local work, via GOOGLE_APPLICATION_CREDENTIALS, and never commit it. On Cloud Run or Cloud Functions, attach the service account to the service so no key file exists.
A CX agent lives in one location, such as us-central1 or global, and the client must use that location's endpoint. For a regional agent the endpoint is LOCATION-dialogflow.googleapis.com, for example us-central1-dialogflow.googleapis.com. For the global location the endpoint is plain dialogflow.googleapis.com with no prefix; there is no global-dialogflow.googleapis.com host. A mismatch returns a 'not found' or 'wrong location' error even when the agent ID is right.
The session ID gives the bot memory. With the sender's IGSID, each user keeps their own contexts (ES) or current page and parameters (CX). The Dialogflow ES docs give the default context lifespan as 20 minutes (or 5 requests), after which a context expires, so store anything important in your own database.
What are the limits and policies for Instagram bots?
Most failures after launch come from the messaging policy, not from code. Design around these rules.
| Rule | Detail | What to do |
|---|---|---|
| User must message first | You cannot start a conversation with a cold DM | Use ads, story replies or comment triggers to prompt the user |
| 24-hour window | You can reply only within 24 hours of the user's last message | Resolve the request inside the window |
| Human agent tag | Extends replies to 7 days for human support only | Use for staff follow-ups, never for automated marketing |
| Text length | 1000 bytes per text message | Truncate or split; emoji and non-Latin text use more bytes than characters |
| Rich replies | Quick replies, templates and buttons, with limits on count and label length | Map Dialogflow custom payloads to Meta's message JSON |
| Automation disclosure | Meta expects people to know they are talking to an automated system and to be able to reach a human | Add a welcome line and a 'talk to a person' intent |
How do I test and fix a bot that is not working?
For local development, run the Flask app and expose it with ngrok (ngrok http 5000). Use the HTTPS URL plus /webhook as the callback, and update it in the dashboard after each restart on free plans. Go Live only after review passes and the privacy policy URL and app icon are set. Live mode is what lets non-team users reach the bot.
If you are choosing a route, a no-code platform is almost always faster and cheaper for common questions. Choose the custom webhook when you need CRM or database access, multiple channels or strict data control. Dialogflow suits structured intents such as order status and bookings, while open-ended questions are often easier with an LLM bot grounded in your documents.
| Symptom | Likely cause | Fix |
|---|---|---|
| Callback URL will not verify | Server returns JSON or a 404 instead of the raw hub.challenge, or the verify token differs | Return the challenge as plain text with 200 and match the token exactly |
| Verified but no messages arrive | 'messages' field not subscribed, or 'Allow access to messages' is off | Subscribe the field and account, and enable the setting in Instagram |
| Real users never get replies | App is in Development mode | Finish review and switch to Live |
| (#10) permission error | Permission not approved or token lacks the scope | Request the correct permission and regenerate the token |
| Replies stop after weeks | Token expired | Refresh long-lived tokens before their roughly 60-day expiry |
| Bot replies to itself | Echo events handled as user messages | Skip events with is_echo |
| Signature check always fails | Parsed JSON hashed instead of the raw body, or wrong app secret | Hash the raw bytes with the secret of the same app |
Common questions
Does Dialogflow ES or CX support Instagram directly?
No. Neither version has an Instagram connector in its integrations list. You need a relay that takes the Meta webhook and calls detectIntent.
Do I need App Review if I use my own webhook?
Yes, to serve the public. In Development mode, only users with a role on the app can message the bot, so you can build without review, but live customers need the approved messaging permission and Business verification.
Can the bot message customers first?
No. The user must start the conversation, and you can only reply within 24 hours of their last message. Comment or story-reply triggers can start a conversation when the user responds.
Can Dialogflow send buttons and quick replies on Instagram?
Yes, but Dialogflow does not translate them for you. Return a custom payload from the agent and have your relay convert it into Meta's quick reply or template JSON, within Meta's limits on count and label length.
Is ManyChat cheaper than building a custom webhook?
Usually in the first months, since it needs no development and no review. A custom webhook has little platform fee but costs developer time, hosting and the maintenance of API version and permission changes.