diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0daa0133..ce1c814f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -24,6 +24,7 @@ - pip install requests - pip install temp - pip install aiokafka + - pip install slack-sdk - python3 -m unittest test @@ -48,6 +49,7 @@ - pip install aiohttp - pip install temp - pip install aiokafka + - pip install slack-sdk - python3 -m unittest test test py39: @@ -71,6 +73,7 @@ - pip install -U git+https://github.com/TeskaLabs/asab - pip install temp - pip install aiokafka + - pip install slack-sdk - python3 -m unittest test test flake: @@ -90,6 +93,7 @@ - pip install aiohttp - pip install temp - pip install aiokafka + - pip install slack-sdk - pip install -U git+https://github.com/TeskaLabs/asab - python3 -m flake8 asabiris diff --git a/README.md b/README.md index 05d368a0..20eeba71 100644 --- a/README.md +++ b/README.md @@ -71,4 +71,52 @@ https://teskalabs.github.io/asab-iris/ **Templates used for other purpose must be stored under** ``` /Templates/General/ -``` \ No newline at end of file +``` + +## Creating Xbot Tokens for Slack Apps + +### Prerequisites +- You have a Slack workspace where you can create and install apps. +- You have a GitHub repository where you want to add the instructions. + +### Step 1: Create a Slack App +1. Go to the [Slack API website](https://api.slack.com/apps) and sign in to your Slack account. +2. Click on the "Create New App" button. +3. Give your app a name and select the workspace where you want to install it. +4. Click on the "Create App" button. + +### Step 2: Configure App Permissions +1. In the left sidebar, click on "OAuth & Permissions". +2. Scroll down to the "Bot Token Scopes" section and click on the "Add an OAuth Scope" button. +3. Add the necessary scopes for sending messages and uploading files. For example: + - `chat:write` (for sending messages) + - `files:write` (for uploading files) +4. Click on the "Save Changes" button. + +### Step 3: Install the App in your Workspace +1. In the left sidebar, click on "OAuth & Permissions". +2. Scroll up to the "OAuth Tokens & Redirect URLs" section. +3. Click on the "Install to Workspace" button. +4. Review the requested scopes and click on the "Allow" button. +5. Copy the generated OAuth access token. This will be your xbot token. + +## Adding the App to a Channel + +### Step 1: Choose a Channel +1. Open your Slack workspace and navigate to the channel where you want to add the app. + +### Step 2: Invite the App to the Channel +1. In the channel, click on the channel name or the gear icon to access the channel settings. +2. Select "Add apps" from the dropdown menu. + +### Step 3: Search for the App +1. In the search bar, type the name of your app and press Enter. +2. Locate your app in the search results and click on it to select it. + +### Step 4: Confirm the Addition +1. Review the app details and permissions to ensure it aligns with your requirements. +2. Click on the "Add to Channel" or "Add" button to add the app to the channel. + +### Step 5: Verify the App's Presence +1. Look for the app's name or icon in the channel member list. +2. If the app is successfully added, it should appear as a member of the channel. diff --git a/asabiris/output/slack/service.py b/asabiris/output/slack/service.py index 68c1d46f..41f7a8f9 100644 --- a/asabiris/output/slack/service.py +++ b/asabiris/output/slack/service.py @@ -12,14 +12,20 @@ L = logging.getLogger(__name__) +asab.Config.add_defaults( + { + 'slack': { + "channel": "general", + } + }) class SlackOutputService(asab.Service, OutputABC): def __init__(self, app, service_name="SlackOutputService"): super().__init__(app, service_name) try: - self.SlackWebhookUrl = asab.Config.get("slack", "webhook_url") + self.SlackWebhookUrl = asab.Config.get("slack", "token") self.Client = WebClient(token=self.SlackWebhookUrl) - self.Channel = asab.Config.get("slack", "slack_channel") + self.Channel = asab.Config.get("slack", "channel") except configparser.NoOptionError as e: L.error("Please provide webhook_url in slack configuration section.") raise e diff --git a/etc/asab-iris.conf b/etc/asab-iris.conf index 42e9c287..8b13c987 100644 --- a/etc/asab-iris.conf +++ b/etc/asab-iris.conf @@ -12,3 +12,7 @@ from=info@example.com ssl=no starttls=yes subject=Mail from ASAB Iris + +[slack] +token=xoxb-111111111111-2222222222222-3333333333333voe +channel=general diff --git a/qa.md b/qa.md index c2cd27fc..136d88fc 100644 --- a/qa.md +++ b/qa.md @@ -429,4 +429,32 @@ EXPECTED RESPONSE: "message": "Invalid path '/Templates/MISSING.md'.", "uuid": "c941fe16-470e-42d2-958c-c9fb09ac8e7d" } +``` + +## TSM022: Try to send Slack with attachment + +`PUT /send_slack` + +``` +{ + "body":{ + "template":"/Templates/Slack/alert.md", + "params":{ + "message":"I am testing a template", + "event":"Iris-Event" + } +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5afBtee8smQ9rUMGoL5h98I+QAOPQMT54OY80RmfqSp12a75qG9sts3d4hKlHOUqsxntzJdLoLNC0IZ67NuwZ2we6zQ1iyoK7OKzJEBjZ5MpGHnlcdVRzzzVuhBBRMcuB7S+XCeCSvEkWSGothPNwlWBDnHT7FSWNM61PR9Y0cHrdQ0EOAb5BnLA+LkXwh6QogJ27SoDSqGvODjKgEN7JFoObJn+GNcfty+radorf3Zpv7XqMV94TI6Rha7FKiHzK+1p9toRNkw/RLNZuY46A/Lz2pC7dVC1ppZ5mHpIiqeHs0y5TguPKEPsqeaubcKj6ON+DJzirgqUeDVoyGca7jZzFo9Lg2f5K4YboZEpvzriHZrCx3a68qWwoAEpC1oAA1qjKaKJkzHxuTkVqPGOLxHQjQ3TTZFB+dxwIljKsZ+6IiABU6U9AHfguXIAV3vKDhbO8Jtm+c81AixI/i+HvsNmIWKQNyMv8ZgLSoMjUhqoP7WyJdz3OpUJahzUoVhyLvEk71nqqP5mH3FWXUUz8DgYZJTb1RYiOWBRpo8xW5TMUgd0pybcUCMeGk+dUaI5CplhS9ILSHN/kY07cAeQ7zgr/FfudCUorOkkzwaKPXPnz2eG23McrGTBGOfp+1QouvJTqahewU4LKjrhwSloKUhF1lKtgADlMjw3mPwHUrdWkujc1sgA7rAHBtpQAAAAAAAAAAAAAEVYSUa6AAAARXhpZgAASUkqAAgAAAAGABIBAwABAAAAAQAAABoBBQABAAAAVgAAABsBBQABAAAAXgAAACgBAwABAAAAAgAAABMCAwABAAAAAQAAAGmHBAABAAAAZgAAAAAAAAA4YwAA6AMAADhjAADoAwAABgAAkAcABAAAADAyMTABkQcABAAAAAECAwAAoAcABAAAADAxMDABoAMAAQAAAP//AAACoAQAAQAAAPoAAAADoAQAAQAAAPoAAAAAAAAA", + "content-type":"image/jpeg", + "filename":"kiwi.jpeg" + } + ] +} +EXPECTED RESPONSE: + +{ + "result": "OK" +} ``` \ No newline at end of file