-
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.
WIP broken Quart/Slack implementation
- Loading branch information
Showing
6 changed files
with
128 additions
and
3 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
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 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,40 @@ | ||
.. _slack: | ||
|
||
Slack Integration | ||
================= | ||
|
||
machine-access-control (MAC) offers a Slack integration for logging and control. | ||
|
||
.. _slack.setup: | ||
|
||
Setup | ||
----- | ||
|
||
To set up the Slack integration: | ||
|
||
1. `Create a new Slack app <https://api.slack.com/apps?new_app=1&track=hello-world-bolt>`_ | ||
|
||
1. Create your new app "from scratch". | ||
2. Set a meaningful name, such as ``machine-access-control`` and create the app in your Workspace. | ||
3. In the left menu, navigate to ``OAuth & Permissions``. | ||
4. In the "Scopes" pane, under "Bot Token Scopes", click "Add an OAuth Scope" and add scopes for ``app_mentions:read``, ``canvases:read``, ``canvases:write``, ``channels:read``, ``chat:write``, ``groups:read``, ``groups:write``, ``incoming-webhook``, ``users.profile:read``, and ``users:read``. | ||
|
||
2. In your workspace, create a new private channel for admins to interact with MAC in, and MAC to post status updates to. | ||
3. In the left menu, navigate to ``Install App``. Click on the button to install to your workspace. When prompted for a channel for the app to post in, select the private channel that you created in the previous step. | ||
4. On the next screen, ``Installed App Settings``, copy the ``Bot User OAuth Token`` and set this as the ``SLACK_BOT_TOKEN`` environment variable for the MAC server. | ||
5. Go back to the main settings for your app and navigate to ``Socket Mode`` under ``Settings`` on the left menu; toggle on ``Enable Socket Mode``. For ``Token Name``, enter ``socket-mode-token`` and click ``Generate``. Copy the generated token and set it as the ``SLACK_APP_TOKEN`` environment variable for the MAC server **TBD is this needed? document on config page.** | ||
6. Go back to the main settings for your app and navigate to ``Basic Information`` under ``Settings`` on the left menu; in the ``App Credentials`` pane click ``Show`` in the ``Signing Secret`` box and then copy that value; set it as the ``SLACK_SIGNING_SECRET`` environment variable for the MAC server. | ||
|
||
.. _slack.configuration: | ||
|
||
Configuration | ||
------------- | ||
|
||
TBD. | ||
|
||
.. _slack.usage: | ||
|
||
Usage | ||
----- | ||
|
||
TBD. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,25 @@ | ||
"""Slack app.""" | ||
|
||
import os | ||
from slack_bolt import App | ||
from slack_bolt.adapter.quart import AsyncQuartReceiver | ||
from quart import Quart | ||
import logging | ||
|
||
logger: logging.Logger = logging.getLogger(__name__) | ||
|
||
|
||
class SlackApp: | ||
"""MAC Slack App.""" | ||
|
||
def __init__(self, app: Quart) -> None: | ||
receiver: AsyncQuartReceiver = AsyncQuartReceiver(app) | ||
self.app: App = App( | ||
token=os.environ("SLACK_APP_TOKEN"), | ||
signing_secret=os.environ("SLACK_SIGNING_SECRET"), | ||
receiver=receiver | ||
) | ||
|
||
@self.app.event("app_mention") | ||
async def handle_app_mention(self, event, say): | ||
logging.info("app mention event=%s say=%s", event, say) |