Post alerts on Slack#
If you are a member of a Slack workspace, you can add a channel and make it private. Then follow these steps:
1. Create a Slack App#
Go to Slack API Apps
Click “Create New App” and follow the prompts
2. Configure OAuth & Permissions#
Navigate to “OAuth & Permissions” in your app settings
Add the necessary scopes for your app (e.g.,
chat:write,channels:read,groups:read)
3. Install the App to Your Workspace#
Click “Install App to Workspace”
Authorize the required permissions
4. Get Your OAuth Token#
After installation, copy the OAuth token provided
Use this token to authenticate API requests
5. Post Alerts to Slack#
Invite the app to your channel typing
invite @name_of_your_appUse the Slack API or a library (like
slack_sdkin Python) to send messages to your private channel
Example code#
from slack_sdk import WebClient
from slack_sdk.errors import SlackApiError
from credentials import load_credentials, get_credential
# Load credentials from credentials.txt
load_credentials()
# Get credentials
SLACK_BOT_TOKEN = get_credential('SLACK_WEBHOOK') # From credentials.txt
CHANNEL_ID = get_credential('SLACK_CHANNEL_ID') # From credentials.txt
# Initialize Slack client
client = WebClient(token=SLACK_BOT_TOKEN)
def post_message(text):
"""Send a message to Slack channel"""
try:
response = client.chat_postMessage(
channel=CHANNEL_ID,
text=text
)
print("✅ Message sent, ts:", response["ts"])
except SlackApiError as e:
print("❌ Slack error:", e.response["error"])
# Example usage
post_message('Hello from ACME alerts!')
Finally go on the settings of the channel and activate share link to invite other members of your group