| 1 | # Tengo |
| 2 | 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 |
| 3 | |
| 4 | FIXME: Document support for [dropping messages](https://github.com/42wim/matterbridge/pull/1272). |
| 5 | |
| 6 | ## InMessage |
| 7 | InMessage allows you to specify the location of a tengo (https://github.com/d5/tengo/) script. |
| 8 | This script will receive every incoming message and can be used to modify the Username and the Text of that message. |
| 9 | The script will have the following global variables: \ |
| 10 | to modify: `msgUsername` and `msgText` \ |
| 11 | to read: `msgChannel` and `msgAccount` |
| 12 | |
| 13 | The script is reloaded on every message, so you can modify the script on the fly. |
| 14 | |
| 15 | Example script can be found in https://github.com/42wim/matterbridge/tree/master/gateway/bench.tengo |
| 16 | and https://github.com/42wim/matterbridge/tree/master/contrib/example.tengo |
| 17 | |
| 18 | The example below will check if the text contains blah and if so, it'll replace the text and the username of that message. |
| 19 | ``` |
| 20 | text := import("text") |
| 21 | if text.re_match("blah",msgText) { |
| 22 | msgText="replaced by this" |
| 23 | msgUsername="fakeuser" |
| 24 | } |
| 25 | ``` |
| 26 | |
| 27 | Setting: OPTIONAL, RELOADABLE \ |
| 28 | Format: string |
| 29 | Example: |
| 30 | |
| 31 | `InMessage="example.tengo"` |
| 32 | |
| 33 | ## OutMessage |
| 34 | OutMessage allows you to specify the location of the script that |
| 35 | will be invoked on each message being sent to a bridge and can be used to modify the Username |
| 36 | and the Text of that message. |
| 37 | |
| 38 | The script will have the following global variables: |
| 39 | read-only: |
| 40 | `inAccount`, `inProtocol`, `inChannel`, `inGateway`, `inEvent` |
| 41 | `outAccount`, `outProtocol`, `outChannel`, `outGateway`, `outEvent` |
| 42 | |
| 43 | read-write: |
| 44 | `msgText`, `msgUsername` |
| 45 | |
| 46 | Notice: `msgUsername` is already formatted by [RemoteNickFormat](https://github.com/42wim/matterbridge/wiki/Settings#remotenickformat) at this point. |
| 47 | |
| 48 | The script is reloaded on every message, so you can modify the script on the fly. |
| 49 | |
| 50 | The default script in https://github.com/42wim/matterbridge/tree/master/internal/tengo/outmessage.tengo |
| 51 | is compiled in and will be executed if no script is specified. |
| 52 | |
| 53 | **Tengo scripts on a docker instance** |
| 54 | Place your scripts in `/etc/matterbridge` on the container and reference them with `OutMessage="/etc/matterbridge/example.tengo"` |
| 55 | |
| 56 | Setting: OPTIONAL, RELOADABLE \ |
| 57 | Format: string |
| 58 | Example: |
| 59 | |
| 60 | `OutMessage="example.tengo"` |
| 61 | |
| 62 | ## RemoteNickFormat |
| 63 | RemoteNickFormat allows you to specify the location of a tengo (https://github.com/d5/tengo/) script. |
| 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 | Setting: OPTIONAL, RELOADABLE \ |
| 75 | Format: string \ |
| 76 | Example: |
| 77 | |
| 78 | `RemoteNickFormat="remotenickformat.tengo"` |
| 79 | |