{"id":21072838,"url":"https://github.com/yguy/chatgpt-mattermost-bot","last_synced_at":"2025-05-07T18:09:20.911Z","repository":{"id":148760956,"uuid":"610341921","full_name":"yGuy/chatgpt-mattermost-bot","owner":"yGuy","description":"A very simple implementation of a service for a mattermost bot that uses ChatGPT in the backend.","archived":false,"fork":false,"pushed_at":"2024-03-19T10:01:45.000Z","size":375,"stargazers_count":155,"open_issues_count":15,"forks_count":54,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-05-07T18:08:15.392Z","etag":null,"topics":["chatbot","chatgpt","chatgpt-bot","mattermost-bot","mattermost-plugin"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yGuy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"license.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-06T15:24:56.000Z","updated_at":"2025-03-19T06:42:20.000Z","dependencies_parsed_at":"2025-01-03T09:12:26.736Z","dependency_job_id":"43bc9036-2323-4ca8-883e-cc431b870a6e","html_url":"https://github.com/yGuy/chatgpt-mattermost-bot","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yGuy%2Fchatgpt-mattermost-bot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yGuy%2Fchatgpt-mattermost-bot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yGuy%2Fchatgpt-mattermost-bot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yGuy%2Fchatgpt-mattermost-bot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yGuy","download_url":"https://codeload.github.com/yGuy/chatgpt-mattermost-bot/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252931535,"owners_count":21827111,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chatbot","chatgpt","chatgpt-bot","mattermost-bot","mattermost-plugin"],"created_at":"2024-11-19T18:59:11.082Z","updated_at":"2025-05-07T18:09:20.887Z","avatar_url":"https://github.com/yGuy.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# A ChatGPT-powered Chatbot for Mattermost\n\n![A chat window in Mattermost showing the chat between the OpenAI bot and \"yGuy\"](./mattermost-chat.png)\n\nThe bot can talk to you like a regular mattermost user. It's like having chat.openai.com built collaboratively built into Mattermost!\nBut that's not all, you can also use it to generate images via Dall-E or diagram visualizations via a yFiles plugin! \n\nHere's how to get the bot running - it's easy if you have a Docker host.\n\nYou need\n - the [Mattermost token](https://docs.mattermost.com/integrations/cloud-bot-accounts.html) for the bot user (`@chatgpt` by default)\n - the [OpenAI API key](https://platform.openai.com/account/api-keys)\n - a [Docker](https://www.docker.com/) server for continuously running the service, alternatively for testing, Node.js 16 is sufficient.\n\nAndrew Zigler from Mattermost created a [YouTube Video](https://www.youtube.com/watch?v=Hx4Ex7YZZiA) that quickly guides you through the setup.\n\nIf you want to learn more about how this plugin came to live, [read the blog post at yWorks.com](https://www.yworks.com/blog/diagramming-with-chatgpt)!\n\n\n## Options\n\nThese are the available options, you can set them as environment variables when running [the script](./src/botservice.ts)\nor when [running the docker image](#using-the-ready-made-docker-image) or when configuring your [docker-compose](#docker-compose) file.\n\n| Name                 | Required | Example Value                | Description                                                                                                                                                                                        |\n|----------------------|----------|------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| MATTERMOST_URL       | yes      | `https://mattermost.server`  | The URL to the server. This is used for connecting the bot to the Mattermost API                                                                                                                   |\n| MATTERMOST_TOKEN     | yes      | `abababacdcdcd`              | The authentication token from the logged in mattermost bot                                                                                                                                         |\n| OPENAI_API_KEY       | yes      | `sk-234234234234234234`      | The OpenAI API key to authenticate with OpenAI                                                                                                                                                     |\n| OPENAI_API_BASE      | no       | `http://example.com:8080/v1` | The address of an OpenAI compatible API. Overrides the default base path (`https://api.openai.com`)          |\n| OPENAI_MODEL_NAME    | no       | `gpt-3.5-turbo`              | The OpenAI language model to use, defaults to `gpt-3.5-turbo`                                                                                                                                      |\n| OPENAI_MAX_TOKENS    | no       | `2000`                       | The maximum number of tokens to pass to the OpenAI API, defaults to 2000                                                                                                                           |\n| OPENAI_TEMPERATURE   | no       | `0.2`                        | The sampling temperature to use, between 0 and 2, defaults to 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. |\n| YFILES_SERVER_URL    | no       | `http://localhost:3835`      | The URL to the yFiles graph service for embedding auto-generated diagrams.                                                                                                                         |\n| 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                                                                                                        |\n| MATTERMOST_BOTNAME   | no       | `\"@chatgpt\"`                 | the name of the bot user in Mattermost, defaults to '@chatgpt'                                                                                                                                     |\n| PLUGINS              | no       | `graph-plugin, image-plugin` | The enabled plugins of the bot. By default all plugins (grpah-plugin and image-plugin) are enabled.                                                                                                |\n| DEBUG_LEVEL          | no       | `TRACE`                      | a debug level used for logging activity, defaults to `INFO`                                                                                                                                        |\n| BOT_CONTEXT_MSG      | no       | `15`                         | The number of previous messages which are appended to the conversation with ChatGPT, defaults to 100                                                                                               |\n| BOT_INSTRUCTION      | no       | `Act like Elon Musk`         | Extra instruction to give your assistance. How should the assistant behave? |\n\n\u003e **Note**\n\u003e The `YFILES_SERVER_URL` is used for automatically converting text information created by the bot into diagrams.\n\u003e This is currently in development. You can see it in action, here: \n\u003e [LinkedIn Post](https://www.linkedin.com/posts/yguy_chatgpt-yfiles-diagramming-activity-7046713027005407232-2bKH)\n\u003e If you are interested in getting your hands on the plugin, please contact [yWorks](https://www.yworks.com)!\n\n## Using the ready-made Docker image\n\nUse the prebuilt image from [`ghcr.io/yguy/chatgpt-mattermost-bot`](https://ghcr.io/yguy/chatgpt-mattermost-bot)\n\n```bash\ndocker run -d --restart unless-stopped \\\n  -e MATTERMOST_URL=https://mattermost.server \\\n  -e MATTERMOST_TOKEN=abababacdcdcd \\\n  -e OPENAI_API_KEY=234234234234234234 \\\n  --name chatbot \\\n  ghcr.io/yguy/chatgpt-mattermost-bot:latest\n```\n\n## Building the Docker image manually\n\nFirst step is to clone this repo.\n\n```bash\ngit clone https://github.com/yGuy/chatgpt-mattermost-bot.git \u0026\u0026 cd chatgpt-mattermost-bot\n```\n\nFor testing, you could now just run `npm install` and `npm run start` directly, but be sure to set the [environment variables](#options)  or pass them to the node process, first! \n\nFor 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 machine, you can do the following:\n\nBuild the docker image from the [Dockerfile](./Dockerfile):\n```bash\ndocker build . -t yguy/chatgpt-mattermost-bot\n```\n\nCreate and run a container from the image\n```bash\ndocker run -d --restart unless-stopped \\\n  -e MATTERMOST_URL=https://mattermost.server \\\n  -e MATTERMOST_TOKEN=abababacdcdcd \\\n  -e OPENAI_API_KEY=234234234234234234 \\\n  --name chatbot \\\n  yguy/chatgpt-mattermost-bot\n```\n\n### Private TLS Certificate\nIf your Mattermost instance uses a TLS certificate signed by a private CA, you\nwill need to provide the CA's public root to the container for validation.\n\nIf the root certificate is located at `/absolutepath/to/certfile.crt`, then you\ncan 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:\n```bash\ndocker run -d --restart unless-stopped \\\n  -v /absolutepath/to/certfile.crt:/certs/certfile.crt \\\n  -e NODE_EXTRA_CA_CERTS=/certs/certfile.crt \\\n  -e MATTERMOST_URL=https://mattermost.server \\\n  -e MATTERMOST_TOKEN=abababacdcdcd \\\n  -e OPENAI_API_KEY=234234234234234234 \\\n  --name chatbot \\\n  yguy/chatgpt-mattermost-bot\n```\n\nVerify it's running\n```bash\ndocker ps\n```\n\nLater, to stop the service\n```bash\ndocker stop chatbot\n```\n\n## Docker Compose\nIf you want to run docker compose (maybe even merge it with your mattermost docker stack), you can use this \nas a starting point: First adjust the environment variables in `docker-compose.yml`.\n\n### Required Environment Variables\n```yaml\nMATTERMOST_URL: https://mattermost.server\nMATTERMOST_TOKEN: abababacdcdcd\nOPENAI_API_KEY: sk-234234234234234234\n```\n\n### Optional Environment Variables\n```yaml\n# Set this if using a custom username for the bot, default = @chatgpt\nMATTERMOST_BOTNAME: \"@chatgpt\"\n\n# Console logging output level, default = INFO\nDEBUG_LEVEL: TRACE\n\n# Node environment, default = production\nNODE_ENV: production\n```\n\n### Private TLS Certificate\nIf your Mattermost instance uses a TLS certificate signed by a private CA, you\nwill need to provide the CA's public root to the container for validation.\n\nIf the root certificate is located at `/absolutepath/to/certfile.crt`, then you\nwould merge the contents below into the `docker-compose.yml` file:\n```yaml\nservices:\n  chatbot:\n    volumes:\n      - /absolutepath/to/certfile.crt:/certs/certfile.crt:ro\n    environment:\n      NODE_EXTRA_CA_CERTS: /certs/certfile.crt\n```\n\n### Run the container as a service\nWhen all configuration is complete, start the container service.\n```bash\ndocker compose up -d\n```\n\nVerify it's running:\n```bash\ndocker compose ps\n```\n\nTo stop the container:\n```bash\ndocker compose down\n```\n\n\n## Deploy to Kubernetes with Helm\nThe chatgpt-mattermost-bot chart deploys a containerized chatgpt-mattermost-bot instance which will connect to a running mattermost container in the same kubernetes cluster.  Chart uses 'mattermost-team-edition' and the 'mattermost' namespace by default.  Uses environment variables MATTERMOST_TOKEN and OPENAI_API_KEY. \n```bash\nhelm upgrade chatgpt-mattermost-bot ./helm/chatgpt-mattermost-bot \\\n  --create-namespace \\\n  --install \\\n  -n mattermost \\\n  -f ./helm/chatgpt-mattermost-bot/values.yaml \\\n  --set config.MATTERMOST_TOKEN=\"$MATTERMOST_TOKEN\" \\\n  --set config.OPENAI_API_KEY=\"$OPENAI_API_KEY\"\n```\n\n## Example Conversation\n\nHere's an example chat that I just had with our bot:\n\n\u003e@yguy:\n\u003e\u003e@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!\n\t\n\u003echatgpt (BOT):\n\u003e\u003eHello 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!\n\nI 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 running for about 30 users for two weeks and that cost us less than half a dollar for the ChatGPT service! \n\nI will also accept helpful pull requests if you find an issue or have an idea for an improvement.\n\nLast 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)!\n\nThis is under MIT license Copyright (c) 2023 Sebastian Mueller (yWorks) and Michael Haeglsperger (yWorks)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyguy%2Fchatgpt-mattermost-bot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyguy%2Fchatgpt-mattermost-bot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyguy%2Fchatgpt-mattermost-bot/lists"}