Create comment-to-DM automation
Create a keyword-triggered DM automation on an Instagram or Facebook account.
When someone comments a matching keyword (or, with trigger: story_reply, replies
to your Instagram story with one), they automatically receive a DM.
Triggers (trigger):
comment(default): fires on keyword comments on a post or reel.story_reply: fires when someone replies to your Instagram story with a keyword, and answers them with a DM. SetplatformPostIdto a story media id to scope to one story, or omit it to match replies to any story.
Targeting (comment trigger):
- Per-post: set
platformPostIdto scope to one specific post (only one active per-post automation is allowed per post). - Account-wide ("any post"): omit
platformPostId(andpostId). The automation evaluates every comment on every post on the account. You can stack unlimited account-wide automations, each with its own keyword set, and they all run independently. Per-post automations take priority on their post.
Audience (audience, Instagram only): restrict the automation to followers or
non-followers, and/or to accounts above a follower count. Instagram only reveals the
follow relationship for people who have messaged the account, so audience.whenUnknown
decides what happens for everyone else - including verify, which sends a one-tap
confirmation DM (followGate) and then delivers the real DM automatically. People we
already know follow you skip the tap entirely.
Set alsoMatchInDms: true on a comment automation to also answer people who send
a keyword as a direct message instead of commenting it. One automation then covers
both doors, and each door is deduplicated separately (someone who already got the DM
from their comment still gets it if they later DM the keyword). Requires at least one
keyword.
Links in the DM's buttons can be click-tracked (linkTracking, on by default) and
clickers optionally tagged (clickTag) for segmentation. Stats returned include
delivered, read, and link clicks.
API key authentication - use your Zernio API key as a Bearer token
In: header
Instagram or Facebook account ID
What fires the automation. 'comment' (keyword comment on a post) or 'story_reply' (keyword reply to an Instagram story). For 'story_reply', platformPostId is the story media id (omit for any story).
"comment""comment" | "story_reply"Platform media/post ID (or story media id when trigger=story_reply). Omit for an account-wide (any-post / any-story) automation.
Zernio post ID. Required only when also targeting a specific post via platformPostId.
Post content snippet for display
Automation label
Trigger keywords (empty = any comment triggers)
How a keyword is compared with the comment. 'contains' (default) matches anywhere, even inside another word (keyword 'app' fires on 'happy'). 'word' matches the keyword only as a standalone word. 'exact' requires the whole comment to be exactly the keyword.
"contains""exact" | "contains" | "word"Comments containing one of these never trigger the automation, even when a trigger keyword also matches. Compared using the same matchMode.
Only with matchMode=word: also fire on close misspellings of a keyword (one edit for 4-7 character keywords, two from 8 up). Keywords shorter than 4 characters are never fuzzy-matched.
DM text to send to commenter. Max 640 chars when buttons are set, otherwise ~1000.
Optional inline DM buttons (1-3). Phone buttons are Facebook-only. Omit or pass [] for a plain-text DM.
items <= 3Optional public reply to the comment
Optional alternate DM texts for random rotation. When set, each triggered comment sends one picked at random from [dmMessage, ...dmMessageVariations], so repeat commenters get slightly different DMs (helps avoid identical-message patterns). Up to 5. Buttons are attached to whichever text is picked, not varied.
items <= 5Optional alternate public replies, rotated at random alongside commentReply (picked independently of the DM). Up to 5.
items <= 5Wrap link buttons in the DM in a tracked redirect so clicks are counted (Link Clicks / CTR). Pass false to send links exactly as written. Defaults to on.
trueOptional tag applied to a contact when they click a tracked link (requires linkTracking). Lets you segment clickers for broadcasts/sequences.
Seconds to wait after the trigger before sending the DM. Omit or send 0 to reply immediately (the default). Max 86400 (24h). The trigger is still matched and deduplicated the moment the comment arrives, so a delay only moves when the response is sent.
0 <= value <= 86400Seconds to wait before posting the public comment reply. Omit or send 0 to post it right after the DM (the default). The reply never goes out before the DM, so a value below dmDelaySeconds is raised to it. Ignored when trigger=story_reply, which has no public reply.
0 <= value <= 86400Also fire these keywords on a plain inbound DM, so the automation answers people who message the keyword instead of commenting it. Requires at least one keyword (an empty keyword list means 'match anything', which would answer every inbound message) and is rejected on story_reply automations, which already trigger on DMs. Dedup is per door: a contact who already received the DM from their comment can still receive it from a DM.
falseWho a comment automation answers. Instagram only - Meta exposes the follow
relationship on no other platform, and only for people who have MESSAGED the
account (a comment grants no consent). whenUnknown is therefore the important
setting: it decides what happens for a first-time commenter.
Copy for the follow gate. Sensible defaults are used for any field left empty.
Response Body
application/json
application/json
import Zernio from '@zernio/node';const zernio = new Zernio({ apiKey: process.env.ZERNIO_API_KEY });const { data } = await zernio.commentautomations.createCommentAutomation({ body: { profileId: 'profile_abc123', accountId: 'account_abc123', name: 'Example', dmMessage: 'string', },});console.log(data);{
"success": true,
"automation": {
"id": "string",
"name": "string",
"platform": "string",
"trigger": "comment",
"platformPostId": "string",
"keywords": [
"string"
],
"matchMode": "exact",
"excludeKeywords": [
"string"
],
"typoTolerance": true,
"dmMessage": "string",
"buttons": [
{
"type": "url",
"title": "string",
"url": "http://example.com",
"payload": "string",
"phone": "string"
}
],
"template": {
"type": "generic",
"elements": [
{
"title": "string",
"subtitle": "string",
"imageUrl": "http://example.com",
"buttons": [
{
"type": "url",
"title": "string",
"url": "http://example.com",
"payload": "string"
}
]
}
]
},
"commentReply": "string",
"dmMessageVariations": [
"string"
],
"commentReplyVariations": [
"string"
],
"linkTracking": true,
"clickTag": "string",
"dmDelaySeconds": 0,
"commentReplyDelaySeconds": 0,
"audience": {
"followerStatus": "any",
"minFollowerCount": 0,
"whenUnknown": "send"
},
"followGate": {
"message": "string",
"buttonLabel": "string",
"notFollowingMessage": "string"
},
"alsoMatchInDms": true,
"isActive": true,
"stats": {
"totalTriggered": 0,
"totalSent": 0,
"totalFailed": 0
},
"createdAt": "2019-08-24T14:15:22Z"
}
}{
"error": "Unauthorized"
}