Thumbnail

rani/matterbridge.git

Clone URL: https://git.buni.party/rani/matterbridge.git

Viewing file on branch master

1Tengo can be used for advanced scripting in matterbridge, you can modify incoming and outgoing messages.
2
3You can also use it to modify the `{TENGO}` parameter in the `RemoteNickFormat`.
4
5```
6[tengo]
7InMessage="yourscript.tengo"
8OutMessage="yourotherscript.tengo"
9RemoteNickFormat="remotenickformat.tengo"
10```
11
12More information about tengo on: https://github.com/d5/tengo/blob/master/docs/tutorial.md and https://github.com/d5/tengo/blob/master/docs/stdlib.md
13
14FIXME: Document support for [dropping messages](https://github.com/42wim/matterbridge/pull/1272).
15
16## InMessage
17
18InMessage allows you to specify the location of a tengo (https://github.com/d5/tengo/) script.
19This script will receive every incoming message and can be used to modify the Username and the Text of that message.
20
21The script will have the following global variables: \
22to modify: `msgUsername` and `msgText` \
23to read: `msgChannel` and `msgAccount`
24
25The script is reloaded on every message, so you can modify the script on the fly.
26
27Example script can be found in https://github.com/42wim/matterbridge/tree/master/gateway/bench.tengo
28and https://github.com/42wim/matterbridge/tree/master/contrib/example.tengo
29
30The example below will check if the text contains blah and if so, it'll replace the text and the username of that message.
31```
32text := import("text")
33if text.re_match("blah",msgText) {
34 msgText="replaced by this"
35 msgUsername="fakeuser"
36}
37```
38
39`InMessage="example.tengo"`
40
41## OutMessage
42
43OutMessage allows you to specify the location of the script that will be invoked on each message being sent to a bridge and can be used to modify the Username and the Text of that message.
44
45The script will have the following global variables: \
46read-only: \
47`inAccount`, `inProtocol`, `inChannel`, `inGateway`, `inEvent` \
48`outAccount`, `outProtocol`, `outChannel`, `outGateway`, `outEvent` \
49
50read-write: \
51`msgText`, `msgUsername`
52
53The script is reloaded on every message, so you can modify the script on the fly.
54
55The default script in <https://github.com/42wim/matterbridge/tree/master/internal/tengo/outmessage.tengo>
56is compiled in and will be executed if no script is specified.
57
58`OutMessage="example.tengo"`
59
60## RemoteNickFormat
61
62RemoteNickFormat allows you to specify the location of a tengo (https://github.com/d5/tengo/) script.
63
64The script will have the following global variables: \
65to modify: `result` \
66to read: `channel`, `bridge`, `gateway`, `protocol`, `nick`
67
68The result will be set in `{TENGO}` in the RemoteNickFormat key of every bridge where `{TENGO}` is specified
69
70The script is reloaded on every message, so you can modify the script on the fly.
71
72Example script can be found in <https://github.com/42wim/matterbridge/tree/master/contrib/remotenickformat.tengo>
73
74`RemoteNickFormat="remotenickformat.tengo"`
75
76## More information
77
78You can find more tengo examples/info here:
79- <https://github.com/42wim/matterbridge/issues?q=is%3Aissue+tengo+label%3Atengo+is%3Aclosed>
80- <https://github.com/42wim/matterbridge/tree/master/internal/tengo>
81- <https://github.com/42wim/matterbridge/tree/master/contrib>
82- <https://github.com/42wim/matterbridge/wiki/settings#tengo>
83
84The tengo documentation can be found here: <https://github.com/d5/tengo/tree/master/docs>