|
| 1 | +# Connecting to Mattermost |
| 2 | + |
| 3 | +The Mattermost adapter connects to your Mattermost server through a Bot Token and WebSocket. After finishing the two parts below, AstrBot can send and receive messages in Mattermost channels and direct messages. |
| 4 | + |
| 5 | +## Create the AstrBot Mattermost Platform Adapter |
| 6 | + |
| 7 | +Go to the `Bots` page, click `+ Create Bot`, and choose `Mattermost`. |
| 8 | + |
| 9 | +On the configuration page, enable it first, then fill in: |
| 10 | + |
| 11 | +- `Mattermost URL`: your Mattermost server URL, for example `https://chat.example.com` |
| 12 | +- `Mattermost Bot Token`: the access token generated after creating a bot account in Mattermost |
| 13 | +- `Mattermost Reconnect Delay`: how long AstrBot waits before reconnecting after a WebSocket disconnect, default `5` |
| 14 | + |
| 15 | +Then click save. |
| 16 | + |
| 17 | +## Deploy Mattermost |
| 18 | + |
| 19 | +If you do not have a Mattermost server yet, use the official Mattermost Docker Compose repository: |
| 20 | + |
| 21 | +- Official docs: https://docs.mattermost.com/deployment-guide/server/containers/install-docker.html |
| 22 | +- Official repository: https://github.com/mattermost/docker |
| 23 | + |
| 24 | +The current quick-start flow recommended by Mattermost is: |
| 25 | + |
| 26 | +```bash |
| 27 | +git clone https://github.com/mattermost/docker |
| 28 | +cd docker |
| 29 | +cp env.example .env |
| 30 | +``` |
| 31 | + |
| 32 | +Then update at least these values in `.env`: |
| 33 | + |
| 34 | +- `DOMAIN` |
| 35 | +- `MATTERMOST_IMAGE_TAG` |
| 36 | +- It is also recommended to set `MM_SUPPORTSETTINGS_SUPPORTEMAIL` |
| 37 | + |
| 38 | +Create the data directories and set ownership: |
| 39 | + |
| 40 | +```bash |
| 41 | +mkdir -p ./volumes/app/mattermost/{config,data,logs,plugins,client/plugins,bleve-indexes} |
| 42 | +sudo chown -R 2000:2000 ./volumes/app/mattermost |
| 43 | +``` |
| 44 | + |
| 45 | +Choose one startup mode: |
| 46 | + |
| 47 | +Without the bundled NGINX: |
| 48 | + |
| 49 | +```bash |
| 50 | +docker compose -f docker-compose.yml -f docker-compose.without-nginx.yml up -d |
| 51 | +``` |
| 52 | + |
| 53 | +With the bundled NGINX: |
| 54 | + |
| 55 | +```bash |
| 56 | +docker compose -f docker-compose.yml -f docker-compose.nginx.yml up -d |
| 57 | +``` |
| 58 | + |
| 59 | +Access URLs: |
| 60 | + |
| 61 | +- Without NGINX: `http://your-domain:8065` |
| 62 | +- With NGINX: `https://your-domain` |
| 63 | + |
| 64 | +> [!TIP] |
| 65 | +> Mattermost currently states that production Docker support is Linux-only. macOS and Windows are better suited for development or testing. |
| 66 | +
|
| 67 | +## Create a Bot in Mattermost |
| 68 | + |
| 69 | +### 1. Enable Bot Account Creation |
| 70 | + |
| 71 | +Open the Mattermost system console: |
| 72 | + |
| 73 | +`System Console > Integrations > Bot Accounts` |
| 74 | + |
| 75 | +Enable `Enable Bot Account Creation`. |
| 76 | + |
| 77 | +### 2. Create the Bot Account |
| 78 | + |
| 79 | +Go to: |
| 80 | + |
| 81 | +`Product menu > Integrations > Bot Accounts` |
| 82 | + |
| 83 | +Click `Add Bot Account` and fill in: |
| 84 | + |
| 85 | +- `Username` |
| 86 | +- `Display Name` |
| 87 | +- `Description` |
| 88 | + |
| 89 | +After creation, copy the generated Bot Token. It is shown only once. Paste it into AstrBot's `Mattermost Bot Token` field. |
| 90 | + |
| 91 | +### 3. Add the Bot to a Channel |
| 92 | + |
| 93 | +Add the bot to the channel where AstrBot should work. Otherwise the bot will not be able to properly receive and send messages in that channel. |
| 94 | + |
| 95 | +## How to Fill in Mattermost URL |
| 96 | + |
| 97 | +`Mattermost URL` should be the external URL of your Mattermost server, without a trailing slash. For example: |
| 98 | + |
| 99 | +```text |
| 100 | +https://chat.example.com |
| 101 | +``` |
| 102 | + |
| 103 | +If you are only testing locally, you can also use: |
| 104 | + |
| 105 | +```text |
| 106 | +http://127.0.0.1:8065 |
| 107 | +``` |
| 108 | + |
| 109 | +If both AstrBot and Mattermost run in containers, prefer an address reachable from the AstrBot container, such as the Mattermost service name on the same Docker network. |
| 110 | + |
| 111 | +## Start and Verify |
| 112 | + |
| 113 | +After saving the AstrBot platform adapter configuration: |
| 114 | + |
| 115 | +1. Make sure the AstrBot logs do not show Mattermost authentication or WebSocket connection errors. |
| 116 | +2. Send a message in a channel that includes the bot, or send the bot a direct message. |
| 117 | +3. If AstrBot replies normally, the integration is working. |
| 118 | + |
| 119 | +## Common Issues |
| 120 | + |
| 121 | +### Invalid Token Errors |
| 122 | + |
| 123 | +Usually one of these: |
| 124 | + |
| 125 | +- You copied a user token instead of the bot token |
| 126 | +- The token contains extra spaces |
| 127 | +- The bot account was deleted or the token was regenerated |
| 128 | + |
| 129 | +### Connected but No Channel Messages Arrive |
| 130 | + |
| 131 | +Check these first: |
| 132 | + |
| 133 | +- The bot has been added to the target channel |
| 134 | +- `Mattermost URL` points to an address AstrBot can actually reach |
| 135 | +- Your Mattermost reverse proxy forwards WebSocket traffic correctly |
| 136 | + |
| 137 | +### Mattermost Opens in Browser but AstrBot Still Cannot Connect |
| 138 | + |
| 139 | +If AstrBot runs in a container while `Mattermost URL` is set to `localhost` or `127.0.0.1`, AstrBot will connect to itself instead of the Mattermost service. In that case, switch to an address reachable inside the Docker network. |
0 commit comments