Engagement

Automations

Answer comments, story replies and new messages that match a keyword with a direct message on Instagram and Facebook.

An automation answers a comment or message that has a keyword with a direct message, with no code to write. It works for Instagram accounts and Facebook Pages, and each account can hold up to 20 rules.

How Automations Work

A rule's kind sets what it answers and how.

kindRuns onSends
comment_to_dmA comment on the account's postsA private reply
story_replyA message with an attachment, such as a story replyA direct message
welcome_dmAny message to the accountA direct message

A rule runs when it is enabled, the text has one of its keywords, and none of its excludeKeywords. Matching ignores case.

Keywords also match inside longer words, so guide matches "Guidelines". To skip those, add guidelines to excludeKeywords.

RuleDetail
One answerWhen several rules match, the oldest answers
CommentsEach comment is answered once, on any of the account's posts
MessagesA message rule answers a person at most once per 24 hours
Platform rulesOne private reply per comment, within 7 days. Messages follow the 24-hour window
Message limitsOver the account's limit, rules send nothing
Account statusRules pause until you reconnect

Create an Automation

POST /v1/automations creates a rule and returns 201.

import { Configuration, AutomationsApi } from "@onepostly/sdk";

const automationsApi = new AutomationsApi(
  new Configuration({ accessToken: process.env.ONEPOSTLY_API_KEY })
);

const response = await automationsApi.createAutomation({
  createAutomationBody: {
    "accountId": "acc_YOUR_INSTAGRAM_ACCOUNT_ID",
    "kind": "comment_to_dm",
    "name": "Free guide giveaway",
    "keywords": [
      "guide",
      "free"
    ],
    "excludeKeywords": [
      "guidelines"
    ],
    "message": "Thanks for your interest! Here is your guide."
  },
});
console.log(response);
{
  "id": "aut_4b8e2f6a1c9d4e37a5b02c8f6d1e9a33",
  "accountId": "acc_YOUR_INSTAGRAM_ACCOUNT_ID",
  "name": "Free guide giveaway",
  "kind": "comment_to_dm",
  "keywords": [
    "guide",
    "free"
  ],
  "excludeKeywords": [
    "guidelines"
  ],
  "message": "Thanks for your interest! Here is your guide.",
  "enabled": true
}
FieldRule
accountIdAn Instagram or Facebook account from List Accounts
kindcomment_to_dm, story_reply or welcome_dm
name1 to 120 characters
keywords1 to 20 words, each up to 200 characters
excludeKeywordsOptional, up to 20 words of 200 characters
messageThe message to send, 1 to 1,000 characters
enabledOptional, default true. false creates it paused

The response holds the new rule's aut_ id and all of its fields. excludeKeywords comes back as [] when you leave it out.

Manage Automations

MethodPathDoes
GET/v1/automationsLists rules, filtered by accountId if sent
GET/v1/automations/{id}Gets one rule
PATCH/v1/automations/{id}Changes name, keywords, excludeKeywords, message or enabled
DELETE/v1/automations/{id}Deletes the rule and returns 204

The list groups rules by account, oldest first, 50 per page, up to 100 with limit. PATCH changes only the fields you send.

kind and accountId cannot change, so create a new rule instead. Disconnecting an account also removes all of its rules.

Webhooks

Automations send no event of their own. The trigger still arrives as comment.received or message.received, and a sent message as message.sent. See Comment Webhooks and Inbox Webhooks.

Errors

CodeHTTPCauseFix
VALIDATION_ERROR400A field is missing or out of rangeFix the field in param
UNSUPPORTED_PLATFORM400Not an Instagram or Facebook accountUse one of those
LIMIT_REACHED400The account has 20 rulesDelete one first
ACCOUNT_NOT_FOUND404No such accountUse an id from List Accounts
NOT_FOUND404No rule has this idCheck the aut_ id
CONFLICT409The rules changed during the requestSend it again

Other codes are in Error Codes.