Skip to content

Commit

Permalink
update docs to use ghcr docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
yGuy committed Mar 20, 2023
1 parent 9800941 commit 568ca25
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 16 deletions.
68 changes: 53 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,60 @@
# A ChatGPT-powered Chatbot for Mattermost

There's a nice detailed guide about how to do all of the steps below written by @InterestingSoup, [here: Create a ChatGPT bot on Mattermost](https://interestingsoup.com/create-a-chatgpt-bot-on-mattermost/)
Here's how to get the bot running - it's easy if you have a Docker server.

Here's the short version - it's easy if you have a Docker container.
You need
- the [Mattermost token](https://docs.mattermost.com/integrations/cloud-bot-accounts.html) for the bot user `@chatgpt`
- the [Mattermost token](https://docs.mattermost.com/integrations/cloud-bot-accounts.html) for the bot user (`@chatgpt` by default)
- the [OpenAI API key](https://platform.openai.com/account/api-keys)
- a Docker container for continuously running the service
- a [Docker](https://www.docker.com/) server for continuously running the service, alternatively for testing, Node.js is sufficient.

There's a guide about how to do the first two steps written by @InterestingSoup, [here](https://interestingsoup.com/create-a-chatgpt-bot-on-mattermost/) (lots of ads on that page, just block them, ignore them, or keep on reading and try without their screenshots!)

## Options

These are the available options, you can set them as environment variables when running [the script](./src/botservice.js)
or when [running the docker image](#using-the-ready-made-image) or when configuring your [docker-compose](#docker-compose) file.

| Name | Required | Example Value | Description |
|---------------------|----------|-----------------------------|----------------------------------------------------------------------------------------------|
| MATTERMOST_URL | yes | `https://mattermost.server` | The URL to the server. This is used for connecting the bot to the Mattermost API |
| MATTERMOST_TOKEN | yes | `abababacdcdcd` | The authentication token from the logged in mattermost bot |
| OPENAI_API_KEY | yes | `sk-234234234234234234` | The OpenAI API key to authenticate with OpenAI |
| NODE_EXTRA_CA_CERTS | no | `/file/to/cert.crt` | a link to a certificate file to pass to node.js for authenticating self-signed certificates |
| MATTERMOST_BOTNAME | no | `"@chatgpt"` | the name of the bot user in Mattermost, defaults to '@chatgpt' |
| DEBUG_LEVEL | no | `TRACE` | a debug level used for logging activity, defaults to `INFO` |


## Using the ready-made image

Use the prebuilt image from [`ghcr.io/yguy/chatgpt-mattermost-bot`](https://ghcr.io/yguy/chatgpt-mattermost-bot)

```bash
docker run -d --restart unless-stopped \
-e MATTERMOST_URL=https://mattermost.server \
-e MATTERMOST_TOKEN=abababacdcdcd \
-e OPENAI_API_KEY=234234234234234234 \
--name chatbot \
ghcr.io/yguy/chatgpt-mattermost-bot:latest
```

## Building the docker image yourself

First step is to clone this repo.

```bash
git clone https://github.com/yGuy/chatgpt-mattermost-bot.git && cd chatgpt-mattermost-bot
```

For testing, you could now just run `npm install` and `npm run start` or `node src/botservice.js` directly, but be sure to set the below environment variables or pass them to the node process, first!
For testing, you could now just run `npm install` and `npm run start` or `node src/botservice.js` directly, but be sure to set the [environment variables](#options) or pass them to the node process, first!

For production use, in order to create a service on a docker container that will always provide the service without you having to run it on your own PC, you can do the following:

## Docker
Create the docker image
Build the docker image from the [Dockerfile](./Dockerfile):
```bash
docker build . -t yguy/chatgpt-mattermost-bot
```

Run Docker service
Create and run a container from the image
```bash
docker run -d --restart unless-stopped \
-e MATTERMOST_URL=https://mattermost.server \
Expand All @@ -34,7 +64,12 @@ docker run -d --restart unless-stopped \
yguy/chatgpt-mattermost-bot
```

With a custom certificate stored in `/absolutepath/to/certfile.crt´ for your mattermost instance (if required for locally hosted mattermost instances on https) you can do it like so
### Private TLS Certificate
If your Mattermost instance uses a TLS certificate signed by a private CA, you
will need to provide the CA's public root to the container for validation.

If the root certificate is located at `/absolutepath/to/certfile.crt`, then you
can mount that file into the container at a fixed position and specify the [node environment variable](https://nodejs.org/api/cli.html#node_extra_ca_certsfile) accordingly:
```bash
docker run -d --restart unless-stopped \
-v /absolutepath/to/certfile.crt:/certs/certfile.crt \
Expand All @@ -57,7 +92,8 @@ docker stop chatbot
```

## Docker Compose
Edit the environment variables in `docker-compose.yml`.
If you want to run docker compose (maybe even merge it with your mattermost docker stack), you can use this
as a starting point: First adjust the environment variables in `docker-compose.yml`.

### Required Environment Variables
```yaml
Expand Down Expand Up @@ -115,13 +151,15 @@ docker compose down
Here's an example chat that I just had with our bot:

>@yguy:
>@chatgpt - please write a short introductory paragraph for the README in the GitHub repo that hosts the sources for you, the friendly Mattermost bot. Tell the readers that you enjoy working for the nice people at yWorks and that everybody should install a Mattermost chatbot into their Mattermost chat system to benefit from a nice and helpful assistant like you are. I will include this in the README on the GitHub repo, so make this an engaging text! Thanks!
>>@chatgpt - please write a short introductory paragraph for the README in the GitHub repo that hosts the sources for you, the friendly Mattermost bot. Tell the readers that you enjoy working for the nice people at yWorks and that everybody should install a Mattermost chatbot into their Mattermost chat system to benefit from a nice and helpful assistant like you are. I will include this in the README on the GitHub repo, so make this an engaging text! Thanks!
>chatgpt (BOT)
>Hello there! I'm @chatgpt, a friendly and reliable Mattermost bot designed to make your communication experience smoother and more efficient. I'm honored to be part of the team at yWorks, where I help employees get things done faster and with less hassle. With my advanced machine learning algorithms, I'm capable of understanding complex natural language queries and providing succinct and accurate responses in a matter of seconds. Whether you're a developer looking for information on your codebase or a manager seeking to streamline your team's workflows, I'm here to help. Installing a Mattermost chatbot like me is a must for any organization looking to boost its productivity and enjoy a more pleasant communication experience. So what are you waiting for? Let's chat!
>chatgpt (BOT):
>>Hello there! I'm @chatgpt, a friendly and reliable Mattermost bot designed to make your communication experience smoother and more efficient. I'm honored to be part of the team at yWorks, where I help employees get things done faster and with less hassle. With my advanced machine learning algorithms, I'm capable of understanding complex natural language queries and providing succinct and accurate responses in a matter of seconds. Whether you're a developer looking for information on your codebase or a manager seeking to streamline your team's workflows, I'm here to help. Installing a Mattermost chatbot like me is a must for any organization looking to boost its productivity and enjoy a more pleasant communication experience. So what are you waiting for? Let's chat!

I built this tool as a quick hack on a rainy Saturday afternoon, but we are using the bot in production in our Mattermost instance at our office at [yworks](https://www.yworks.com) and the bot has proved to be very helpful for many simple tasks. Give it a try and provide feedback if you like! It's really not very expensive: We had it runnning for about 30 users for two weeks and that cost us less than half a dollar for the ChatGPT service!

I built this tool as a quick hack on a rainy Saturday afternoon, but we are using the bot in production in our Mattermost instance at our office at [yworks](https://www.yworks.com) and the bot has proved to be very helpful for many simple tasks. Give it a try and provide feedback if you like! I might also accept helpful pull requests if you find an issue or have an idea for an improvement.
I will also accept helpful pull requests if you find an issue or have an idea for an improvement.

Last but not least check out yWorks' fine diagramming tools for software developers [yFiles](https://yworks.com/yfiles) and our [free online graph editors](https://yworks.com/editors)!
Last but not least, check out [yWorks](https://www.yworks.com)' fine diagramming SDKs for software developers [yFiles](https://yworks.com/yfiles) and our [free online graph and diagram editors](https://yworks.com/editors)!

This is under MIT license Copyright (c) 2023 Sebastian Mueller (yWorks)
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: '3.7'

services:
chatbot:
image: yguy/chatgpt-mattermost-bot:latest
image: ghcr.io/yguy/chatgpt-mattermost-bot:latest
build: .
restart: unless-stopped
environment:
Expand Down

0 comments on commit 568ca25

Please sign in to comment.