|
1 | | -# bolt-python-search-template |
2 | | -A template for implementing enterprise search in Bolt for Python |
| 1 | +# Bolt for Python Search Template |
| 2 | + |
| 3 | +> ⚠️ **Beta Notice**: This template demonstrates search functionality that is currently in beta and not yet widely available to all developers. The features shown here are being tested and may change before general availability. |
| 4 | +
|
| 5 | +This is a Slack app template for building search functionality using Bolt for Python. It demonstrates how to create custom functions for search and filtering capabilities. |
| 6 | + |
| 7 | +It's recommended to use a [Slack sandbox](https://docs.slack.dev/tools/developer-sandboxes/) for development and testing. Other workspaces may not have access to all these features. To get started: |
| 8 | + |
| 9 | +1. Join the [Slack Developer Program](https://api.slack.com/developer-program) if you haven't already |
| 10 | +2. [Provision a sandbox workspace](https://docs.slack.dev/tools/developer-sandboxes/#provision) |
| 11 | + |
| 12 | +## Installation |
| 13 | + |
| 14 | +### Using Slack CLI |
| 15 | + |
| 16 | +Install the latest version of the Slack CLI for your operating system: |
| 17 | + |
| 18 | +- [Slack CLI for macOS & Linux](https://docs.slack.dev/tools/slack-cli/guides/installing-the-slack-cli-for-mac-and-linux/) |
| 19 | +- [Slack CLI for Windows](https://docs.slack.dev/tools/slack-cli/guides/installing-the-slack-cli-for-windows/) |
| 20 | + |
| 21 | +You'll also need to log in if this is your first time using the Slack CLI. |
| 22 | + |
| 23 | +```sh |
| 24 | +slack login |
| 25 | +``` |
| 26 | + |
| 27 | +#### Initializing the project |
| 28 | + |
| 29 | +```sh |
| 30 | +slack create bolt-python-search --template slack-samples/bolt-python-search-template |
| 31 | +cd bolt-python-search |
| 32 | + |
| 33 | +# Setup your python virtual environment |
| 34 | +python3 -m venv .venv |
| 35 | +source .venv/bin/activate |
| 36 | + |
| 37 | +# Install the dependencies |
| 38 | +pip install -e . |
| 39 | +``` |
| 40 | + |
| 41 | +#### Creating the Slack app |
| 42 | + |
| 43 | +```sh |
| 44 | +slack install |
| 45 | +``` |
| 46 | + |
| 47 | +#### Running the app |
| 48 | + |
| 49 | +```sh |
| 50 | +slack run |
| 51 | +``` |
| 52 | + |
| 53 | +<details> |
| 54 | +<summary><h3>Using Terminal</h3></summary> |
| 55 | + |
| 56 | +1. Open [https://api.slack.com/apps/new](https://api.slack.com/apps/new) and choose "From an app manifest" |
| 57 | +2. Choose the workspace you want to install the application to |
| 58 | +3. 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_ |
| 59 | +4. Review the configuration and click _Create_ |
| 60 | +5. Click _Install to Workspace_ and _Allow_ on the screen that follows. You'll then be redirected to the App Configuration dashboard. |
| 61 | + |
| 62 | +#### Environment Variables |
| 63 | + |
| 64 | +Before you can run the app, you'll need to store some environment variables. |
| 65 | + |
| 66 | +1. Open your apps configuration page from this list, click **OAuth & Permissions** in the left hand menu, then copy the Bot User OAuth Token. You will store this in your environment as `SLACK_BOT_TOKEN`. |
| 67 | +2. 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`. |
| 68 | + |
| 69 | +```zsh |
| 70 | +# Replace with your app token and bot token |
| 71 | +export SLACK_BOT_TOKEN=<your-bot-token> |
| 72 | +export SLACK_APP_TOKEN=<your-app-token> |
| 73 | +``` |
| 74 | + |
| 75 | +### Setup Your Local Project |
| 76 | + |
| 77 | +```sh |
| 78 | +# Clone this project onto your machine |
| 79 | +git clone https://github.com/slack-samples/bolt-python-search-template.git |
| 80 | + |
| 81 | +# Change into this project directory |
| 82 | +cd bolt-python-search-template |
| 83 | + |
| 84 | +# Setup your python virtual environment |
| 85 | +python3 -m venv .venv |
| 86 | +source .venv/bin/activate |
| 87 | + |
| 88 | +# Install all the dependencies |
| 89 | +pip install -e . |
| 90 | + |
| 91 | +# Start your local server |
| 92 | +python3 app.py |
| 93 | +``` |
| 94 | + |
| 95 | +</details> |
| 96 | + |
| 97 | +## Linting |
| 98 | + |
| 99 | +```sh |
| 100 | +# Run ruff from root directory for linting |
| 101 | +ruff check |
| 102 | + |
| 103 | +# Run ruff from root directory for formatting |
| 104 | +ruff format && ruff check --fix |
| 105 | +``` |
| 106 | + |
| 107 | +## Testing |
| 108 | + |
| 109 | +```sh |
| 110 | +# Run pytest from root directory for unit testing |
| 111 | +pytest . |
| 112 | +``` |
| 113 | + |
| 114 | +## Project Structure |
| 115 | + |
| 116 | +### `manifest.json` |
| 117 | + |
| 118 | +`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. |
| 119 | + |
| 120 | +### `app.py` |
| 121 | + |
| 122 | +`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. |
| 123 | + |
| 124 | +### `/listeners` |
| 125 | + |
| 126 | +Every incoming request is routed to a "listener". Inside this directory, we group each listener based on the Slack Platform feature used, so `/listeners/events` handles incoming [Events](https://docs.slack.dev/reference/events) requests, `/listeners/functions` handles [custom steps](https://docs.slack.dev/tools/bolt-js/concepts/custom-steps) and so on. |
| 127 | + |
| 128 | +### `/test` |
| 129 | + |
| 130 | +The `/test` directory contains the test suite for this project. It mirrors the structure of the source code, with test files corresponding to their implementation counterparts. For example, tests for files in `/listeners/functions` are located in `/test/listeners/functions`. |
0 commit comments