{"id":26289960,"url":"https://github.com/slack-samples/bolt-python-ai-chatbot","last_synced_at":"2025-05-07T22:43:49.758Z","repository":{"id":252449057,"uuid":"836237140","full_name":"slack-samples/bolt-python-ai-chatbot","owner":"slack-samples","description":"Bring AI into your workspace using a chatbot powered by Anthropic and OpenAI","archived":false,"fork":false,"pushed_at":"2025-05-01T17:39:22.000Z","size":49,"stargazers_count":62,"open_issues_count":5,"forks_count":27,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-05-01T18:38:31.198Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","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/slack-samples.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-07-31T12:35:04.000Z","updated_at":"2025-05-01T17:39:26.000Z","dependencies_parsed_at":"2024-09-16T22:16:00.977Z","dependency_job_id":"3b1b37f7-62f4-445d-a27c-f7b301fa3257","html_url":"https://github.com/slack-samples/bolt-python-ai-chatbot","commit_stats":null,"previous_names":["slack-samples/bolt-python-ai-chatbot"],"tags_count":0,"template":false,"template_full_name":"slack-samples/bolt-python-starter-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slack-samples%2Fbolt-python-ai-chatbot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slack-samples%2Fbolt-python-ai-chatbot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slack-samples%2Fbolt-python-ai-chatbot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slack-samples%2Fbolt-python-ai-chatbot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/slack-samples","download_url":"https://codeload.github.com/slack-samples/bolt-python-ai-chatbot/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252967973,"owners_count":21833245,"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":[],"created_at":"2025-03-14T23:17:29.151Z","updated_at":"2025-05-07T22:43:49.720Z","avatar_url":"https://github.com/slack-samples.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Slack AI Chatbot\n\nThis Slack chatbot app template offers a customizable solution for integrating AI-powered conversations into your Slack workspace. Here's what the app can do out of the box:\n\n* Interact with the bot by mentioning it in conversations and threads\n* Send direct messages to the bot for private interactions\n* Use the `/ask-bolty` command to communicate with the bot in channels where it hasn't been added\n* Utilize a custom function for integration with Workflow Builder to summarize messages in conversations\n* Select your preferred API/model from the app home to customize the bot's responses\n* Bring Your Own Language Model [BYO LLM](#byo-llm) for customization\n* Custom FileStateStore creates a file in /data per user to store API/model preferences\n\nInspired by [ChatGPT-in-Slack](https://github.com/seratch/ChatGPT-in-Slack/tree/main)\n\nBefore getting started, make sure you have a development workspace where you have permissions to install apps. If you don’t have one setup, go ahead and [create one](https://slack.com/create).\n## Installation\n\n#### Prerequisites\n* To use the OpenAI and Anthropic models, you must have an account with sufficient credits.\n* To use the Vertex models, you must have [a Google Cloud Provider project](https://cloud.google.com/vertex-ai/generative-ai/docs/start/quickstarts/quickstart-multimodal#expandable-1) with sufficient credits.\n\n#### Create a Slack App\n1. Open [https://api.slack.com/apps/new](https://api.slack.com/apps/new) and choose \"From an app manifest\"\n2. Choose the workspace you want to install the application to\n3. Copy the contents of [manifest.json](./manifest.json) into the text box that says `*Paste your manifest code here*` (within the JSON tab) and click *Next*\n4. Review the configuration and click *Create*\n5. Click *Install to Workspace* and *Allow* on the screen that follows. You'll then be redirected to the App Configuration dashboard.\n\n#### Environment Variables\nBefore you can run the app, you'll need to store some environment variables.\n\n1. Open your apps configuration page from this list, click **OAuth \u0026 Permissions** in the left hand menu, then copy the Bot User OAuth Token. You will store this in your environment as `SLACK_BOT_TOKEN`.\n2. Click **Basic Information** from the left hand menu and follow the steps in the App-Level Tokens section to create an app-level token with the `connections:write` scope. Copy this token. You will store this in your environment as `SLACK_APP_TOKEN`.\n\nNext, set the gathered tokens as environment variables using the following commands:\n\n```zsh\n# MacOS/Linux\nexport SLACK_BOT_TOKEN=\u003cyour-bot-token\u003e\nexport SLACK_APP_TOKEN=\u003cyour-app-token\u003e\n```\n\n```pwsh\n# Windows\nset SLACK_BOT_TOKEN=\u003cyour-bot-token\u003e\nset SLACK_APP_TOKEN=\u003cyour-app-token\u003e\n```\n\nDifferent models from different AI providers are available if the corresponding environment variable is added, as shown in the sections below.\n\n##### Anthropic Setup\n\nTo interact with Anthropic models, navigate to your Anthropic account dashboard to [create an API key](https://console.anthropic.com/settings/keys), then export the key as follows:\n\n```zsh\nexport ANTHROPIC_API_KEY=\u003cyour-api-key\u003e\n```\n\n##### Google Cloud Vertex AI Setup\n\nTo use Google Cloud Vertex AI, [follow this quick start](https://cloud.google.com/vertex-ai/generative-ai/docs/start/quickstarts/quickstart-multimodal#expandable-1) to create a project for sending requests to the Gemini API, then gather [Application Default Credentials](https://cloud.google.com/docs/authentication/provide-credentials-adc) with the strategy to match your development environment.\n\nOnce your project and credentials are configured, export environment variables to select from Gemini models:\n\n```zsh\nexport VERTEX_AI_PROJECT_ID=\u003cyour-project-id\u003e\nexport VERTEX_AI_LOCATION=\u003clocation-to-deploy-model\u003e\n```\n\nThe project location can be located under the **Region** on the [Vertex AI](https://console.cloud.google.com/vertex-ai) dashboard, as well as more details about available Gemini models.\n\n##### OpenAI Setup\n\nUnlock the OpenAI models from your OpenAI account dashboard by clicking [create a new secret key](https://platform.openai.com/api-keys), then export the key like so:\n\n```zsh\nexport OPENAI_API_KEY=\u003cyour-api-key\u003e\n```\n\n### Setup Your Local Project\n```zsh\n# Clone this project onto your machine\ngit clone https://github.com/slack-samples/bolt-python-ai-chatbot.git\n\n# Change into this project directory\ncd bolt-python-ai-chatbot\n\n# Setup your python virtual environment\npython3 -m venv .venv\nsource .venv/bin/activate\n\n# Install the dependencies\npip install -r requirements.txt\n\n# Start your local server\npython3 app.py\n```\n\n#### Linting\n```zsh\n# Run flake8 from root directory for linting\nflake8 *.py \u0026\u0026 flake8 listeners/\n\n# Run black from root directory for code formatting\nblack .\n```\n\n## Project Structure\n\n### `manifest.json`\n\n`manifest.json` is a configuration for Slack apps. With a manifest, you can create an app with a pre-defined configuration, or adjust the configuration of an existing app.\n\n\n### `app.py`\n\n`app.py` is the entry point for the application and is the file you'll run to start the server. This project aims to keep this file as thin as possible, primarily using it as a way to route inbound requests.\n\n\n### `/listeners`\n\nEvery incoming request is routed to a \"listener\". Inside this directory, we group each listener based on the Slack Platform feature used, so `/listeners/commands` handles incoming [Slash Commands](https://api.slack.com/interactivity/slash-commands) requests, `/listeners/events` handles [Events](https://api.slack.com/apis/events-api) and so on.\n\n### `/ai`\n\n* `ai_constants.py`: Defines constants used throughout the AI module.\n\n\u003ca name=\"byo-llm\"\u003e\u003c/a\u003e\n#### `ai/providers`\nThis module contains classes for communicating with different API providers, such as [Anthropic](https://www.anthropic.com/), [OpenAI](https://openai.com/), and [Vertex AI](cloud.google.com/vertex-ai). To add your own LLM, create a new class for it using the `base_api.py` as an example, then update `ai/providers/__init__.py` to include and utilize your new class for API communication.\n\n* `__init__.py`: \nThis file contains utility functions for handling responses from the provider APIs and retrieving available providers.\n\n### `/state_store`\n\n* `user_identity.py`: This file defines the UserIdentity class for creating user objects. Each object represents a user with the user_id, provider, and model attributes.\n\n* `user_state_store.py`: This file defines the base class for FileStateStore.\n\n* `file_state_store.py`: This file defines the FileStateStore class which handles the logic for creating and managing files for each user.\n\n* `set_user_state.py`: This file creates a user object and uses a FileStateStore to save the user's selected provider to a JSON file.\n\n* `get_user_state.py`: This file retrieves a users selected provider from the JSON file created with `set_user_state.py`.\n\n## App Distribution / OAuth\n\nOnly implement OAuth if you plan to distribute your application across multiple workspaces. A separate `app_oauth.py` file can be found with relevant OAuth settings.\n\nWhen using OAuth, Slack requires a public URL where it can send requests. In this template app, we've used [`ngrok`](https://ngrok.com/download). Checkout [this guide](https://ngrok.com/docs#getting-started-expose) for setting it up.\n\nStart `ngrok` to access the app on an external network and create a redirect URL for OAuth. \n\n```\nngrok http 3000\n```\n\nThis output should include a forwarding address for `http` and `https` (we'll use `https`). It should look something like the following:\n\n```\nForwarding   https://3cb89939.ngrok.io -\u003e http://localhost:3000\n```\n\nNavigate to **OAuth \u0026 Permissions** in your app configuration and click **Add a Redirect URL**. The redirect URL should be set to your `ngrok` forwarding address with the `slack/oauth_redirect` path appended. For example:\n\n```\nhttps://3cb89939.ngrok.io/slack/oauth_redirect\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslack-samples%2Fbolt-python-ai-chatbot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fslack-samples%2Fbolt-python-ai-chatbot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslack-samples%2Fbolt-python-ai-chatbot/lists"}