Code samples use your device
. Create an API key under API keys.API reference · Conversations
Auto-reply rules
Keyword rules that answer incoming messages per device (exact, contains, regex), with cooldowns.
List auto-reply rules
GET
/v1/sessions/{sessionId}/auto-replyList auto-reply rules for a session.
Path parameters
sessionIdstringrequired
Responses
- 200List of rules
Response fields
rulesarray of objectrequiredrules[].idstringrequiredrules[].session_idstringrequiredrules[].namestringrequiredrules[].trigger_typestringrequiredanyreplies to every message;keywordmatches the whole text;containsmatches a word or phrase inside it;regexusestrigger_textas a regular expressionrules[].trigger_textstring | nullrequiredText or regular expression to compare with; unused byanyrules[].match_caseintegerrequired1 = case-sensitive, 0 = notrules[].reply_typestringrequiredrules[].reply_bodystring | nullrequiredReply text. Supports the personalization tokens{name},{first_name},{phone}and{{first_name|there}}-style fallbacksrules[].reply_r2_keystring | nullrequiredMedia key for non-text repliesrules[].reply_captionstring | nullrequiredrules[].cooldown_msintegerrequiredMinimum time before the same chat gets this rule againrules[].priorityintegerrequiredHigher runs firstrules[].is_activeintegerrequired1 or 0rules[].created_atintegerrequired
Request
curl "https://api.chatkomodo.com/v1/sessions/YOUR_DEVICE_ID/auto-reply" \
-H "Authorization: Bearer $CHATKOMODO_API_KEY"const res = await fetch('https://api.chatkomodo.com/v1/sessions/YOUR_DEVICE_ID/auto-reply', {
method: 'GET',
headers: {
Authorization: `Bearer ${process.env.CHATKOMODO_API_KEY}`,
},
});
const data = await res.json();
if (!res.ok) throw new Error(`${data.code}: ${data.error}`);
console.log(data);import os
import requests
res = requests.get(
"https://api.chatkomodo.com/v1/sessions/YOUR_DEVICE_ID/auto-reply",
headers={
"Authorization": f"Bearer {os.environ['CHATKOMODO_API_KEY']}",
},
timeout=30,
)
res.raise_for_status()
print(res.json())<?php
require 'vendor/autoload.php';
$client = new GuzzleHttp\Client();
$res = $client->request('GET', 'https://api.chatkomodo.com/v1/sessions/YOUR_DEVICE_ID/auto-reply', [
'headers' => [
'Authorization' => 'Bearer ' . getenv('CHATKOMODO_API_KEY'),
],
]);
print_r(json_decode((string) $res->getBody(), true));Response 200
{
"rules": [
{
"id": "01JA5V6Q8M2H7G4K9P3T0R1S2X",
"session_id": "YOUR_DEVICE_ID",
"name": "Opening hours",
"trigger_type": "any",
"trigger_text": "price",
"match_case": 1,
"reply_type": "text",
"reply_body": "Hi Sam, your order has shipped.",
"reply_r2_key": "Hi Sam, your order has shipped.",
"reply_caption": "Hi Sam, your order has shipped.",
"cooldown_ms": 1767225600000,
"priority": 1,
"is_active": 1,
"created_at": 1767225600000
}
]
}Create an auto-reply rule
POST
/v1/sessions/{sessionId}/auto-replyAdds a rule that answers inbound messages of this session. Only the first matching active rule answers, and only chats that are not groups, channels or Status. Booleans accept true/false, 1/0 and the strings "true", "false", "1", "0".
Path parameters
sessionIdstringrequiredSession (device) id
Request body
namestringrequiredRule nametrigger_typestringrequiredany: every inbound message;keyword: the whole message equalstrigger_text;contains: the message containstrigger_text;regex: the message matches the regular expression intrigger_text(rejected asUNSAFE_REGEXwhen it could backtrack catastrophically)trigger_textstring | nullText or regular expression to compare with; unused byanymatch_caseboolean | number | stringCase-sensitive matching (default false)reply_typestringDefaulttextreply_bodystring | nullReply text; personalization tokens such as{first_name}or{{first_name|there}}are filled from the CRMreply_r2_keystring | nullMedia key from/v1/media/upload-urlfor non-text repliesreply_captionstring | nullCaption of a media reply (tokens are filled like inreply_body)cooldown_msintegerMinimum time before this rule answers the same chat again (default 60 000)priorityintegerRules are tried from the highest priority down; the first match answers (default 0)is_activeboolean | number | stringInactive rules never fire (default true)
Responses
- 201Rule created
Response fields
idstringrequiredRule id
- 400Invalid body (
VALIDATION_FAILED,INVALID_JSON) or an unsafe regular expression (UNSAFE_REGEX) - 401Missing or invalid credentials
- 403The API key is restricted to other sessions, or the operation is not available to CS-agent logins
- 404Unknown session, or a session of another tenant
Request
curl -X POST "https://api.chatkomodo.com/v1/sessions/YOUR_DEVICE_ID/auto-reply" \
-H "Authorization: Bearer $CHATKOMODO_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Opening hours",
"trigger_type": "contains",
"trigger_text": "open",
"reply_type": "text",
"reply_body": "We are open Monday to Saturday, 9:00–17:00.",
"cooldown_ms": 3600000
}'const res = await fetch('https://api.chatkomodo.com/v1/sessions/YOUR_DEVICE_ID/auto-reply', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.CHATKOMODO_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
"name": "Opening hours",
"trigger_type": "contains",
"trigger_text": "open",
"reply_type": "text",
"reply_body": "We are open Monday to Saturday, 9:00–17:00.",
"cooldown_ms": 3600000
}),
});
const data = await res.json();
if (!res.ok) throw new Error(`${data.code}: ${data.error}`);
console.log(data);import os
import requests
res = requests.post(
"https://api.chatkomodo.com/v1/sessions/YOUR_DEVICE_ID/auto-reply",
headers={
"Authorization": f"Bearer {os.environ['CHATKOMODO_API_KEY']}",
},
json={
"name": "Opening hours",
"trigger_type": "contains",
"trigger_text": "open",
"reply_type": "text",
"reply_body": "We are open Monday to Saturday, 9:00–17:00.",
"cooldown_ms": 3600000,
},
timeout=30,
)
res.raise_for_status()
print(res.json())<?php
require 'vendor/autoload.php';
$client = new GuzzleHttp\Client();
$res = $client->request('POST', 'https://api.chatkomodo.com/v1/sessions/YOUR_DEVICE_ID/auto-reply', [
'headers' => [
'Authorization' => 'Bearer ' . getenv('CHATKOMODO_API_KEY'),
],
'json' => [
'name' => 'Opening hours',
'trigger_type' => 'contains',
'trigger_text' => 'open',
'reply_type' => 'text',
'reply_body' => 'We are open Monday to Saturday, 9:00–17:00.',
'cooldown_ms' => 3600000,
],
]);
print_r(json_decode((string) $res->getBody(), true));Response 201
{
"id": "01JA5V6Q8M2H7G4K9P3T0R1S2X"
}Update an auto-reply rule
PATCH
/v1/sessions/{sessionId}/auto-reply/{ruleId}Changes the given fields of a rule; omitted fields keep their value. The resulting regular expression is re-checked when the rule is or becomes a regex rule.
Path parameters
sessionIdstringrequiredSession (device) idruleIdstringrequiredRule id
Request body
namestringRule nametrigger_typestringany: every inbound message;keyword: the whole message equalstrigger_text;contains: the message containstrigger_text;regex: the message matches the regular expression intrigger_text(rejected asUNSAFE_REGEXwhen it could backtrack catastrophically)trigger_textstring | nullText or regular expression to compare with; unused byanymatch_caseboolean | number | stringCase-sensitive matching (default false)reply_typestringDefaulttextreply_bodystring | nullReply text; personalization tokens such as{first_name}or{{first_name|there}}are filled from the CRMreply_r2_keystring | nullMedia key from/v1/media/upload-urlfor non-text repliesreply_captionstring | nullCaption of a media reply (tokens are filled like inreply_body)cooldown_msintegerMinimum time before this rule answers the same chat again (default 60 000)priorityintegerRules are tried from the highest priority down; the first match answers (default 0)is_activeboolean | number | stringInactive rules never fire (default true)
Responses
- 200Updated
Response fields
okbooleanrequired
- 400Invalid body (
VALIDATION_FAILED,INVALID_JSON) or an unsafe regular expression (UNSAFE_REGEX) - 401Missing or invalid credentials
- 403The API key is restricted to other sessions, or the operation is not available to CS-agent logins
- 404Rule not found (
NOT_FOUND); unknown session, or a session of another tenant
Request
curl -X PATCH "https://api.chatkomodo.com/v1/sessions/YOUR_DEVICE_ID/auto-reply/RULE_ID" \
-H "Authorization: Bearer $CHATKOMODO_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"reply_body": "We are open Monday to Saturday, 9:00–18:00."
}'const res = await fetch('https://api.chatkomodo.com/v1/sessions/YOUR_DEVICE_ID/auto-reply/RULE_ID', {
method: 'PATCH',
headers: {
Authorization: `Bearer ${process.env.CHATKOMODO_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
"reply_body": "We are open Monday to Saturday, 9:00–18:00."
}),
});
const data = await res.json();
if (!res.ok) throw new Error(`${data.code}: ${data.error}`);
console.log(data);import os
import requests
res = requests.patch(
"https://api.chatkomodo.com/v1/sessions/YOUR_DEVICE_ID/auto-reply/RULE_ID",
headers={
"Authorization": f"Bearer {os.environ['CHATKOMODO_API_KEY']}",
},
json={
"reply_body": "We are open Monday to Saturday, 9:00–18:00.",
},
timeout=30,
)
res.raise_for_status()
print(res.json())<?php
require 'vendor/autoload.php';
$client = new GuzzleHttp\Client();
$res = $client->request('PATCH', 'https://api.chatkomodo.com/v1/sessions/YOUR_DEVICE_ID/auto-reply/RULE_ID', [
'headers' => [
'Authorization' => 'Bearer ' . getenv('CHATKOMODO_API_KEY'),
],
'json' => [
'reply_body' => 'We are open Monday to Saturday, 9:00–18:00.',
],
]);
print_r(json_decode((string) $res->getBody(), true));Response 200
{
"ok": true
}Delete an auto-reply rule
DEL
/v1/sessions/{sessionId}/auto-reply/{ruleId}Deletes the rule and its per-chat cooldown records.
Path parameters
sessionIdstringrequiredSession (device) idruleIdstringrequiredRule id
Responses
- 200Deleted
Response fields
okbooleanrequired
- 401Missing or invalid credentials
- 403The API key is restricted to other sessions, or the operation is not available to CS-agent logins
- 404Rule not found (
NOT_FOUND); unknown session, or a session of another tenant
Request
curl -X DELETE "https://api.chatkomodo.com/v1/sessions/YOUR_DEVICE_ID/auto-reply/RULE_ID" \
-H "Authorization: Bearer $CHATKOMODO_API_KEY"const res = await fetch('https://api.chatkomodo.com/v1/sessions/YOUR_DEVICE_ID/auto-reply/RULE_ID', {
method: 'DELETE',
headers: {
Authorization: `Bearer ${process.env.CHATKOMODO_API_KEY}`,
},
});
const data = await res.json();
if (!res.ok) throw new Error(`${data.code}: ${data.error}`);
console.log(data);import os
import requests
res = requests.delete(
"https://api.chatkomodo.com/v1/sessions/YOUR_DEVICE_ID/auto-reply/RULE_ID",
headers={
"Authorization": f"Bearer {os.environ['CHATKOMODO_API_KEY']}",
},
timeout=30,
)
res.raise_for_status()
print(res.json())<?php
require 'vendor/autoload.php';
$client = new GuzzleHttp\Client();
$res = $client->request('DELETE', 'https://api.chatkomodo.com/v1/sessions/YOUR_DEVICE_ID/auto-reply/RULE_ID', [
'headers' => [
'Authorization' => 'Bearer ' . getenv('CHATKOMODO_API_KEY'),
],
]);
print_r(json_decode((string) $res->getBody(), true));Response 200
{
"ok": true
}