generated from slack-samples/bolt-python-custom-step-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from slack-samples/Initial-poc-with-workflow
feat: make it work with OAuth 2
- Loading branch information
Showing
41 changed files
with
1,091 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
JIRA_BASE_URL=http://localhost:8080 | ||
SECRET_HEADER_KEY=My-Header | ||
SECRET_HEADER_VALUE=a123 | ||
JIRA_CLIENT_ID=abc134 | ||
JIRA_CLIENT_SECRET=abc134 | ||
APP_BASE_URL=https://this-si-my-app | ||
APP_HOME_PAGE_URL=slack://app?team={TEAM_ID}&id={APP_ID}&tab=home |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Linting validation using ruff | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 5 | ||
strategy: | ||
matrix: | ||
python-version: ["3.12"] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
pip install -U pip | ||
pip install -r requirements.txt | ||
- name: Lint with ruff | ||
run: | | ||
ruff check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Testing with pytest | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 5 | ||
strategy: | ||
matrix: | ||
python-version: ["3.10", "3.11", "3.12"] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
pip install -U pip | ||
pip install -r requirements.txt | ||
- name: Test with pytest | ||
run: | | ||
pytest tests/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,3 +36,8 @@ tmp.txt | |
logs/ | ||
*.db | ||
.pytype/ | ||
|
||
#tmp | ||
.slack/apps.dev.json | ||
data | ||
.ruff_cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,113 @@ | ||
# Bolt for Python Automation Template App | ||
# Bolt for Python Jira Functions | ||
|
||
This is a generic Bolt for Python template app used to build out Slack automations. | ||
This is a Bolt for Python app used to interact with Jira Server. | ||
|
||
Before 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). | ||
Before 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). | ||
|
||
## Installation | ||
|
||
#### Create a Slack App | ||
### Install the Slack CLI | ||
|
||
1. Open [https://api.slack.com/apps/new](https://api.slack.com/apps/new) and choose "From an app manifest" | ||
2. Choose the workspace you want to install the application to | ||
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* | ||
4. Review the configuration and click *Create* | ||
5. Click *Install to Workspace* and *Allow* on the screen that follows. You'll then be redirected to the App Configuration dashboard. | ||
To use this template, you need to install and configure the Slack CLI. | ||
Step-by-step instructions can be found in our | ||
[Quickstart Guide](https://api.slack.com/automation/quickstart). | ||
|
||
#### Environment Variables | ||
|
||
Before you can run the app, you'll need to store some environment variables. | ||
|
||
1. Rename `.env.sample` to `.env` | ||
2. Open your apps configuration page from [this list](https://api.slack.com/apps), click *OAuth & Permissions* in the left hand menu, then copy the *Bot User OAuth Token* into your `.env` file under `SLACK_BOT_TOKEN` | ||
3. 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 that token into your `.env` as `SLACK_APP_TOKEN`. | ||
|
||
### Setup Your Local Project | ||
### Create a Slack App | ||
|
||
```zsh | ||
# Clone this project onto your machine | ||
git clone https://github.com/slack-samples/bolt-python-automation-template.git | ||
slack create my-app -t slack-samples/bolt-python-jira-functions | ||
|
||
# Change into this project directory | ||
cd bolt-python-automation-template | ||
# Change into the project directory | ||
cd my-app | ||
|
||
# Set up virtual environment | ||
python3 -m venv .venv | ||
source .venv/bin/activate | ||
|
||
# Install dependencies | ||
pip install -r requirements.txt | ||
``` | ||
|
||
### Environment Variables | ||
|
||
Before you can run the app, you'll need to store some environment variables. | ||
|
||
1. Rename `.example.env` to `.env` | ||
2. Follow these | ||
[Jira Instruction](https://confluence.atlassian.com/adminjiraserver0909/configure-an-incoming-link-1251415519.html) | ||
to create an external application and get the `Client ID` (`JIRA_CLIENT_ID`) | ||
and `Client secret` (`JIRA_CLIENT_SECRET`) values. | ||
3. Populate the other environment variable value with proper values. | ||
|
||
### Running Your Project Locally | ||
|
||
You'll know an app is the development version if the name has the string | ||
`(local)` appended. | ||
|
||
```zsh | ||
# Run Bolt server | ||
slack run | ||
|
||
INFO:slack_bolt.App:Starting to receive messages from a new connection | ||
``` | ||
|
||
To stop running locally, press `<CTRL> + C` to end the process. | ||
|
||
#### Linting | ||
|
||
```zsh | ||
# Run flake8 from root directory for linting | ||
flake8 *.py | ||
# Run ruff from root directory for linting | ||
ruff check | ||
|
||
# Run ruff from root directory for code formatting | ||
ruff format | ||
ruff check --fix | ||
``` | ||
|
||
## Testing | ||
|
||
# Run black from root directory for code formatting | ||
black . | ||
For an example of how to test a function, see | ||
`tests/functions/test_create_issue.py`. | ||
|
||
Run all tests with: | ||
|
||
```zsh | ||
pytest tests/ | ||
``` | ||
|
||
## Project Structure | ||
|
||
### `.slack/` | ||
|
||
Contains `apps.dev.json` and `apps.json`, which include installation details for | ||
development and deployed apps. | ||
|
||
### `manifest.json` | ||
|
||
`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. | ||
`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. | ||
|
||
### `app.py` | ||
|
||
`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. | ||
`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. | ||
|
||
### `/listeners` | ||
|
||
Every incoming request is routed to a "listener". Inside this directory, we | ||
group each listener based on the Slack Platform feature used, so | ||
`/listeners/shortcuts` handles incoming | ||
[Shortcuts](https://api.slack.com/interactivity/shortcuts) requests, | ||
`/listeners/views` handles | ||
[View submissions](https://api.slack.com/reference/interaction-payloads/views#view_submission) | ||
and so on. | ||
|
||
### `slack.json` | ||
|
||
Used by the CLI to interact with the project's SDK dependencies. It contains | ||
script hooks that are executed by the CLI and implemented by the SDK. |
Oops, something went wrong.