> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs-parschat.parstechai.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs-parschat.parstechai.com/_mcp/server.

# Create a rule

POST https://api-chat.parstechai.com/v1/robots/{robot_id}/channels/{channel_id}/rules
Content-Type: application/json

Creates a keyword-triggered automation on one channel.

A DM rule sends `actions`. A comment rule can post a public reply with `reply_in_comment`, follow it privately with `then_send_dm`, or do both, which is the pattern that turns a public comment into a private sale. A comment rule with neither is rejected with 422.

Add `require_follow` to withhold the answer until the commenter follows the page.

Reference: https://docs-parschat.parstechai.com/api-reference/instagram-automation/create-rule

## Authentication

- `Authorization` header (bearer token, required) — Your API key, issued by ParsChat sales. One key per account, spanning every robot you own. Send it as `Authorization: Bearer pk_live_…`.

## Request

### Path parameters

- `robot_id` (string, required) — The robot's id, as returned by the create call.
- `channel_id` (string, required) — The channel's id.

### Body (application/json)

This endpoint expects a Rule.

- `id` (string, optional) — ParsChat identifier for the rule.
- `name` (string, optional) — Your label for the rule. Shown in the panel.
- `trigger` (Trigger, optional) — What makes a rule fire.
- `actions` (list of Action, optional) — What to send on a DM rule.
- `reply_in_comment` (RuleReplyInComment, optional) — Comment rules only. Posts a public reply under the comment.
- `then_send_dm` (list of Action, optional) — Comment rules only. Follows the public reply with a private message.
- `require_follow` (RequireFollow, optional) — Withhold the reply until the commenter follows the page. The verification round-trip is ours: you do not implement it.
- `is_active` (boolean, optional, default: true) — Whether the rule is currently firing.
- `created_at` (datetime, optional) — When the rule was created.

## Response

### 201

The rule was created and is live if `is_active` is true.

- `id` (string, optional) — ParsChat identifier for the rule.
- `name` (string, optional) — Your label for the rule. Shown in the panel.
- `trigger` (Trigger, optional) — What makes a rule fire.
- `actions` (list of Action, optional) — What to send on a DM rule.
- `reply_in_comment` (RuleReplyInComment, optional) — Comment rules only. Posts a public reply under the comment.
- `then_send_dm` (list of Action, optional) — Comment rules only. Follows the public reply with a private message.
- `require_follow` (RequireFollow, optional) — Withhold the reply until the commenter follows the page. The verification round-trip is ours: you do not implement it.
- `is_active` (boolean, optional, default: true) — Whether the rule is currently firing.
- `created_at` (datetime, optional) — When the rule was created.

## Errors

### 400 Bad Request Error

The request itself is malformed: a parameter is missing, unparseable, or out of range. Unlike 422, the request never reached validation of its contents.

- `error` (ErrorError, optional)

### 401 Unauthorized Error

The key is missing, wrong, revoked, or past its expiry date. All four answer `invalid_key`: telling an expired key from an unknown one would confirm to whoever holds a leaked key that it was once real.

- `error` (ErrorError, optional)

### 403 Forbidden Error

The call is understood but not permitted: a missing role, a lapsed plan, or exhausted capacity.

- `error` (ErrorError, optional)

### 404 Not Found Error

No such resource, or it belongs to another partner. We return 404 rather than 403 here, because a 403 would confirm the id exists.

- `error` (ErrorError, optional)

### 422 Unprocessable Entity Error

The payload is malformed, or a prerequisite is not configured.

- `error` (ErrorError, optional)

### 429 Too Many Requests Error

You are calling the API too fast. `details` names the limit you are held to. This never means an automated reply to an end customer was discarded: those are queued, not dropped.

- `error` (ErrorError, optional)

### 500 Internal Server Error

Something failed on our side. Retry with backoff, and quote `request_id` if it persists.

- `error` (ErrorError, optional)

### 503 Service Unavailable Error

A service we depend on (a channel provider, or our AI service) is unavailable. Retry with backoff.

- `error` (ErrorError, optional)

## Types

### Trigger

What makes a rule fire.

- `on` (enum, required) — `dm` matches direct messages. `comment` matches comments on posts and reels.
  - Allowed values: `dm`, `comment`
- `keywords` (list of string, required) — Words that trigger the rule. At least one is required.
- `match` (enum, optional, default: contains) — `contains` matches a keyword anywhere in the text. `equal` requires the whole message to match.
  - Allowed values: `contains`, `equal`
- `media_id` (string, optional) — Comment rules only. Scopes the rule to one post or reel. Omit it and the rule applies to every post. Get ids from the media endpoint.

### Action

One step of a reply. The vocabulary is closed: an unknown `type` returns 422, so new action types can be added without breaking a partner who guessed.

- `type` (enum, required) — Which kind of step this is.
  - Allowed values: `text`, `image`, `link`, `delay`
- `body` (string, optional) — Message text. Required when `type` is `text`.
- `url` (string, optional) — Destination for a `link`, or the image source for an `image`.
- `label` (string, optional) — Button label for a `link`.
- `seconds` (integer, optional) — How long to wait. Used when `type` is `delay`.

### RuleReplyInComment

Comment rules only. Posts a public reply under the comment.

- `body` (string, optional) — The public reply text.

### RequireFollow

Withhold the reply until the commenter follows the page. The verification round-trip is ours: you do not implement it.

- `enabled` (boolean, optional) — Whether the gate applies to this rule.
- `prompt` (string, optional) — Sent instead of the reply when the sender does not follow.
- `button_text` (string, optional) — Label on the postback button, tapped inside Instagram.
- `retry_prompt` (string, optional) — Sent when someone taps the button before actually following.

### ErrorError

- `code` (string, optional) — Stable machine-readable code. Branch on this, not on the message.
- `message` (string, optional) — Human-readable explanation. Wording may change.
- `request_id` (string, optional) — Log this. It is what lets support find your exact request.
- `details` (map from string to any, optional) — Machine-readable context for the code. On `capacity_exhausted` it carries `occupied`, `requested` and `capacity`; on `rate_limited`, `limit_per_minute` and `window_seconds`.

## Examples

### DM keyword reply

**Request**

```json
{
  "name": "Price enquiry to catalogue",
  "trigger": {
    "on": "dm",
    "keywords": [
      "price",
      "how much",
      "cost"
    ],
    "match": "contains"
  },
  "actions": [
    {
      "type": "text",
      "body": "Hello! Here is our catalogue."
    },
    {
      "type": "link",
      "url": "https://shop.example/catalogue",
      "label": "Catalogue"
    }
  ],
  "is_active": true
}
```

**Response**

```json
{
  "id": "rul_7nQ2xK",
  "name": "Price enquiry to catalogue",
  "trigger": {
    "on": "dm",
    "keywords": [
      "price",
      "how much",
      "cost"
    ],
    "match": "contains"
  },
  "actions": [
    {
      "type": "text",
      "body": "Hello! Here is our catalogue."
    },
    {
      "type": "link",
      "url": "https://shop.example/catalogue",
      "label": "Catalogue"
    }
  ],
  "is_active": true,
  "created_at": "2026-09-20T11:12:00Z"
}
```

**SDK Code**

```python DM keyword reply
import requests

url = "https://api-chat.parstechai.com/v1/robots/rbt_8fK2mQ/channels/chn_3pQ7xL/rules"

payload = {
    "name": "Price enquiry to catalogue",
    "trigger": {
        "on": "dm",
        "keywords": ["price", "how much", "cost"],
        "match": "contains"
    },
    "actions": [
        {
            "type": "text",
            "body": "Hello! Here is our catalogue."
        },
        {
            "type": "link",
            "url": "https://shop.example/catalogue",
            "label": "Catalogue"
        }
    ],
    "is_active": True
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript DM keyword reply
const url = 'https://api-chat.parstechai.com/v1/robots/rbt_8fK2mQ/channels/chn_3pQ7xL/rules';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"name":"Price enquiry to catalogue","trigger":{"on":"dm","keywords":["price","how much","cost"],"match":"contains"},"actions":[{"type":"text","body":"Hello! Here is our catalogue."},{"type":"link","url":"https://shop.example/catalogue","label":"Catalogue"}],"is_active":true}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go DM keyword reply
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api-chat.parstechai.com/v1/robots/rbt_8fK2mQ/channels/chn_3pQ7xL/rules"

	payload := strings.NewReader("{\n  \"name\": \"Price enquiry to catalogue\",\n  \"trigger\": {\n    \"on\": \"dm\",\n    \"keywords\": [\n      \"price\",\n      \"how much\",\n      \"cost\"\n    ],\n    \"match\": \"contains\"\n  },\n  \"actions\": [\n    {\n      \"type\": \"text\",\n      \"body\": \"Hello! Here is our catalogue.\"\n    },\n    {\n      \"type\": \"link\",\n      \"url\": \"https://shop.example/catalogue\",\n      \"label\": \"Catalogue\"\n    }\n  ],\n  \"is_active\": true\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby DM keyword reply
require 'uri'
require 'net/http'

url = URI("https://api-chat.parstechai.com/v1/robots/rbt_8fK2mQ/channels/chn_3pQ7xL/rules")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"name\": \"Price enquiry to catalogue\",\n  \"trigger\": {\n    \"on\": \"dm\",\n    \"keywords\": [\n      \"price\",\n      \"how much\",\n      \"cost\"\n    ],\n    \"match\": \"contains\"\n  },\n  \"actions\": [\n    {\n      \"type\": \"text\",\n      \"body\": \"Hello! Here is our catalogue.\"\n    },\n    {\n      \"type\": \"link\",\n      \"url\": \"https://shop.example/catalogue\",\n      \"label\": \"Catalogue\"\n    }\n  ],\n  \"is_active\": true\n}"

response = http.request(request)
puts response.read_body
```

```java DM keyword reply
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api-chat.parstechai.com/v1/robots/rbt_8fK2mQ/channels/chn_3pQ7xL/rules")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"name\": \"Price enquiry to catalogue\",\n  \"trigger\": {\n    \"on\": \"dm\",\n    \"keywords\": [\n      \"price\",\n      \"how much\",\n      \"cost\"\n    ],\n    \"match\": \"contains\"\n  },\n  \"actions\": [\n    {\n      \"type\": \"text\",\n      \"body\": \"Hello! Here is our catalogue.\"\n    },\n    {\n      \"type\": \"link\",\n      \"url\": \"https://shop.example/catalogue\",\n      \"label\": \"Catalogue\"\n    }\n  ],\n  \"is_active\": true\n}")
  .asString();
```

```php DM keyword reply
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api-chat.parstechai.com/v1/robots/rbt_8fK2mQ/channels/chn_3pQ7xL/rules', [
  'body' => '{
  "name": "Price enquiry to catalogue",
  "trigger": {
    "on": "dm",
    "keywords": [
      "price",
      "how much",
      "cost"
    ],
    "match": "contains"
  },
  "actions": [
    {
      "type": "text",
      "body": "Hello! Here is our catalogue."
    },
    {
      "type": "link",
      "url": "https://shop.example/catalogue",
      "label": "Catalogue"
    }
  ],
  "is_active": true
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp DM keyword reply
using RestSharp;

var client = new RestClient("https://api-chat.parstechai.com/v1/robots/rbt_8fK2mQ/channels/chn_3pQ7xL/rules");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"name\": \"Price enquiry to catalogue\",\n  \"trigger\": {\n    \"on\": \"dm\",\n    \"keywords\": [\n      \"price\",\n      \"how much\",\n      \"cost\"\n    ],\n    \"match\": \"contains\"\n  },\n  \"actions\": [\n    {\n      \"type\": \"text\",\n      \"body\": \"Hello! Here is our catalogue.\"\n    },\n    {\n      \"type\": \"link\",\n      \"url\": \"https://shop.example/catalogue\",\n      \"label\": \"Catalogue\"\n    }\n  ],\n  \"is_active\": true\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift DM keyword reply
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "name": "Price enquiry to catalogue",
  "trigger": [
    "on": "dm",
    "keywords": ["price", "how much", "cost"],
    "match": "contains"
  ],
  "actions": [
    [
      "type": "text",
      "body": "Hello! Here is our catalogue."
    ],
    [
      "type": "link",
      "url": "https://shop.example/catalogue",
      "label": "Catalogue"
    ]
  ],
  "is_active": true
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api-chat.parstechai.com/v1/robots/rbt_8fK2mQ/channels/chn_3pQ7xL/rules")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### Comment reply, then DM

**Request**

```json
{
  "name": "Comment on launch post: public reply and DM",
  "trigger": {
    "on": "comment",
    "keywords": [
      "available",
      "in stock"
    ],
    "match": "contains",
    "media_id": "17895695668004550"
  },
  "reply_in_comment": {
    "body": "Yes, it is in stock. Details sent by DM."
  },
  "then_send_dm": [
    {
      "type": "text",
      "body": "Hello! This product is available."
    },
    {
      "type": "link",
      "url": "https://shop.example/p/1042",
      "label": "Buy"
    }
  ],
  "is_active": true
}
```

**Response**

```json
{
  "id": "rul_9pL3mT",
  "name": "Comment on launch post: public reply and DM",
  "trigger": {
    "on": "comment",
    "keywords": [
      "available",
      "in stock"
    ],
    "match": "contains",
    "media_id": "17895695668004550"
  },
  "reply_in_comment": {
    "body": "Yes, it is in stock. Details sent by DM."
  },
  "then_send_dm": [
    {
      "type": "text",
      "body": "Hello! This product is available."
    },
    {
      "type": "link",
      "url": "https://shop.example/p/1042",
      "label": "Buy"
    }
  ],
  "is_active": true,
  "created_at": "2026-09-20T11:15:40Z"
}
```

**SDK Code**

```python Comment reply, then DM
import requests

url = "https://api-chat.parstechai.com/v1/robots/rbt_8fK2mQ/channels/chn_3pQ7xL/rules"

payload = {
    "name": "Comment on launch post: public reply and DM",
    "trigger": {
        "on": "comment",
        "keywords": ["available", "in stock"],
        "match": "contains",
        "media_id": "17895695668004550"
    },
    "reply_in_comment": { "body": "Yes, it is in stock. Details sent by DM." },
    "then_send_dm": [
        {
            "type": "text",
            "body": "Hello! This product is available."
        },
        {
            "type": "link",
            "url": "https://shop.example/p/1042",
            "label": "Buy"
        }
    ],
    "is_active": True
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript Comment reply, then DM
const url = 'https://api-chat.parstechai.com/v1/robots/rbt_8fK2mQ/channels/chn_3pQ7xL/rules';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"name":"Comment on launch post: public reply and DM","trigger":{"on":"comment","keywords":["available","in stock"],"match":"contains","media_id":"17895695668004550"},"reply_in_comment":{"body":"Yes, it is in stock. Details sent by DM."},"then_send_dm":[{"type":"text","body":"Hello! This product is available."},{"type":"link","url":"https://shop.example/p/1042","label":"Buy"}],"is_active":true}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Comment reply, then DM
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api-chat.parstechai.com/v1/robots/rbt_8fK2mQ/channels/chn_3pQ7xL/rules"

	payload := strings.NewReader("{\n  \"name\": \"Comment on launch post: public reply and DM\",\n  \"trigger\": {\n    \"on\": \"comment\",\n    \"keywords\": [\n      \"available\",\n      \"in stock\"\n    ],\n    \"match\": \"contains\",\n    \"media_id\": \"17895695668004550\"\n  },\n  \"reply_in_comment\": {\n    \"body\": \"Yes, it is in stock. Details sent by DM.\"\n  },\n  \"then_send_dm\": [\n    {\n      \"type\": \"text\",\n      \"body\": \"Hello! This product is available.\"\n    },\n    {\n      \"type\": \"link\",\n      \"url\": \"https://shop.example/p/1042\",\n      \"label\": \"Buy\"\n    }\n  ],\n  \"is_active\": true\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Comment reply, then DM
require 'uri'
require 'net/http'

url = URI("https://api-chat.parstechai.com/v1/robots/rbt_8fK2mQ/channels/chn_3pQ7xL/rules")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"name\": \"Comment on launch post: public reply and DM\",\n  \"trigger\": {\n    \"on\": \"comment\",\n    \"keywords\": [\n      \"available\",\n      \"in stock\"\n    ],\n    \"match\": \"contains\",\n    \"media_id\": \"17895695668004550\"\n  },\n  \"reply_in_comment\": {\n    \"body\": \"Yes, it is in stock. Details sent by DM.\"\n  },\n  \"then_send_dm\": [\n    {\n      \"type\": \"text\",\n      \"body\": \"Hello! This product is available.\"\n    },\n    {\n      \"type\": \"link\",\n      \"url\": \"https://shop.example/p/1042\",\n      \"label\": \"Buy\"\n    }\n  ],\n  \"is_active\": true\n}"

response = http.request(request)
puts response.read_body
```

```java Comment reply, then DM
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api-chat.parstechai.com/v1/robots/rbt_8fK2mQ/channels/chn_3pQ7xL/rules")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"name\": \"Comment on launch post: public reply and DM\",\n  \"trigger\": {\n    \"on\": \"comment\",\n    \"keywords\": [\n      \"available\",\n      \"in stock\"\n    ],\n    \"match\": \"contains\",\n    \"media_id\": \"17895695668004550\"\n  },\n  \"reply_in_comment\": {\n    \"body\": \"Yes, it is in stock. Details sent by DM.\"\n  },\n  \"then_send_dm\": [\n    {\n      \"type\": \"text\",\n      \"body\": \"Hello! This product is available.\"\n    },\n    {\n      \"type\": \"link\",\n      \"url\": \"https://shop.example/p/1042\",\n      \"label\": \"Buy\"\n    }\n  ],\n  \"is_active\": true\n}")
  .asString();
```

```php Comment reply, then DM
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api-chat.parstechai.com/v1/robots/rbt_8fK2mQ/channels/chn_3pQ7xL/rules', [
  'body' => '{
  "name": "Comment on launch post: public reply and DM",
  "trigger": {
    "on": "comment",
    "keywords": [
      "available",
      "in stock"
    ],
    "match": "contains",
    "media_id": "17895695668004550"
  },
  "reply_in_comment": {
    "body": "Yes, it is in stock. Details sent by DM."
  },
  "then_send_dm": [
    {
      "type": "text",
      "body": "Hello! This product is available."
    },
    {
      "type": "link",
      "url": "https://shop.example/p/1042",
      "label": "Buy"
    }
  ],
  "is_active": true
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp Comment reply, then DM
using RestSharp;

var client = new RestClient("https://api-chat.parstechai.com/v1/robots/rbt_8fK2mQ/channels/chn_3pQ7xL/rules");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"name\": \"Comment on launch post: public reply and DM\",\n  \"trigger\": {\n    \"on\": \"comment\",\n    \"keywords\": [\n      \"available\",\n      \"in stock\"\n    ],\n    \"match\": \"contains\",\n    \"media_id\": \"17895695668004550\"\n  },\n  \"reply_in_comment\": {\n    \"body\": \"Yes, it is in stock. Details sent by DM.\"\n  },\n  \"then_send_dm\": [\n    {\n      \"type\": \"text\",\n      \"body\": \"Hello! This product is available.\"\n    },\n    {\n      \"type\": \"link\",\n      \"url\": \"https://shop.example/p/1042\",\n      \"label\": \"Buy\"\n    }\n  ],\n  \"is_active\": true\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Comment reply, then DM
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "name": "Comment on launch post: public reply and DM",
  "trigger": [
    "on": "comment",
    "keywords": ["available", "in stock"],
    "match": "contains",
    "media_id": "17895695668004550"
  ],
  "reply_in_comment": ["body": "Yes, it is in stock. Details sent by DM."],
  "then_send_dm": [
    [
      "type": "text",
      "body": "Hello! This product is available."
    ],
    [
      "type": "link",
      "url": "https://shop.example/p/1042",
      "label": "Buy"
    ]
  ],
  "is_active": true
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api-chat.parstechai.com/v1/robots/rbt_8fK2mQ/channels/chn_3pQ7xL/rules")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### Follow required first

**Request**

```json
{
  "name": "Price enquiry, follow first",
  "trigger": {
    "on": "comment",
    "keywords": [
      "price",
      "1"
    ],
    "match": "contains"
  },
  "reply_in_comment": {
    "body": "Your answer has been sent by DM."
  },
  "then_send_dm": [
    {
      "type": "text",
      "body": "Hello, message us for more help."
    }
  ],
  "require_follow": {
    "enabled": true,
    "prompt": "Follow the page first, then tap the button below.",
    "button_text": "I followed",
    "retry_prompt": "We checked, and the follow is not confirmed yet. Follow the page, then tap again."
  },
  "is_active": true
}
```

**Response**

```json
{
  "id": "rul_4kN8qW",
  "name": "Price enquiry, follow first",
  "trigger": {
    "on": "comment",
    "keywords": [
      "price",
      "1"
    ],
    "match": "contains"
  },
  "reply_in_comment": {
    "body": "Your answer has been sent by DM."
  },
  "then_send_dm": [
    {
      "type": "text",
      "body": "Hello, message us for more help."
    }
  ],
  "require_follow": {
    "enabled": true,
    "prompt": "Follow the page first, then tap the button below.",
    "button_text": "I followed",
    "retry_prompt": "We checked, and the follow is not confirmed yet. Follow the page, then tap again."
  },
  "is_active": true,
  "created_at": "2026-09-20T11:18:02Z"
}
```

**SDK Code**

```python Follow required first
import requests

url = "https://api-chat.parstechai.com/v1/robots/rbt_8fK2mQ/channels/chn_3pQ7xL/rules"

payload = {
    "name": "Price enquiry, follow first",
    "trigger": {
        "on": "comment",
        "keywords": ["price", "1"],
        "match": "contains"
    },
    "reply_in_comment": { "body": "Your answer has been sent by DM." },
    "then_send_dm": [
        {
            "type": "text",
            "body": "Hello, message us for more help."
        }
    ],
    "require_follow": {
        "enabled": True,
        "prompt": "Follow the page first, then tap the button below.",
        "button_text": "I followed",
        "retry_prompt": "We checked, and the follow is not confirmed yet. Follow the page, then tap again."
    },
    "is_active": True
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript Follow required first
const url = 'https://api-chat.parstechai.com/v1/robots/rbt_8fK2mQ/channels/chn_3pQ7xL/rules';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"name":"Price enquiry, follow first","trigger":{"on":"comment","keywords":["price","1"],"match":"contains"},"reply_in_comment":{"body":"Your answer has been sent by DM."},"then_send_dm":[{"type":"text","body":"Hello, message us for more help."}],"require_follow":{"enabled":true,"prompt":"Follow the page first, then tap the button below.","button_text":"I followed","retry_prompt":"We checked, and the follow is not confirmed yet. Follow the page, then tap again."},"is_active":true}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Follow required first
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api-chat.parstechai.com/v1/robots/rbt_8fK2mQ/channels/chn_3pQ7xL/rules"

	payload := strings.NewReader("{\n  \"name\": \"Price enquiry, follow first\",\n  \"trigger\": {\n    \"on\": \"comment\",\n    \"keywords\": [\n      \"price\",\n      \"1\"\n    ],\n    \"match\": \"contains\"\n  },\n  \"reply_in_comment\": {\n    \"body\": \"Your answer has been sent by DM.\"\n  },\n  \"then_send_dm\": [\n    {\n      \"type\": \"text\",\n      \"body\": \"Hello, message us for more help.\"\n    }\n  ],\n  \"require_follow\": {\n    \"enabled\": true,\n    \"prompt\": \"Follow the page first, then tap the button below.\",\n    \"button_text\": \"I followed\",\n    \"retry_prompt\": \"We checked, and the follow is not confirmed yet. Follow the page, then tap again.\"\n  },\n  \"is_active\": true\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Follow required first
require 'uri'
require 'net/http'

url = URI("https://api-chat.parstechai.com/v1/robots/rbt_8fK2mQ/channels/chn_3pQ7xL/rules")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"name\": \"Price enquiry, follow first\",\n  \"trigger\": {\n    \"on\": \"comment\",\n    \"keywords\": [\n      \"price\",\n      \"1\"\n    ],\n    \"match\": \"contains\"\n  },\n  \"reply_in_comment\": {\n    \"body\": \"Your answer has been sent by DM.\"\n  },\n  \"then_send_dm\": [\n    {\n      \"type\": \"text\",\n      \"body\": \"Hello, message us for more help.\"\n    }\n  ],\n  \"require_follow\": {\n    \"enabled\": true,\n    \"prompt\": \"Follow the page first, then tap the button below.\",\n    \"button_text\": \"I followed\",\n    \"retry_prompt\": \"We checked, and the follow is not confirmed yet. Follow the page, then tap again.\"\n  },\n  \"is_active\": true\n}"

response = http.request(request)
puts response.read_body
```

```java Follow required first
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api-chat.parstechai.com/v1/robots/rbt_8fK2mQ/channels/chn_3pQ7xL/rules")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"name\": \"Price enquiry, follow first\",\n  \"trigger\": {\n    \"on\": \"comment\",\n    \"keywords\": [\n      \"price\",\n      \"1\"\n    ],\n    \"match\": \"contains\"\n  },\n  \"reply_in_comment\": {\n    \"body\": \"Your answer has been sent by DM.\"\n  },\n  \"then_send_dm\": [\n    {\n      \"type\": \"text\",\n      \"body\": \"Hello, message us for more help.\"\n    }\n  ],\n  \"require_follow\": {\n    \"enabled\": true,\n    \"prompt\": \"Follow the page first, then tap the button below.\",\n    \"button_text\": \"I followed\",\n    \"retry_prompt\": \"We checked, and the follow is not confirmed yet. Follow the page, then tap again.\"\n  },\n  \"is_active\": true\n}")
  .asString();
```

```php Follow required first
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api-chat.parstechai.com/v1/robots/rbt_8fK2mQ/channels/chn_3pQ7xL/rules', [
  'body' => '{
  "name": "Price enquiry, follow first",
  "trigger": {
    "on": "comment",
    "keywords": [
      "price",
      "1"
    ],
    "match": "contains"
  },
  "reply_in_comment": {
    "body": "Your answer has been sent by DM."
  },
  "then_send_dm": [
    {
      "type": "text",
      "body": "Hello, message us for more help."
    }
  ],
  "require_follow": {
    "enabled": true,
    "prompt": "Follow the page first, then tap the button below.",
    "button_text": "I followed",
    "retry_prompt": "We checked, and the follow is not confirmed yet. Follow the page, then tap again."
  },
  "is_active": true
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp Follow required first
using RestSharp;

var client = new RestClient("https://api-chat.parstechai.com/v1/robots/rbt_8fK2mQ/channels/chn_3pQ7xL/rules");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"name\": \"Price enquiry, follow first\",\n  \"trigger\": {\n    \"on\": \"comment\",\n    \"keywords\": [\n      \"price\",\n      \"1\"\n    ],\n    \"match\": \"contains\"\n  },\n  \"reply_in_comment\": {\n    \"body\": \"Your answer has been sent by DM.\"\n  },\n  \"then_send_dm\": [\n    {\n      \"type\": \"text\",\n      \"body\": \"Hello, message us for more help.\"\n    }\n  ],\n  \"require_follow\": {\n    \"enabled\": true,\n    \"prompt\": \"Follow the page first, then tap the button below.\",\n    \"button_text\": \"I followed\",\n    \"retry_prompt\": \"We checked, and the follow is not confirmed yet. Follow the page, then tap again.\"\n  },\n  \"is_active\": true\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Follow required first
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "name": "Price enquiry, follow first",
  "trigger": [
    "on": "comment",
    "keywords": ["price", "1"],
    "match": "contains"
  ],
  "reply_in_comment": ["body": "Your answer has been sent by DM."],
  "then_send_dm": [
    [
      "type": "text",
      "body": "Hello, message us for more help."
    ]
  ],
  "require_follow": [
    "enabled": true,
    "prompt": "Follow the page first, then tap the button below.",
    "button_text": "I followed",
    "retry_prompt": "We checked, and the follow is not confirmed yet. Follow the page, then tap again."
  ],
  "is_active": true
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api-chat.parstechai.com/v1/robots/rbt_8fK2mQ/channels/chn_3pQ7xL/rules")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```