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.
kind | Runs on | Sends |
|---|---|---|
comment_to_dm | A comment on the account's posts | A private reply |
story_reply | A message with an attachment, such as a story reply | A direct message |
welcome_dm | Any message to the account | A 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.
| Rule | Detail |
|---|---|
| One answer | When several rules match, the oldest answers |
| Comments | Each comment is answered once, on any of the account's posts |
| Messages | A message rule answers a person at most once per 24 hours |
| Platform rules | One private reply per comment, within 7 days. Messages follow the 24-hour window |
| Message limits | Over the account's limit, rules send nothing |
| Account status | Rules 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
}| Field | Rule |
|---|---|
accountId | An Instagram or Facebook account from List Accounts |
kind | comment_to_dm, story_reply or welcome_dm |
name | 1 to 120 characters |
keywords | 1 to 20 words, each up to 200 characters |
excludeKeywords | Optional, up to 20 words of 200 characters |
message | The message to send, 1 to 1,000 characters |
enabled | Optional, 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
| Method | Path | Does |
|---|---|---|
GET | /v1/automations | Lists 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
| Code | HTTP | Cause | Fix |
|---|---|---|---|
VALIDATION_ERROR | 400 | A field is missing or out of range | Fix the field in param |
UNSUPPORTED_PLATFORM | 400 | Not an Instagram or Facebook account | Use one of those |
LIMIT_REACHED | 400 | The account has 20 rules | Delete one first |
ACCOUNT_NOT_FOUND | 404 | No such account | Use an id from List Accounts |
NOT_FOUND | 404 | No rule has this id | Check the aut_ id |
CONFLICT | 409 | The rules changed during the request | Send it again |
Other codes are in Error Codes.