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