Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating Slack engine to use slack_bolt #62957

Merged
merged 5 commits into from
Oct 31, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Updating setup instructions to follow those for setting up an App.
garethgreenaway committed Oct 25, 2022

Verified

This commit was signed with the committer’s verified signature.
plyr4 dave vader
commit 93caca405832e92a78db43f0008ae449ef4c1102
57 changes: 42 additions & 15 deletions salt/engines/slack.py
Original file line number Diff line number Diff line change
@@ -3,21 +3,43 @@
.. versionadded:: 2016.3.0
:depends: `slackclient <https://pypi.org/project/slackclient/>`_ Python module
:depends: `slack_bolt <https://pypi.org/project/slack_bolt/>`_ Python module
.. important::
This engine requires a bot user. To create a bot user, first go to the
**Custom Integrations** page in your Slack Workspace. Copy and paste the
following URL, and replace ``myworkspace`` with the proper value for your
workspace:
``https://myworkspace.slack.com/apps/manage/custom-integrations``
Next, click on the ``Bots`` integration and request installation. Once
approved by an admin, you will be able to proceed with adding the bot user.
Once the bot user has been added, you can configure it by adding an avatar,
setting the display name, etc. You will also at this time have access to
your API token, which will be needed to configure this engine.
This engine requires a Slack app and a Slack Bot user. To create a
bot user, first go to the **Custom Integrations** page in your
Slack Workspace. Copy and paste the following URL, and log in with
account credentials with administrative privileges:
``https://api.slack.com/apps/new``
Next, click on the ``From scratch`` option from the ``Create an app`` popup.
Give your new app a unique name, eg. ``SaltSlackEngine``, select the workspace
where your app will be running, and click ``Create App``.
Next, click on ``Socket Mode`` and then click on the toggle button for
``Enable Socket Mode``. In the dialog give your Socket Mode Token a unique
name and then copy and save the app level token. This will be used
as the ``app_token`` parameter in the Slack engine configuration.
Next, click on ``OAuth & Permissions`` and then under ``Bot Token Scope``, click
on ``Add an OAuth Scope``. Ensure the following scopes are included:
- ``channels:history``
- ``channels:read``
- ``chat:write``
- ``commands``
- ``files:read``
- ``files:write``
- ``im:history``
- ``mpim:history``
- ``usergroups:read``
- ``users:read``
Once all the scopes have been added, click the ``Install to Workspace`` button
under ``OAuth Tokens for Your Workspace``, then click ``Allow``. Copy and save
the ``Bot User OAuth Token``, this will be used as the ``bot_token`` parameter
in the Slack engine configuration.
Finally, add this bot user to a channel by switching to the channel and
using ``/invite @mybotuser``. Keep in mind that this engine will process
@@ -74,6 +96,9 @@
.. versionchanged:: 2017.7.0
Access control group support added
.. versionchanged:: 3006.0
Updated to use slack_bolt Python library.
This example uses a single group called ``default``. In addition, other groups
are being loaded from pillar data. The group names do not have any
significance, it is the users and commands defined within them that are used to
@@ -83,7 +108,8 @@
engines:
- slack:
token: 'xoxb-xxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxx'
app_token: "xapp-x-xxxxxxxxxxx-xxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
bot_token: 'xoxb-xxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxx'
control: True
fire_all: False
groups_pillar_name: 'slack_engine:groups_pillar'
@@ -121,7 +147,8 @@
engines:
- slack:
groups_pillar: slack_engine_pillar
token: 'xoxb-xxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxx'
app_token: "xapp-x-xxxxxxxxxxx-xxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
bot_token: 'xoxb-xxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxx'
control: True
fire_all: True
tag: salt/engines/slack