In November 2022 OpenAI launched their AI-driven chatbot called ChatGPT. It swept the world fast and started to be implemented via API into anything that it can be used with.
From websites, search engines, chat platforms even personal assistants, everyone wants to be able to elevate current solutions with some AI power. On that note, the Mattermost chat platform is also a perfect candidate for this implementation.
Considering that I use Mattermost as my Synology support platform I have decided to give it a go.
One of the first things needed in order to make this happen is to have a Mattermost instance up and running. I'm self-hosting it using Docker, and more details on that can be found on the following link.
Prerequisites for ChatGPT and Mattermost integration
In order to get this running there are several steps that need to be executed. I will follow through and list them all. First, prerequisites.
- the Mattermost token for the bot user @chatgpt
- the OpenAI API key
- a Docker container for continuously running the service
These are the three elements needed so let's see how to configure each of them, starting with creating the Mattermost chatgpt bot.
Create a Mattermost bot account
Once there is a functional Mattermost instance up and running it is time to make the bot. Like with any other bot, the process is the same.
In the upper left menu of Mattermost we choose Integrations > Bot Accounts > Add Bot account.
Fill in the needed information, add a bot icon (not mandatory), and make sure to configure the username of the bot as chatgpt. If you want to use a different name then that will need to be changed inside the
src/botservice.js file inside the repo before pulling it and making it into a Docker image!
Create an OpenAI API key
- Next, go to Open AI platform, register/log in, and in the API Keys section, click Create new Secret Key.
- Save the OpenAI API Key that is generated, and store it safely as it will also be used as one of the Docker variables.
Deploy the ChatGPT container
Finally, we need to run the Docker container. To do that we first need to a) build the image from the GitHub repository, or use the image that I have already built and uploaded to the official HUB.
If you want to use the already-built image then just use the following
docker-compose either via the Docker command line or using Portainer and its stacks feature.
version: "3" services: chatgp: image: blackvoidclub/chatgpt-mattermost-bot:latest container_name: chatgpt environment: - MATTERMOST_URL=https://mattermost.server - MATTERMOST_TOKEN=xxxxxxxxxxxxxxxx - OPENAI_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx restart: always
MATTERMOST_URL variable needs to have a valid Mattermost instance URL.
MATTERMOST_TOKEN will have the ChatGPT bot ID that was generated upon creation. Finally,
OPENAI_API_KEY needs to have the value of the secret key generated on the OpenAI website.
There are several optional variables as well, so add them if you want.
# Set this if using a custom username for the bot, default = @chatgpt MATTERMOST_BOTNAME: "@chatgpt" # Console logging output level, default = INFO DEBUG_LEVEL: TRACE # Node environment, default = production NODE_ENV: production
If on the other hand, you want to build your own image before running it using the same compose as above, just a different name of the image, do the following on your Docker-capable machine.
- Clone the repo
git clone https://github.com/yGuy/chatgpt-mattermost-bot
- Go into repo directory
- Create docker image
docker build . -t yguy/chatgpt-mattermost-bot
That's it. Everything should be up and running and if all the parameters are set correctly we should be able to have chatGPT running inside Mattermost.
How to use ChatGPT bot in Mattermost?
Interact with the ChatGPT bot in Mattermost, as with any other member of the chat platform. Be sure to tag its name in order to initiate a response.
In case you want it to work in any channel, first, add it as a member of your Mattermost team. Then, add it to the specific channels that you want.
There we have it. Mattermost instance using a ChatGPT AI bot to enrich the experience. The GPT is a separate docker container, and any updates to it will require a rebuild of the image as the source code changes.