ChatGPTMattermostChatbot
An AI-powered Mattermost ChatGPT chatbot that utilizes the OpenAI API to provide helpful, contextual responses to user messages, extract text from links, and describe or generate images. With Docker support!
Install / Use
/learn @Elehiggle/ChatGPTMattermostChatbotREADME
ChatGPTMattermostChatbot

This project is a chatbot for Mattermost that integrates with the OpenAI API to provide helpful responses to user messages. The chatbot - like this readme - is mostly written by Claude 3 AI, listens for messages mentioning the chatbot or direct messages, processes the messages, and sends the responses back to the Mattermost channel. Also compatible with models o3-mini and possibly o1 (non-preview).
Features
- Responds to messages mentioning "@chatbot" (or rather the chatbot's username) or direct messages
- Extracts images, PDFs and other files from message attachments and from URL links in messages
- Supports FlareSolverr to bypass Javascript/CAPTCHA restrictions
- Supports DALL-E-3 image generation via function calling
- Supports the Vision API for describing images. Images from PDFs will also be sent here
- Gets transcripts of YouTube videos for easy tl;dw summarizations. Title, description and uploader are also provided
- Ability to create custom emoji from image URLs, optionally with removing the background
- Accesses additional live information via function calling (requires TOOL_USE_ENABLED="TRUE"). Currently supported: stock data (via Yahoo Finance, eg. ask about AAPL) cryptocurrency data ( via Coingecko), fiat currency exchange rates (via ECB)
- Sends screenshots of rendered raw HTML code or from URLs (via function calling).
- Maintains context of the conversation within a thread
- Sends typing indicators to show that the chatbot is processing the message
- Utilizes a thread pool to handle multiple requests concurrently (due to
mattermostdriver-asynciobeing outdated) - Offers Docker support for easy deployment
Prerequisites
- Python 3.11 or just a server with Docker (you can get away with using 3.8 if you use datetime.datetime.utcnow() instead of datetime.datetime.now(datetime.UTC))
- OpenAI API key
- Mattermost Bot token (alternatively personal access token or login/password for a dedicated Mattermost user account for the chatbot)
- The bot account needs to be added to the team and to the channels you want it to watch
Installation
-
Prepare a Mattermost bot account token and OpenAI API key
- Create an OpenAI API key here
- Create a Mattermost bot account token directly in the chat: Left menu -> Integrations -> Bot accounts. Give it the post:channels permission (this also suffices for DMs)
-
Clone the repository:
git clone https://github.com/Elehiggle/ChatGPTMattermostChatbot.git cd ChatGPTMattermostChatbot -
Install the required dependencies:
pip3 install -r requirements.txt -
Set the following environment variables with your own values:
| Parameter | Description |
|------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| AI_API_KEY | Required. Your OpenAI API key |
| AI_MODEL | The OpenAI model to use. Default: "gpt-4o" |
| 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. Slightly increased cost because input is filled with function definitions (roughly 0.15 cents per query, 0.0015 USD). Default: "TRUE" |
Extended optional configuration variables
| 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. For o1/o3 or other reasoning models, MAX_COMPLETION_TOKENS will be set to your configured value. Default: "16384" |
| TEMPERATURE | The temperature value for controlling the randomness of the generated responses (0.0 = analytical, 1.0 = fully random). Default: "1" |
| REASONING_EFFORT | Constrains effort on reasoning for reasoning models. Only supported on non-preview o1 and o3-mini. low, medium, high. Default: "medium" |
| IMAGE_SIZE | The image size for image generation. Default: "1024x1024" (see docs for allowed types) |
| IMAGE_QUALITY | The image quality for image generation. Default: "standard" (also: "hd") |
| IMAGE_STYLE | The image style for image generation. Default: "vivid" (also: "natural")
