Automate Instagram DMs with Meta’s official API, n8n and the OpenAI API. Send one permitted private reply to a comment, answer eligible inbound messages, optionally verify followers where supported, and save consenting sales enquiries to Zoho CRM.
- Instagram · Comment or DM
- Meta API · Official connection
- n8n · Rules and routing
- OpenAI · Helpful answers
Replies return through n8n and Meta to Instagram. Consenting sales enquiries go from n8n to Zoho CRM.
1. Start here: what you are building
Someone comments GUIDE. Your workflow sends one useful private reply. When they reply or send a new DM, the AI can answer approved questions, offer a human handoff, and—with permission—save a sales enquiry to Zoho CRM. Start with one Reel and one resource.
The system at a glance
Instagram → Meta’s official API → n8n → OpenAI API → n8n → Instagram. Zoho CRM is an optional branch for people who ask for help with your services.
What each part does
Instagram is the inbox. Meta’s API is the approved connection. n8n moves information and applies rules. OpenAI drafts answers. Zoho stores qualified enquiries. A webhook is simply Meta notifying your workflow that something happened.
ChatGPT and the API are different
You will use the OpenAI API, billed separately from a ChatGPT subscription. ChatGPT alone does not watch an Instagram inbox. This replaces selected ManyChat workflows, with setup and maintenance becoming your responsibility.
Gather these before you begin
An Instagram Business or Creator account; permission to manage it; a Meta developer account; n8n with a public HTTPS address; an OpenAI API project with billing; and optionally Zoho CRM admin access. You do not need to give n8n your Instagram password.
Costs and expectations
Budget for n8n hosting or its cloud plan, OpenAI usage, and any Zoho plan or API limits. Start small and set usage alerts. Meta access approval can take additional time; there is no guaranteed same-day setup.
2. Connect Instagram to Meta
This guide uses Instagram API with Instagram Login throughout. Keep that route consistent: its host is graph.instagram.com and it uses an Instagram User access token. Facebook Login is a separate route with different permissions and Page tokens.
Step 1 · Prepare your account
In Instagram settings, confirm the account is Business or Creator. Check the connected-tools/message-access setting and enable access where required. Confirm you can receive messages from a second account. Menu labels can vary.
Step 2 · Create your Meta app
Open Meta for Developers and create an app with the Instagram business use case. Add Instagram API with Instagram Login. Configure the required login redirect URL, website URL and privacy policy. Follow the dashboard’s current checklist.
Open →Step 3 · Request the relevant permissions
For this route, request instagram_business_basic, instagram_business_manage_comments and instagram_business_manage_messages. Comments and ordinary messaging have separate requirements. Do not copy the older Facebook Login permission names into this route.
Step 4 · Authorize the professional account
Use Business Login for Instagram to authorize the account and obtain its Instagram User access token and professional account ID. Store the token in n8n Credentials. Keep the app secret in a server-side secret store. Record expiry and renewal requirements.
Step 5 · Test access before public launch
Start with the professional account and tester roles configured in your dashboard. Standard Access is for eligible accounts you own/manage; serving other businesses requires Advanced Access and the relevant review. Complete App Review and business verification wherever Meta requires them. A role-account test does not establish public access.
Checkpoint
Make an authenticated account request using the API version selected in your Meta dashboard. Confirm the returned account is the intended TALC AI account. Keep API_VERSION and IG_ACCOUNT_ID as configuration values; never substitute an Instagram username for an ID.
Source: Meta · Instagram Login
3. Let n8n receive Instagram events
Create a small receiving workflow first. Publish it before adding the production URL in Meta. Keep the receiving step fast: validate the request, save the event durably, acknowledge it, then let a worker do the slower AI and CRM work.
Step 6 · Configure the callback URL
In n8n, add a GET Webhook at a path such as instagram-events. Set its response to use Respond to Webhook. Add a second POST Webhook at the same path for event delivery. Use the production HTTPS URL; the test URL is temporary.
Open →Verify the GET challenge
Generate a random verify token and save it server-side. On GET, require hub.mode=subscribe and an exact hub.verify_token match. Return hub.challenge unchanged as plain text with HTTP 200. Reject mismatches. Enter the same callback and verify token in Meta’s webhook configuration.
Protect POST events
Enable access to the raw request body. Validate X-Hub-Signature-256 using HMAC-SHA256 with the Meta app secret and the exact raw bytes, before parsing or processing. Reject invalid signatures. If your n8n environment cannot do this safely, put a verified webhook gateway in front of it. A GET verify token does not authenticate POST events.
Step 7 · Subscribe and activate
Subscribe the connected professional account to the comments and messages events required by your flows. Subscribe to messaging_postbacks only if you implement supported interactive replies. Complete both app webhook configuration and account subscription as required by Meta. Publish the workflow.
Save, acknowledge, then process
Write each valid event into a database or durable queue before returning HTTP 200. A separate worker reads queued events. Do not acknowledge first and hope a later AI step succeeds: that can lose messages. Do not wait for OpenAI before acknowledging Meta.
Deduplicate and filter
Loop through every entry and event in a batched payload. Store message IDs/comment IDs with the account ID and event type as unique keys. Ignore message echoes, delivery/read notifications and your own messages. Use a unique database constraint so simultaneous retries cannot send twice.
Checkpoint
Use Meta’s test delivery, then send a real DM and add a real comment from an allowed test account. In n8n Executions, confirm the account ID, comment ID, sender ID and text arrive. Keep the professional account ID separate from the sender’s Instagram-scoped ID (IGSID).
Source: n8n · Webhook
4. Build the comment → private DM workflow
Use a fixed message for resource delivery; AI is unnecessary for this first step. Meta allows one private reply to a comment, within seven days of the comment’s creation. Ordinary follow-up requires a reply from the person and must stay within the applicable messaging window. Instagram Live has a different, broadcast-only private-reply window.
Step 8 · Match the campaign
Add a Switch node for comment events. Check the media ID against the Reel(s) in your campaign, normalize text, and match a whole keyword such as GUIDE. Ignore your own comments. Save a campaign record containing media ID, keyword, approved resource URL and message text.
Visual flow · comment delivery
Comment GUIDE → validate and deduplicate → check campaign + comment age → reserve one send → send fixed private reply → save the message ID. Do not send another message just because the first was opened.
Step 9 · Configure HTTP Request
Use POST https://graph.instagram.com/API_VERSION/IG_ACCOUNT_ID/messages. Replace the two placeholders with your configured values. Add Authorization: Bearer YOUR_TOKEN through n8n Credentials and Content-Type: application/json. The JSON recipient uses comment_id, not a username.
Private-reply JSON body
{"recipient":{"comment_id":"COMMENT_ID_FROM_EVENT"},"message":{"text":"Hi! I’m TALC AI’s automated assistant. Here’s the guide you requested: YOUR_APPROVED_RESOURCE_URL. Reply if you have a question."}} Replace every placeholder before testing.
Step 10 · Record the outcome
Only mark delivered after a successful API response and save its message_id. For explicit temporary failures, retry with backoff within the permitted window. For a timeout with an uncertain send result, reconcile or send to manual review rather than blindly sending again. Non-followers may receive it in Requests.
Alternative · reply first, then deliver
If you want to check follower status, make the single private reply an invitation: “Reply GUIDE here to continue.” After their reply, run the optional profile check and deliver in the DM workflow. A comment alone does not establish the profile-consent context needed for that check.
Read Meta’s private-reply rules
The initial private reply does not by itself open an unrestricted conversation. Build the time and one-reply checks into n8n immediately before sending.
Open →Source: Meta · Private replies
5. Add helpful AI replies and optional follower verification
For ordinary inbound DMs, use a conservative 24-hour automation window from the person’s most recent message. Recheck eligibility when sending, including queued retries. Keep the AI responsible for wording; let n8n decide whether a message can be sent and which links or actions are allowed.
Step 11 · Create the inbound-DM branch
Route messages events into a separate workflow. Read sender.id as the customer’s IGSID and entry.id as your professional account ID. Save the latest user-message time. Load only the short conversation history for this account and sender. Treat attachments or unsupported messages as human-review cases initially.
Visual flow · inbound conversation
User DM → check STOP/human takeover/window → optional follower check → load approved answers → OpenAI → validate result → recheck window → Instagram reply. If someone requests a person or the answer is uncertain, pause the bot and notify the team.
Step 12 · Add the OpenAI request
Create a restricted OpenAI project API key and store it in n8n Credentials. In an HTTP Request node, POST to https://api.openai.com/v1/responses with Bearer authentication. Select a text model available in your project, set a small max_output_tokens, and pass approved business information as instructions and the DM as input.
Open →Request example
{"model":"YOUR_AVAILABLE_MODEL_ID","instructions":"Answer as TALC AI’s automated assistant using only the supplied approved FAQ. Ask for a human if unsure. Never invent prices or links.","input":"USER_MESSAGE_FROM_WEBHOOK","max_output_tokens":200,"store":false} Use n8n field expressions, not a literal placeholder message.
Keep the business knowledge small
Add approved service descriptions, published pricing only if applicable, hours, contact options and a short FAQ. Map resource/service keys to approved URLs in n8n. Treat user messages as untrusted data: they cannot change the rules, reveal secrets or authorize a CRM action. Do not give the model arbitrary tools.
Step 13 · Validate and send
Check for a completed OpenAI response. With raw HTTP, read output_text content from message items in the output array; do not assume output[0] is always the message. Reject missing output and disallowed URLs. Keep the reply comfortably below Meta’s 1,000-byte text limit, including Unicode. Send via the same /messages endpoint, with recipient.id set to the customer’s IGSID.
Ordinary-DM JSON body
{"recipient":{"id":"CUSTOMER_IGSID_FROM_MESSAGE"},"message":{"text":"VALIDATED_ASSISTANT_REPLY"}} This recipient format is for an existing eligible DM conversation. The comment workflow instead uses recipient.comment_id.
Step 14 · Optional follower verification
Only after the relevant messaging interaction grants profile access, call GET https://graph.instagram.com/API_VERSION/CUSTOMER_IGSID?fields=is_user_follow_business with the Instagram User access token. Confirm the field is supported for your app, permissions, API version and interaction. This checks the person’s relationship to your connected account, not any arbitrary account.
Open →Use three outcomes
true = verified follower at the time checked. false = verified non-follower at the time checked. Missing field, permission error or API failure = unknown. For unknown, offer the resource or human help; never label them a non-follower. An “I followed” message is a recheck request, not proof. Do not scrape follower lists or infer status from follower counts.
If you choose a follow gate
Explain the condition before collecting the keyword. For a confirmed non-follower, invite them to follow and reply CHECK; make a fresh supported profile request after that reply. Keep a manual alternative when verification is unavailable. Do not poll indefinitely or send reminders outside the messaging window.
Human handoff and opt-out
Check STOP, UNSUBSCRIBE and equivalent requests before calling AI. Persist an opt-out flag and suppress automated follow-ups. On HUMAN or uncertainty, persist human_takeover=true and alert your chosen internal channel. Resume only through a deliberate staff action. Do not use the HUMAN_AGENT tag to extend AI messaging.
Meta’s messaging reference
This tutorial deliberately keeps ordinary automation within 24 hours. Some Meta entry points have different windows; use them only after implementing and verifying that specific documented flow.
Open →Source: Meta · User profile
6. Send qualified enquiries to Zoho CRM
Offer help after answering the person’s question. Ask one question at a time: what they need, the company or project, and how they want to be contacted. Explain that you will save their details so the team can follow up. Delivering a requested guide is not blanket consent for marketing.
Step 15 · Connect Zoho
In n8n Credentials, authorize Zoho CRM using OAuth and the correct regional accounts/API domain for your Zoho data centre. Grant the minimum module access needed. Add a Zoho node for supported operations, or use an authenticated HTTP Request for the Upsert endpoint.
Step 16 · Map your fields
In Zoho’s Leads module, create a unique custom field such as Instagram_Lead_Key. Store IG_ACCOUNT_ID:CUSTOMER_IGSID there. Verify the actual field API name. Map Last_Name from the name the person provides, plus their confirmed email/phone if supplied. Add service interest, campaign, consent time and source. Meet your layout’s mandatory fields; never invent contact details.
Step 17 · Upsert instead of duplicate
POST to YOUR_ZOHO_API_DOMAIN/crm/v8/Leads/upsert. Use your unique custom field in duplicate_check_fields. Example shape: {"data":[{"Last_Name":"PROVIDED_NAME","Instagram_Lead_Key":"ACCOUNT_ID:IGSID"}],"duplicate_check_fields":["Instagram_Lead_Key"],"trigger":[]}. Replace the example field with its verified API name.
Open →Step 18 · Confirm success before promising follow-up
Inspect each record result, including partial-success responses. Save the Zoho record ID and route failures to a retry queue. Start with CRM workflow triggers disabled and check separately for any configured Cadences. Assign an owner or create a task only after testing the intended side effects. Tell the user the team received their request only after the save succeeds.
Protect conversation data
Store only the fields needed for follow-up and a short factual summary. Avoid full DM transcripts by default. Restrict n8n execution logs and CRM access, redact secrets, set retention/deletion rules and publish a privacy notice covering Meta, OpenAI, n8n and Zoho. store:false is not a promise of zero provider retention; review each provider’s data controls.
Source: Zoho · Upsert records
7. Test, launch and troubleshoot
Run the checks below with a small test campaign before turning the system on for everyone. Keep a kill switch that disables outbound sends while continuing to save valid incoming events for review.
Launch checklist · comment-to-DM
An allowed account comments GUIDE on the selected Reel and receives exactly one private reply. A non-keyword comment or a comment on another Reel sends nothing. Replaying the same event sends nothing. An old comment outside the permitted window sends nothing. Check Requests when the recipient does not follow you.
Launch checklist · messages
A new DM receives a grounded answer. A duplicate DM event produces one reply. A message outside the automation window sends nothing. STOP suppresses further automation. HUMAN pauses the bot. Unknown questions, attachments and API failures reach a person. Ensure your team can see and answer the conversation.
Launch checklist · followers and CRM
Test verified true, verified false and unknown follower results. Confirm a comment-only interaction does not force a profile lookup. Test a consenting lead twice: one Zoho record should be updated. Confirm a CRM failure is visible to staff and does not trigger a false success message.
FAQ · Can ChatGPT replace ManyChat?
OpenAI can supply the conversational intelligence. Meta’s official API and n8n supply the event handling, permissions, messaging and rules. You must maintain tokens, reviews, storage, handoff, monitoring and failures yourself. A ChatGPT subscription is not an Instagram automation connector.
FAQ · Do I need a Facebook Page?
This guide follows Instagram Login. Do not assume a Facebook Page or Page token is required for that route. If you choose Facebook Login instead, follow its own account-linking and Page-token requirements throughout. Mixing the routes is a common cause of authentication errors.
FAQ · Why does the callback fail?
Confirm public HTTPS, the production URL, an active/published workflow, an exact verify-token match and a plain-text hub.challenge response. For POST failures, check signature validation against the unmodified raw body. Never fix the problem by disabling signature validation.
FAQ · Why do test messages work but public ones fail?
Check app access level, connected-account authorization, required permissions, event subscriptions and the current App Review checklist. App-role tests do not prove an account outside that configuration can use the app. Recheck token expiry and message-access settings.
FAQ · Can I message every follower?
This is an interaction-triggered setup, not a cold-DM broadcaster. A follower relationship alone does not authorize ordinary API messaging. A comment can support the documented single private reply; further conversation requires the person’s response and the applicable window.
FAQ · Can I guarantee people follow first?
No. Only use an explicit supported profile result after the required interaction and consent. Missing permissions, unsupported fields and transient failures must remain unknown. Offer a manual or ungated fallback instead of claiming every commenter has been verified.
FAQ · What if I get a rate-limit or token error?
Pause affected sends, inspect the returned API error and alert the operator. Back off on retryable failures; renew or reauthorize expired credentials. Use the limits reported for your app instead of hard-coding an internet “safe DM count.” Never retry past the messaging window.
FAQ · Will this guide activate automation for TALC AI?
Publishing this tutorial does not connect the Instagram account or enable any real DM workflow. Those changes require the account authorization, credentials, Meta setup and testing described above.
Go live gradually
Enable one keyword on one Reel. Watch duplicate prevention, send errors, opt-outs, AI answers and CRM saves. Set daily spend and volume alerts. Expand only after the small campaign passes. Review the linked official documentation again whenever Meta changes the API version or access rules.
Official sources
- Meta · Instagram Login
- n8n · Webhook
- Meta · Private replies
- Meta · User profile
- Zoho · Upsert records
Prepared with AI and approved for publication by TALC AI. Official documentation is linked throughout.