Rules allow you to automatically perform actions on tickets when specific events occur. Rules are executed in the order of their priority
field, with the rules having the higher priority being executed first.
For example, you can use rules to automatically tag your tickets, assign agents, apply macros, send messages and more.
Rule properties
Rule example object
{
"id": 1234,
"code": "\nif (eq(ticket.from_agent, false) && eq(ticket.status, 'open')) {\n if (containsAny(message.intents.name, ['other/no_reply']) || containsAny(ticket.customer.email, [\n 'noreply@',\n '@noreply'\n ])) {\n Action('addTags', { tags: 'auto-close' });\n Action('setStatus', { status: 'closed' })\n }\n}\n",
"code_ast": {
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 10,
"column": 1
}
},
"type": "Program",
"body": [
{
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 10,
"column": 1
}
},
"type": "IfStatement",
"test": {
"loc": {
"start": {
"line": 2,
"column": 4
},
"end": {
"line": 2,
"column": 61
}
},
"type": "LogicalExpression",
"operator": "&&",
"left": {
"loc": {
"start": {
"line": 2,
"column": 4
},
"end": {
"line": 2,
"column": 32
}
},
"type": "CallExpression",
"callee": {
"loc": {
"start": {
"line": 2,
"column": 4
},
"end": {
"line": 2,
"column": 6
}
},
"type": "Identifier",
"name": "eq"
},
"arguments": [
{
"loc": {
"start": {
"line": 2,
"column": 7
},
"end": {
"line": 2,
"column": 24
}
},
"type": "MemberExpression",
"computed": false,
"object": {
"loc": {
"start": {
"line": 2,
"column": 7
},
"end": {
"line": 2,
"column": 13
}
},
"type": "Identifier",
"name": "ticket"
},
"property": {
"loc": {
"start": {
"line": 2,
"column": 14
},
"end": {
"line": 2,
"column": 24
}
},
"type": "Identifier",
"name": "from_agent"
}
},
{
"loc": {
"start": {
"line": 2,
"column": 26
},
"end": {
"line": 2,
"column": 31
}
},
"type": "Literal",
"value": false,
"raw": "false"
}
]
},
"right": {
"loc": {
"start": {
"line": 2,
"column": 36
},
"end": {
"line": 2,
"column": 61
}
},
"type": "CallExpression",
"callee": {
"loc": {
"start": {
"line": 2,
"column": 36
},
"end": {
"line": 2,
"column": 38
}
},
"type": "Identifier",
"name": "eq"
},
"arguments": [
{
"loc": {
"start": {
"line": 2,
"column": 39
},
"end": {
"line": 2,
"column": 52
}
},
"type": "MemberExpression",
"computed": false,
"object": {
"loc": {
"start": {
"line": 2,
"column": 39
},
"end": {
"line": 2,
"column": 45
}
},
"type": "Identifier",
"name": "ticket"
},
"property": {
"loc": {
"start": {
"line": 2,
"column": 46
},
"end": {
"line": 2,
"column": 52
}
},
"type": "Identifier",
"name": "status"
}
},
{
"loc": {
"start": {
"line": 2,
"column": 54
},
"end": {
"line": 2,
"column": 60
}
},
"type": "Literal",
"value": "open",
"raw": "'open'"
}
]
}
},
"consequent": {
"loc": {
"start": {
"line": 2,
"column": 63
},
"end": {
"line": 10,
"column": 1
}
},
"type": "BlockStatement",
"body": [
{
"loc": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 9,
"column": 5
}
},
"type": "IfStatement",
"test": {
"loc": {
"start": {
"line": 3,
"column": 8
},
"end": {
"line": 6,
"column": 10
}
},
"type": "LogicalExpression",
"operator": "||",
"left": {
"loc": {
"start": {
"line": 3,
"column": 8
},
"end": {
"line": 3,
"column": 61
}
},
"type": "CallExpression",
"callee": {
"loc": {
"start": {
"line": 3,
"column": 8
},
"end": {
"line": 3,
"column": 19
}
},
"type": "Identifier",
"name": "containsAny"
},
"arguments": [
{
"loc": {
"start": {
"line": 3,
"column": 20
},
"end": {
"line": 3,
"column": 40
}
},
"type": "MemberExpression",
"computed": false,
"object": {
"loc": {
"start": {
"line": 3,
"column": 20
},
"end": {
"line": 3,
"column": 35
}
},
"type": "MemberExpression",
"computed": false,
"object": {
"loc": {
"start": {
"line": 3,
"column": 20
},
"end": {
"line": 3,
"column": 27
}
},
"type": "Identifier",
"name": "message"
},
"property": {
"loc": {
"start": {
"line": 3,
"column": 28
},
"end": {
"line": 3,
"column": 35
}
},
"type": "Identifier",
"name": "intents"
}
},
"property": {
"loc": {
"start": {
"line": 3,
"column": 36
},
"end": {
"line": 3,
"column": 40
}
},
"type": "Identifier",
"name": "name"
}
},
{
"loc": {
"start": {
"line": 3,
"column": 42
},
"end": {
"line": 3,
"column": 60
}
},
"type": "ArrayExpression",
"elements": [
{
"loc": {
"start": {
"line": 3,
"column": 43
},
"end": {
"line": 3,
"column": 59
}
},
"type": "Literal",
"value": "other/no_reply",
"raw": "'other/no_reply'"
}
]
}
]
},
"right": {
"loc": {
"start": {
"line": 3,
"column": 65
},
"end": {
"line": 6,
"column": 10
}
},
"type": "CallExpression",
"callee": {
"loc": {
"start": {
"line": 3,
"column": 65
},
"end": {
"line": 3,
"column": 76
}
},
"type": "Identifier",
"name": "containsAny"
},
"arguments": [
{
"loc": {
"start": {
"line": 3,
"column": 77
},
"end": {
"line": 3,
"column": 98
}
},
"type": "MemberExpression",
"computed": false,
"object": {
"loc": {
"start": {
"line": 3,
"column": 77
},
"end": {
"line": 3,
"column": 92
}
},
"type": "MemberExpression",
"computed": false,
"object": {
"loc": {
"start": {
"line": 3,
"column": 77
},
"end": {
"line": 3,
"column": 83
}
},
"type": "Identifier",
"name": "ticket"
},
"property": {
"loc": {
"start": {
"line": 3,
"column": 84
},
"end": {
"line": 3,
"column": 92
}
},
"type": "Identifier",
"name": "customer"
}
},
"property": {
"loc": {
"start": {
"line": 3,
"column": 93
},
"end": {
"line": 3,
"column": 98
}
},
"type": "Identifier",
"name": "email"
}
},
{
"loc": {
"start": {
"line": 3,
"column": 100
},
"end": {
"line": 6,
"column": 9
}
},
"type": "ArrayExpression",
"elements": [
{
"loc": {
"start": {
"line": 4,
"column": 12
},
"end": {
"line": 4,
"column": 22
}
},
"type": "Literal",
"value": "noreply@",
"raw": "'noreply@'"
},
{
"loc": {
"start": {
"line": 5,
"column": 12
},
"end": {
"line": 5,
"column": 22
}
},
"type": "Literal",
"value": "@noreply",
"raw": "'@noreply'"
}
]
}
]
}
},
"consequent": {
"loc": {
"start": {
"line": 6,
"column": 12
},
"end": {
"line": 9,
"column": 5
}
},
"type": "BlockStatement",
"body": [
{
"loc": {
"start": {
"line": 7,
"column": 8
},
"end": {
"line": 7,
"column": 50
}
},
"type": "ExpressionStatement",
"expression": {
"loc": {
"start": {
"line": 7,
"column": 8
},
"end": {
"line": 7,
"column": 49
}
},
"type": "CallExpression",
"callee": {
"loc": {
"start": {
"line": 7,
"column": 8
},
"end": {
"line": 7,
"column": 14
}
},
"type": "Identifier",
"name": "Action"
},
"arguments": [
{
"loc": {
"start": {
"line": 7,
"column": 15
},
"end": {
"line": 7,
"column": 24
}
},
"type": "Literal",
"value": "addTags",
"raw": "'addTags'"
},
{
"loc": {
"start": {
"line": 7,
"column": 26
},
"end": {
"line": 7,
"column": 48
}
},
"type": "ObjectExpression",
"properties": [
{
"loc": {
"start": {
"line": 7,
"column": 28
},
"end": {
"line": 7,
"column": 46
}
},
"type": "Property",
"key": {
"loc": {
"start": {
"line": 7,
"column": 28
},
"end": {
"line": 7,
"column": 32
}
},
"type": "Identifier",
"name": "tags"
},
"computed": false,
"value": {
"loc": {
"start": {
"line": 7,
"column": 34
},
"end": {
"line": 7,
"column": 46
}
},
"type": "Literal",
"value": "auto-close",
"raw": "'auto-close'"
},
"kind": "init",
"method": false,
"shorthand": false
}
]
}
]
}
},
{
"loc": {
"start": {
"line": 8,
"column": 8
},
"end": {
"line": 8,
"column": 49
}
},
"type": "ExpressionStatement",
"expression": {
"loc": {
"start": {
"line": 8,
"column": 8
},
"end": {
"line": 8,
"column": 49
}
},
"type": "CallExpression",
"callee": {
"loc": {
"start": {
"line": 8,
"column": 8
},
"end": {
"line": 8,
"column": 14
}
},
"type": "Identifier",
"name": "Action"
},
"arguments": [
{
"loc": {
"start": {
"line": 8,
"column": 15
},
"end": {
"line": 8,
"column": 26
}
},
"type": "Literal",
"value": "setStatus",
"raw": "'setStatus'"
},
{
"loc": {
"start": {
"line": 8,
"column": 28
},
"end": {
"line": 8,
"column": 48
}
},
"type": "ObjectExpression",
"properties": [
{
"loc": {
"start": {
"line": 8,
"column": 30
},
"end": {
"line": 8,
"column": 46
}
},
"type": "Property",
"key": {
"loc": {
"start": {
"line": 8,
"column": 30
},
"end": {
"line": 8,
"column": 36
}
},
"type": "Identifier",
"name": "status"
},
"computed": false,
"value": {
"loc": {
"start": {
"line": 8,
"column": 38
},
"end": {
"line": 8,
"column": 46
}
},
"type": "Literal",
"value": "closed",
"raw": "'closed'"
},
"kind": "init",
"method": false,
"shorthand": false
}
]
}
]
}
}
]
},
"alternate": null
}
]
},
"alternate": null
}
],
"sourceType": "script"
},
"created_datetime": "2019-11-16T15:59:41.966927",
"deactivated_datetime": "2019-11-28T15:59:41.966927",
"description": "Automatically close all tickets from Amazon because there is nothing to do for them. We still want to keep them to be able to search.",
"event_types": "ticket-created,ticket-updated",
"name": "Auto-close all tickets from Amazon",
"priority": "100",
"updated_datetime": "2019-11-25T15:59:41.966927",
"uri": "/api/rules/1234/"
}