
elehiggle/claude3mattermostchatbotPrepare a Mattermost bot account token and Anthropic API key
Clone the repository:
bashgit clone [***] cd Claude3MattermostChatbot
Install the required dependencies:
bashpip3 install -r requirements.txt
Set the following environment variables with your own values:
| Parameter | Description |
|---|---|
AI_API_KEY | Required. Your Anthropic API key |
AI_MODEL | The Anthropic model to use. Default: "claude-3-5-sonnet-20240620" |
MATTERMOST_URL | Required. The URL of your Mattermost server |
MATTERMOST_TOKEN | Required if not using user/password. The bot token (alternatively personal access token) with relevant permissions created specifically for the chatbot. Don't forget to add the bot account to the team |
MATTERMOST_USERNAME | Required if not using token. The username of the dedicated Mattermost user account for the chatbot (if using username/password login) |
MATTERMOST_PASSWORD | Required if not using token. The password of the dedicated Mattermost user account for the chatbot (if using username/password login) |
MATTERMOST_MFA_TOKEN | The MFA token of the dedicated Mattermost user account for the chatbot (if using MFA) |
TOOL_USE_ENABLED | Allows tool function calling for live data and image generation. It works but its IMO poorly implemented in the Anthropic API and messes with the output and has extra cost. Default: "FALSE" |
| Parameter | Description |
|---|---|
AI_SYSTEM_PROMPT | The system prompt/instructions. Default: click (Subject to change. current_time and CHATBOT_USERNAME variables inside the prompt will be auto-formatted and substituted. |
AI_TIMEOUT | The timeout for the AI API call in seconds. Default: "120" |
MAX_TOKENS | The maximum number of tokens to generate in the response. Default: "8192" (max) |
TEMPERATURE | The temperature value for controlling the randomness of the generated responses (0.0 = analytical, 1.0 = fully random). Default: "0.15" |
TYPE_INDICATOR_MODE | "FULL" = typing indicator will be sent to main thread/channel and the subthread; "THREAD" = only to the subthread, unless there is none (this is kinda expected behaviour, but I prefer full). Default: "FULL" |
MAX_RESPONSE_SIZE_MB | The maximum size of the website or file content to extract (in megabytes, per URL/file). Default: "100" |
***_ENDPOINT | Endpoint URL to your *** instance (eg. "<[***]>"). If you use this, MAX_RESPONSE_SIZE_MB won't be honored since it can't stream content. For most effectiveness, use a residential IP endpoint |
BROWSER_EXECUTABLE_PATH | Path to a Chromium binary which is used for the raw_html_to_image function call capability. Fully optional. Chromium is auto installed on the docker image. Default: "/usr/bin/chromium" |
DISABLE_SPECIFIC_TOOL_CALLS | Disable certain function call tools like create_custom_emoji_by_url or get_exchange_rates. Supports multiple, separated by comma |
KEEP_ALL_URL_CONTENT | Whether to feed the AI all URL content from the whole conversation thread. The website result is cached in memory. If you only want it to know about the current message's URL content (due to context size or cost), set to "FALSE". Default: "TRUE" |
MATTERMOST_IGNORE_SENDER_ID | The user ID of a user to ignore (optional, useful if you have multiple chatbots that are not real bot accounts to prevent endless loops). Supports multiple, separated by comma |
MATTERMOST_PORT | The port of your Mattermost server. Default: "443" |
MATTERMOST_SCHEME | The scheme of the connection. Default: "https" |
MATTERMOST_BASEPATH | The basepath of your Mattermost server. Default: "/api/v4" |
MATTERMOST_CERT_VERIFY | Cert verification. Default: "TRUE" (also: path to your certificate file) |
MATTERMOST_TIMEOUT | The timeout for the Mattermost server in seconds. Default: "10" |
AI_API_BASEURL | AI API Base URL. Default: None (which will use "<[***]>"). Useful if you want to use a different AI with Anthropic compatible endpoint |
LOG_LEVEL | The log level. Default: "INFO" |
LOG_LEVEL_ROOT | The root log level (for other modules than this chatbot). Default: "INFO" |
Run the script:
bashpython3 chatbot.py
The chatbot will connect to the Mattermost server and start listening for messages. When a user mentions the chatbot in a message or sends a direct message to the chatbot, the chatbot will process the message, extract content from links (if any), process images, PDFs and other files, handle image content using the Vision API, and send the response back to the Mattermost channel.
Note: If you don't trust your users at all, it's recommended to disable the URL/image grabbing feature, even though the chatbot filters out local addresses and IPs.
You can also run the chatbot using Docker. Use the following command to run the chatbot container:
bashdocker run -d --name chatbotclaude \ -e AI_API_KEY="your_ai_api_key" \ -e AI_MODEL="claude-3-5-sonnet-20240620" \ -e MATTERMOST_URL="mattermostinstance.example.com" \ -e MATTERMOST_TOKEN="your_mattermost_token" \ -e MAX_TOKENS="4096" \ -e TEMPERATURE="0.15" \ ghcr.io/elehiggle/claude3mattermostchatbot:latest
!Mattermost Custom emoji bot example
The bot will take an image URL, optionally remove the background, and create a custom emoji on the Mattermost server with a provided or generated name.
The official Mattermost AI plugin is a great way to integrate AI into your Mattermost server with its own advantages, like a nice UI. However, the features differ greatly. It requires direct access to the server, whereas this bot merely needs a bot token and can be conveniently used in a Docker environment.
Also there is:
While the official plugin certainly will improve over time, this bot here will too and there will be certain features that will absolutely never make it into the official plugin, due to it primarily focusing on features for developers like function calling to retrieve GitHub issues, for example.
While the chatbot works great for me, there might still be some bugs lurking inside. I have done my best to address them, but if you encounter any issues, please let me know!
Please note that the monkey patch in the code is necessary due to some SSL errors that occur because of a mistake within the mattermostdriver library. The patch ensures that the chatbot can establish a secure connection with the Mattermost server.
OpenAI *** Mattermost Chatbot
Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.
This project is licensed under the MIT License.
探索更多轩辕镜像的使用方法,找到最适合您系统的配置方式
通过 Docker 登录认证访问私有仓库
在 Linux 系统配置镜像服务
在 Docker Desktop 配置镜像
Docker Compose 项目配置
Kubernetes 集群配置 Containerd
K3s 轻量级 Kubernetes 镜像加速
VS Code Dev Containers 配置
MacOS OrbStack 容器配置
在宝塔面板一键配置镜像
Synology 群晖 NAS 配置
飞牛 fnOS 系统配置镜像
极空间 NAS 系统配置服务
爱快 iKuai 路由系统配置
绿联 NAS 系统配置镜像
QNAP 威联通 NAS 配置
Podman 容器引擎配置
HPC 科学计算容器配置
ghcr、Quay、nvcr 等镜像仓库
无需登录使用专属域名
需要其他帮助?请查看我们的 常见问题Docker 镜像访问常见问题解答 或 提交工单
免费版仅支持 Docker Hub 访问,不承诺可用性和速度;专业版支持更多镜像源,保证可用性和稳定速度,提供优先客服响应。
专业版支持 docker.io、gcr.io、ghcr.io、registry.k8s.io、nvcr.io、quay.io、mcr.microsoft.com、docker.elastic.co 等;免费版仅支持 docker.io。
当返回 402 Payment Required 错误时,表示流量已耗尽,需要充值流量包以恢复服务。
通常由 Docker 版本过低导致,需要升级到 20.x 或更高版本以支持 V2 协议。
先检查 Docker 版本,版本过低则升级;版本正常则验证镜像信息是否正确。
使用 docker tag 命令为镜像打上新标签,去掉域名前缀,使镜像名称更简洁。
来自真实用户的反馈,见证轩辕镜像的优质服务