Skip to content

Commit bb0ebff

Browse files
clean
0 parents  commit bb0ebff

26 files changed

Lines changed: 1039 additions & 0 deletions

.github/CODEOWNERS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Code owners are the default owners for everything in
2+
# this repository. The owners listed below will be requested for
3+
# review when a pull request is opened.
4+
# To add code owner(s), uncomment the line below and
5+
# replace the @global-owner users with their GitHub username(s).
6+
# * @global-owner1 @global-owner2

.github/dependabot.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "pip"
4+
directory: "/"
5+
schedule:
6+
interval: "monthly"
7+
labels:
8+
- "pip"
9+
- "dependencies"
10+
- package-ecosystem: "github-actions"
11+
directory: "/"
12+
schedule:
13+
interval: "monthly"
14+
labels:
15+
- "dependencies"

.github/workflows/lint.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Linting validation using ruff
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
8+
jobs:
9+
lint:
10+
runs-on: ubuntu-latest
11+
timeout-minutes: 5
12+
strategy:
13+
matrix:
14+
python-version: ["3.13"]
15+
16+
steps:
17+
- uses: actions/checkout@v5
18+
- name: Set up Python ${{ matrix.python-version }}
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: ${{ matrix.python-version }}
22+
- name: Install dependencies
23+
run: |
24+
pip install -U pip
25+
pip install .
26+
- name: Lint with ruff
27+
run: |
28+
ruff check

.github/workflows/tests.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Run all the unit tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
timeout-minutes: 5
12+
strategy:
13+
matrix:
14+
python-version: ["3.11", "3.12", "3.13"]
15+
16+
steps:
17+
- uses: actions/checkout@v5
18+
- name: Set up Python ${{ matrix.python-version }}
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: ${{ matrix.python-version }}
22+
- name: Install dependencies
23+
run: |
24+
pip install -U pip
25+
pip install .
26+
- name: Run all tests
27+
run: |
28+
pytest .

.gitignore

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# general things to ignore
2+
build/
3+
dist/
4+
docs/_sources/
5+
docs/.doctrees
6+
.eggs/
7+
*.egg-info/
8+
*.egg
9+
*.py[cod]
10+
__pycache__/
11+
*.so
12+
*~
13+
14+
# virtualenv
15+
env*/
16+
venv/
17+
.venv*
18+
.env*
19+
20+
# codecov / coverage
21+
.coverage
22+
cov_*
23+
coverage.xml
24+
25+
# due to using pytest, tox or ruff
26+
.tox
27+
.cache
28+
.pytest_cache/
29+
.python-version
30+
pip
31+
.mypy_cache/
32+
.ruff_cache
33+
34+
# misc
35+
tmp.txt
36+
.DS_Store
37+
logs/
38+
*.db
39+
.pytype/
40+
.vscode
41+
.cursor

.slack/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
apps.dev.json
2+
cache/
3+
config.json

.slack/hooks.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"hooks": {
3+
"get-hooks": "python3 -m slack_cli_hooks.hooks.get_hooks"
4+
}
5+
}

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023- Slack Technologies, LLC
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
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`.

app.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import logging
2+
import os
3+
4+
from slack_bolt import App
5+
from slack_bolt.adapter.socket_mode import SocketModeHandler
6+
7+
from listeners import register_listeners
8+
9+
logging.basicConfig(level=logging.DEBUG)
10+
11+
app = App(token=os.environ.get("SLACK_BOT_TOKEN"))
12+
13+
register_listeners(app)
14+
15+
if __name__ == "__main__":
16+
SocketModeHandler(app, os.environ.get("SLACK_APP_TOKEN")).start()

0 commit comments

Comments
 (0)