summaryrefslogtreecommitdiff
path: root/example/messaging.jsonc
blob: 649d7ee40cf64048c4b844fde5eb7a158a7aec80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
{
    "remotes": [
        {
            "type": "telegram",
            "id": "Telegram",    // this endpoint is identified with "remote:Telegram"
            "enabled": true,     // default: true, if set to false, this remote will be ignored
            "token": "================TOKEN================",
            "chat_id": 12345678  // repeat to and from this chat
        },
        {
            "type": "psmb",            // psmb is a special case, since it is not an endpoint
            "id": "mypsmb",            // this stub endpoint is identified with "remote:mypsmb"
            "enabled": true,           // but it creates zero or one or more than one sub "virtual" endpoints
            "host": "1.onesmp.org",
            "port": 3456,
            "subscribe_to": "chat_.+", // psmb subscription pattern
                                       // for example: if you have topic chat_1 and chat_2
                                       // then they are identified with "remote:mypsmb:chat_1" and "remote:mypsmb:chat_2"
                                       // dispatching messages from "remote:mypsmb" to virtual endpoints
                                       // such as "remote:mypsmb:chat_1", is done by psmb stub endpoint
            "topics": [                // all topics this endpoint can actually "see"
                "chat_qq",             // regexp in "subscribe_to" and action route "to"
                "chat_wechat"          // will only match endpoints declared in this list
            ]
        },
        {
            "type": "json-rpc",
            "id": "rpc",
            "enabled": true,
            "listen": ["127.0.0.1", 8008],
            "methods": {
                "get": "getMessage",
                "put": "sendMessage"
            }
        }
    ],
    "routing": [
        // all rules are processed sequentially
        // a message may match multiple rules and thus may be duplicate in your case
        // if the message is dropped in an action in one rule,
        // (the action type is just "drop" and it does not have any argument)
        // all subsequent rules will NOT see this message
        {
            // inbound chat messages (remote -> all servers)
            "object": "chat_message", // match chat messages
            "from": "remote:.*",      // regexp matching source,
                                      // only messages with matched source will be
                                      // processed by this rule, otherwise this rule is skipped
            "actions": [{
                "type": "format",
                "color": "green"
            }, {                      // actions run sequentially
                "type": "route",      // route this message to matched destinations
                "to": "server:.*"     // regexp matching destination  
            }]
        },
        {
            // outbound messages (starting with '#', server -> all remotes)
            "object": "chat_message",
            "from": "server:.*",
            "actions": [{
                "type": "filter",     // filter the message using given regexp
                                      // if the message does not match given pattern,
                                      // it won't be passed into subsequent actions
                "pattern": "#.+"      // match all messages starts with char '#'
            }, {
                "type": "replace",    // replace the message, removing heading '#'
                "from": "^#(.*)",     // capture all chars after the heading '#'
                "to": "$1"            // and make them as the output
            }, {
                "type": "route",      // send the message to all remotes
                "to": "remote:.*"
            }]
        },
        {
            // cross-server messages (server -> all other servers)
            "object": "chat_message",
            "from": "server:.*",
            "actions": [{
                "type": "route",
                "to": "server:.*",
                "backflow": false      // do not repeat to sender, true by default
                                       // since the destination pattern will match the source,
                                       // we have to set backflow to false to prevent
                                       // players from seeing duplicate messages
            }]
        }
    ]
}