|
1 | | -# python-slack-hooks |
2 | | -Helper library implementing the contract between the Slack CLI and Bolt for Python |
| 1 | +<h1 align="center">Python Slack Hooks</h1> |
| 2 | + |
| 3 | +A helper library implementing the contract between the |
| 4 | +[Slack CLI][slack-cli-docs] and |
| 5 | +[Bolt for Python](https://slack.dev/bolt-python/) |
| 6 | + |
| 7 | +## Environment requirements |
| 8 | + |
| 9 | +Before getting started, make sure you have a development workspace where you |
| 10 | +have permissions to install apps. **Please note that leveraging all features in |
| 11 | +this project require that the workspace be part of |
| 12 | +[a Slack paid plan](https://slack.com/pricing).** |
| 13 | + |
| 14 | +### Install the Slack CLI |
| 15 | + |
| 16 | +Install the Slack CLI. Step-by-step instructions can be found in this |
| 17 | +[Quickstart Guide][slack-cli-docs]. |
| 18 | + |
| 19 | +### Environment Setup |
| 20 | + |
| 21 | +Create a project folder and a |
| 22 | +[virtual environment](https://docs.python.org/3/library/venv.html#module-venv) |
| 23 | +within it |
| 24 | + |
| 25 | +```zsh |
| 26 | +# Python 3.6+ required |
| 27 | +mkdir myproject |
| 28 | +cd myproject |
| 29 | +python3 -m venv .venv |
| 30 | +``` |
| 31 | + |
| 32 | +Activate the environment |
| 33 | + |
| 34 | +```zsh |
| 35 | +source .venv/bin/activate |
| 36 | +``` |
| 37 | + |
| 38 | +### Pypi |
| 39 | + |
| 40 | +Install this package using pip. |
| 41 | + |
| 42 | +```zsh |
| 43 | +pip install -U slack-cli-hooks |
| 44 | +``` |
| 45 | + |
| 46 | +### Clone |
| 47 | + |
| 48 | +Clone this project using git. |
| 49 | + |
| 50 | +```zsh |
| 51 | +git clone https://github.com/slackapi/python-slack-hooks.git |
| 52 | +``` |
| 53 | + |
| 54 | +Follow the |
| 55 | +[Develop Locally](https://github.com/slackapi/python-slack-hooks/blob/main/.github/maintainers_guide.md#develop-locally) |
| 56 | +steps in the maintainers guide to build and use this package. |
| 57 | + |
| 58 | +## Simple project |
| 59 | + |
| 60 | +In the same directory where we installed `slack-cli-hooks` |
| 61 | + |
| 62 | +1. Define basic information and metadata about our app via an |
| 63 | + [App Manifest](https://api.slack.com/reference/manifests) (`manifest.json`). |
| 64 | +2. Create a `slack.json` file that defines the interface between the |
| 65 | + [Slack CLI][slack-cli-docs] and [Bolt for Python][bolt-python-docs]. |
| 66 | +3. Use an `app.py` file to define the entrypoint for a |
| 67 | + [Bolt for Python][bolt-python-docs] project. |
| 68 | + |
| 69 | +### Application Configuration |
| 70 | + |
| 71 | +Define your [Application Manifest](https://api.slack.com/reference/manifests) in |
| 72 | +a `manifest.json` file. |
| 73 | + |
| 74 | +```json |
| 75 | +{ |
| 76 | + "display_information": { |
| 77 | + "name": "simple-app" |
| 78 | + }, |
| 79 | + "outgoing_domains": [], |
| 80 | + "settings": { |
| 81 | + "org_deploy_enabled": true, |
| 82 | + "socket_mode_enabled": true, |
| 83 | + }, |
| 84 | + "features": { |
| 85 | + "bot_user": { |
| 86 | + "display_name": "simple-app" |
| 87 | + } |
| 88 | + }, |
| 89 | + "oauth_config": { |
| 90 | + "scopes": { |
| 91 | + "bot": ["chat:write"] |
| 92 | + } |
| 93 | + } |
| 94 | +} |
| 95 | +``` |
| 96 | + |
| 97 | +### CLI/Bolt Interface Configuration |
| 98 | + |
| 99 | +Define the Slack CLI configuration in a file named `slack.json`. |
| 100 | + |
| 101 | +```json |
| 102 | +{ |
| 103 | + "hooks": { |
| 104 | + "get-hooks": "python3 -m slack_cli_hooks.hooks.get_hooks" |
| 105 | + } |
| 106 | +} |
| 107 | +``` |
| 108 | + |
| 109 | +### Source code |
| 110 | + |
| 111 | +Create a [Bolt for Python][bolt-python-docs] app in a file named `app.py`. |
| 112 | +Alternatively you can use an existing app instead. |
| 113 | + |
| 114 | +```python |
| 115 | +from slack_bolt import App |
| 116 | +from slack_bolt.adapter.socket_mode import SocketModeHandler |
| 117 | + |
| 118 | +app = App() |
| 119 | + |
| 120 | +# Add functionality here |
| 121 | + |
| 122 | +if __name__ == "__main__": |
| 123 | + SocketModeHandler(app).start() |
| 124 | +``` |
| 125 | + |
| 126 | +## Running the app |
| 127 | + |
| 128 | +You should now be able to harness the power of the Slack CLI and Bolt. |
| 129 | + |
| 130 | +Run the app this way: |
| 131 | + |
| 132 | +```zsh |
| 133 | +slack run |
| 134 | +``` |
| 135 | + |
| 136 | +## Getting Help |
| 137 | + |
| 138 | +If you get stuck we're here to help. Ensure your issue is related to this |
| 139 | +project and not to [Bolt for Python][bolt-python-docs]. The following are the |
| 140 | +best ways to get assistance working through your issue: |
| 141 | + |
| 142 | +- [Issue Tracker](https://github.com/slackapi/python-slack-hooks/issues) for |
| 143 | + questions, bug reports, feature requests, and general discussion. **Try |
| 144 | + searching for an existing issue before creating a new one.** |
| 145 | +- Email our developer support team: `support@slack.com` |
| 146 | + |
| 147 | +## Contributing |
| 148 | + |
| 149 | +Contributions are more then welcome. Please look at the |
| 150 | +[contributing guidelines](https://github.com/slackapi/python-slack-hooks/blob/main/.github/CONTRIBUTING.md) |
| 151 | +for more info! |
| 152 | + |
| 153 | +[slack-cli-docs]: https://api.slack.com/automation/cli |
| 154 | +[bolt-python-docs]: https://slack.dev/bolt-python/concepts |
0 commit comments