mirror of
https://gitea.com/mcereda/oam.git
synced 2026-02-08 21:34:25 +00:00
chore(kb/slack): bots, bots everywhere
This commit is contained in:
@@ -3,8 +3,9 @@
|
|||||||
1. [TL;DR](#tldr)
|
1. [TL;DR](#tldr)
|
||||||
1. [Add custom emoji](#add-custom-emoji)
|
1. [Add custom emoji](#add-custom-emoji)
|
||||||
1. [Give aliases to existing emojis](#give-aliases-to-existing-emojis)
|
1. [Give aliases to existing emojis](#give-aliases-to-existing-emojis)
|
||||||
1. [Apps](#apps)
|
1. [Use incoming webhooks for notifications](#use-incoming-webhooks-for-notifications)
|
||||||
1. [Incoming webhooks](#incoming-webhooks)
|
1. [Use bots for notifications](#use-bots-for-notifications)
|
||||||
|
1. [Create apps](#create-apps)
|
||||||
1. [Further readings](#further-readings)
|
1. [Further readings](#further-readings)
|
||||||
1. [Sources](#sources)
|
1. [Sources](#sources)
|
||||||
|
|
||||||
@@ -18,16 +19,38 @@ brew install --cask 'slack'
|
|||||||
mas install '803453959'
|
mas install '803453959'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
CLI:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
brew install --cask 'slack-cli' \
|
||||||
|
&& slack login
|
||||||
|
```
|
||||||
|
|
||||||
|
Authorization data will be saved to `~/.slack/credentials.json`.
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>Usage</summary>
|
<summary>Usage</summary>
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
# Send notifications to channels
|
# Login.
|
||||||
curl -X 'POST' -H 'Content-type: application/json' \
|
slack login
|
||||||
--data '{"text": "Hello, World!"}' \
|
|
||||||
'https://hooks.slack.com/services/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'
|
# List authorized accounts.
|
||||||
|
slack auth list
|
||||||
|
slack list
|
||||||
|
```
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# 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!"}'
|
||||||
```
|
```
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
@@ -59,38 +82,62 @@ Check out [slackmojis] for some common reactions.
|
|||||||
1. Choose the image.
|
1. Choose the image.
|
||||||
1. Give it an alias.
|
1. Give it an alias.
|
||||||
|
|
||||||
## Apps
|
## Use incoming webhooks for notifications
|
||||||
|
|
||||||
Direct links:
|
|
||||||
|
|
||||||
- [Create a new App](https://api.slack.com/apps?new_app=1).
|
|
||||||
|
|
||||||
## Incoming webhooks
|
|
||||||
|
|
||||||
Refer [Sending messages using incoming webhooks] and [Setting Up Slack Webhook URL Simplified 101].
|
Refer [Sending messages using incoming webhooks] and [Setting Up Slack Webhook URL Simplified 101].
|
||||||
|
|
||||||
1. Enable Incoming Webhooks for a Slack app.<br/>
|
1. Enable Incoming Webhooks for a Slack app.<br/>
|
||||||
_Features_ → _Incoming Webhooks_ → _Activate Incoming Webhooks_.
|
_Features_ → _Incoming Webhooks_ → _Activate Incoming Webhooks_.
|
||||||
1. Create a new Webhook URL and authorize it (or request authorization for it).
|
1. Create a new Webhook URL and authorize it (or request authorization for it).
|
||||||
1. Install the app in the workspace.
|
1. Install (or request an higher entity to install) the app in the workspace.<br/>
|
||||||
1. Send a test request to the webhook.
|
App details → _Settings_ → _Install App_ → _OAuth Tokens_.<br/>
|
||||||
|
1. Send a test request to the webhook:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
curl -X 'POST' -H 'Content-type: application/json' \
|
curl --request 'POST' --url 'https://hooks.slack.com/services/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' \
|
||||||
'https://hooks.slack.com/services/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' --data '{"text": "Hello, World!"}'
|
--header 'Content-type: application/json' --data '{"text": "Hello, World!"}'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Use bots for notifications
|
||||||
|
|
||||||
|
Refer [Automating Slack Notifications: Sending Messages as a Bot with Python].
|
||||||
|
|
||||||
|
1. [Create a new Slack App][create apps].
|
||||||
|
1. Select _From Scratch_.
|
||||||
|
1. Enter a name (e.g., `test bot`) and select a workspace for it.
|
||||||
|
1. Add the required OAuth scopes (e.g. `chat:write`).<br/>
|
||||||
|
App details → _Features_ → _OAuth & Permissions_ → _Scopes_ → _Bot Token Scopes_.
|
||||||
|
1. Install (or request an higher entity to install) the app in the workspace.<br/>
|
||||||
|
App details → _Settings_ → _Install App_ → _OAuth Tokens_.<br/>
|
||||||
|
This will automatically generate an OAuth token for the app. Note that token down.
|
||||||
|
1. Add the app to the channels it needs to interact with.
|
||||||
|
Channel details → _Integrations_ tab → _Apps_ section → _Add apps_.
|
||||||
|
1. Try sending messages using the app's OAuth token:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
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!"}'
|
||||||
|
```
|
||||||
|
|
||||||
|
## Create apps
|
||||||
|
|
||||||
|
[Direct link](https://api.slack.com/apps?new_app=1).
|
||||||
|
|
||||||
## Further readings
|
## Further readings
|
||||||
|
|
||||||
- [Website]
|
- [Website]
|
||||||
- [Sending messages using incoming webhooks]
|
- [Sending messages using incoming webhooks]
|
||||||
- [Posting messages using curl]
|
- [Posting messages using curl]
|
||||||
|
- [CLI]
|
||||||
|
|
||||||
### Sources
|
### Sources
|
||||||
|
|
||||||
- [Slackmojis]
|
- [Slackmojis]
|
||||||
- [Slack Notifications for Ansible Tower (AWX)]
|
- [Slack Notifications for Ansible Tower (AWX)]
|
||||||
- [Setting Up Slack Webhook URL Simplified 101]
|
- [Setting Up Slack Webhook URL Simplified 101]
|
||||||
|
- [How to quickly get and use a Slack API bot token]
|
||||||
|
- [Automating Slack Notifications: Sending Messages as a Bot with Python]
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Reference
|
Reference
|
||||||
@@ -98,14 +145,19 @@ Refer [Sending messages using incoming webhooks] and [Setting Up Slack Webhook U
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<!-- In-article sections -->
|
<!-- In-article sections -->
|
||||||
|
[create apps]: #create-apps
|
||||||
|
|
||||||
<!-- Knowledge base -->
|
<!-- Knowledge base -->
|
||||||
<!-- Files -->
|
<!-- Files -->
|
||||||
<!-- Upstream -->
|
<!-- Upstream -->
|
||||||
|
[cli]: https://tools.slack.dev/slack-cli/
|
||||||
[posting messages using curl]: https://api.slack.com/tutorials/tracks/posting-messages-with-curl
|
[posting messages using curl]: https://api.slack.com/tutorials/tracks/posting-messages-with-curl
|
||||||
[sending messages using incoming webhooks]: https://api.slack.com/messaging/webhooks
|
[sending messages using incoming webhooks]: https://api.slack.com/messaging/webhooks
|
||||||
[website]: https://slack.com/
|
[website]: https://slack.com/
|
||||||
|
[how to quickly get and use a slack api bot token]: https://api.slack.com/tutorials/tracks/getting-a-token
|
||||||
|
|
||||||
<!-- Others -->
|
<!-- Others -->
|
||||||
|
[automating slack notifications: sending messages as a bot with python]: https://medium.com/@sid2631/automating-slack-notifications-sending-messages-as-a-bot-with-python-2beb6c16cd8c
|
||||||
[setting up slack webhook url simplified 101]: https://hevodata.com/learn/slack-webhook-url/
|
[setting up slack webhook url simplified 101]: https://hevodata.com/learn/slack-webhook-url/
|
||||||
[slack notifications for ansible tower (awx)]: https://mpolinowski.github.io/docs/DevOps/Ansible/2021-04-30-ansible-tower-slack-notifications/2021-04-30/
|
[slack notifications for ansible tower (awx)]: https://mpolinowski.github.io/docs/DevOps/Ansible/2021-04-30-ansible-tower-slack-notifications/2021-04-30/
|
||||||
[slackmojis]: https://slackmojis.com/
|
[slackmojis]: https://slackmojis.com/
|
||||||
|
|||||||
Reference in New Issue
Block a user