5.1 KiB
Slack
- TL;DR
- Add custom emoji
- Give aliases to existing emojis
- Use incoming webhooks for notifications
- Use bots for notifications
- Create apps
- Further readings
TL;DR
Setup
brew install --cask 'slack'
mas install '803453959'
CLI:
brew install --cask 'slack-cli' \
&& slack login
Authorization data will be saved to ~/.slack/credentials.json.
Usage
# Login.
slack login
# List authorized accounts.
slack auth list
slack list
# Send notifications to channels using the APIs.
curl --request 'POST' --url 'https://slack.com/api/chat.postMessage?pretty=1' \
--header 'Authorization: Bearer xoxb-012345678901-0123456789012-abcdefghijklmnopqrstuvwx' \
--header 'Content-type: application/json' --data '{"channel": "C04K1234567", "text": "Hello, World!"}'
# Send notifications to channels using incoming webhooks.
curl --request 'POST' --url 'https://hooks.slack.com/services/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' \
--header 'Content-type: application/json' --data '{"text": "Hello, World!"}'
Add custom emoji
Check out slackmojis for some common reactions.
- Go to https://{{org-name}}.slack.com/customize/emoji.
- Select Add Custom Emoji.
- Upload the image. Supported formats: GIF, JPG, PNG.
- Give it a name.
Give aliases to existing emojis
- Go to https://{{org-name}}.slack.com/customize/emoji.
- Select Add Alias.
- Choose the image.
- Give it an alias.
Use incoming webhooks for notifications
Refer Sending messages using incoming webhooks and Setting Up Slack Webhook URL Simplified 101.
-
Enable Incoming Webhooks for a Slack app.
Features → Incoming Webhooks → Activate Incoming Webhooks. -
Create a new Webhook URL and authorize it (or request authorization for it).
-
Install (or request an higher entity to install) the app in the workspace.
App details → Settings → Install App → OAuth Tokens. -
Send a test request to the webhook:
curl --request 'POST' --url 'https://hooks.slack.com/services/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' \ --header 'Content-type: application/json' --data '{"text": "Hello, World!"}'
Use bots for notifications
Refer Automating Slack Notifications: Sending Messages as a Bot with Python.
-
Select From Scratch.
-
Enter a name (e.g.,
test bot) and select a workspace for it. -
Add the required OAuth scopes (e.g.
chat:write).
App details → Features → OAuth & Permissions → Scopes → Bot Token Scopes. -
Install (or request an higher entity to install) the app in the workspace.
App details → Settings → Install App → OAuth Tokens.
This will automatically generate an OAuth token for the app. Note that token down. -
Add the app to the channels it needs to interact with. Channel details → Integrations tab → Apps section → Add apps.
-
Try sending messages using the app's OAuth token:
curl --request 'POST' --url 'https://slack.com/api/chat.postMessage?pretty=1' \ --header 'Authorization: Bearer xoxb-012345678901-0123456789012-abcdefghijklmnopqrstuvwx' \ --header 'Content-type: application/json' --data '{"channel": "C04K1234567", "text": "Hello, World!"}'