2026-07-08 15:23:34 +08:00
# Build a Mattermost AI Agent with nanobot
2026-10-10 11:48:50 +08:00
This guide connects nanobot to Mattermost through the built-in Mattermost channel, using WebSocket events and the Mattermost REST API.
2026-07-08 15:23:34 +08:00
## What this guide builds
- a Mattermost bot account or token
- the `mattermost` channel enabled in nanobot
- mention-only group behavior for first deployment
2026-07-08 15:58:43 +08:00
- one pairing-approved DM or mention test
2026-07-08 15:23:34 +08:00
## Prerequisites
- A working local nanobot reply:
```bash
nanobot agent -m "Hello!"
```
- A Mattermost server URL.
- A bot token or personal access token for the bot account.
## Install nanobot
```bash
python -m pip install nanobot-ai
nanobot onboard --wizard
```
## Enable the Mattermost channel
Merge this snippet into `~/.nanobot/config.json` :
```json
{
"channels" : {
"mattermost" : {
"enabled" : true ,
"serverUrl" : "https://mattermost.example.com" ,
"token" : "YOUR_MATTERMOST_TOKEN" ,
"teamId" : "YOUR_TEAM_ID" ,
"groupPolicy" : "mention" ,
2026-08-04 19:00:36 +08:00
"groupPolicyInThread" : "open" ,
2026-07-08 15:58:43 +08:00
"replyInThread" : true ,
"dm" : {
"policy" : "allowlist"
}
2026-07-08 15:23:34 +08:00
}
}
}
```
2026-10-10 11:48:50 +08:00
`teamId` scopes the channel to a Mattermost team. Keep `groupPolicy` as `mention` for the first test. `groupPolicyInThread` can be `"mention"` , `"open"` , or `"allowlist"` and controls messages that reply inside a thread. If it is omitted, it inherits `groupPolicy` , preserving the behavior of existing configurations. Set it to `"open"` explicitly when follow-up messages in threads should not require another @mention .
2026-08-04 19:00:36 +08:00
2026-10-10 11:48:50 +08:00
When `groupPolicy` is `"allowlist"` , `groupAllowFrom` remains the outer channel boundary for root posts and thread replies. A thread policy cannot open a channel that is not on that allowlist.
2026-07-08 15:23:34 +08:00
2026-10-10 11:48:50 +08:00
Mattermost DMs are open by default. Setting `dm.policy` to `"allowlist"` with no `dm.allowFrom` entries makes new DM senders receive a pairing code. Approve the code before using the bot normally.
2026-07-08 15:58:43 +08:00
2026-07-08 15:23:34 +08:00
## Run nanobot gateway
```bash
nanobot channels status
nanobot gateway
```
## Test a message
2026-10-10 11:48:50 +08:00
DM the bot account. It should return a pairing code. Approve it from a trusted local surface:
2026-07-08 15:58:43 +08:00
```bash
nanobot agent -m "/pairing approve ABCD-EFGH"
```
Then DM the bot again, or mention it in a channel where the bot has access:
2026-07-08 15:23:34 +08:00
```text
@nanobot Hello from Mattermost
```
## Security notes
- Store the Mattermost token in an environment variable for deployed services.
2026-07-08 15:58:43 +08:00
- Keep `dm.policy` as `"allowlist"` when you want pairing-based approval.
2026-07-08 15:23:34 +08:00
- Use mention-only group behavior before opening the bot to busy channels.
- Review file and shell tools before inviting broad channel access.
## Troubleshooting
2026-10-10 11:48:50 +08:00
- If startup logs say `serverUrl and token must be configured` , check the camelCase config keys.
2026-07-08 15:58:43 +08:00
- If DMs are ignored, review the `dm` policy and pairing approval state.
2026-10-10 11:48:50 +08:00
- If channel messages are ignored, confirm the bot is mentioned and belongs to the team/channel.
- If thread replies are surprising, review `groupPolicyInThread` , `replyInThread` , and `includeThreadContext` .
2026-07-08 15:23:34 +08:00
## Next: memory, automations, MCP tools
- [Chat Apps reference ](../chat-apps.md )
- [Pairing ](../configuration.md#pairing )
- [Long-running AI Agent ](./long-running-ai-agent.md )
- [Deployment ](../deployment.md )