-
Notifications
You must be signed in to change notification settings - Fork 31
Open
Description
Background
A slack token is the new method of authentication
It allows multiple slack channels and specific scopes.
How
Here's how to hit the API using the token instead of the webhook
https://api.slack.com/tutorials/tracks/posting-messages-with-curl
# test auth
auth_test = requests.post(
'https://slack.com/api/auth.test',
headers=({'Authorization': f'Bearer {self.slack_token}'})
).json()
# send message
requests.post(
'https://slack.com/api/chat.postMessage',
headers=({'Authorization': f'Bearer {self.slack_token}'}),
json=payload
)Code references
terraform-aws-clickops-notifier/clickopsnotifier/app.py
Lines 57 to 64 in be9694c
| for parameter_name in PARAMETER_NAMES_FOR_SLACK_WEBHOOKS: | |
| webhook_url = get_webhook_url(parameter_name) | |
| messenger = Messenger( | |
| webhook_type="slack", | |
| webhook_url=webhook_url, | |
| parameter_name=parameter_name, | |
| ) | |
| _MESSENGERS.append(messenger) |
terraform-aws-clickops-notifier/clickopsnotifier/messenger.py
Lines 10 to 15 in be9694c
| def __init__( | |
| self, webhook_type: str, webhook_url: str, parameter_name: str | |
| ) -> None: | |
| self.webhook_url = webhook_url | |
| if self.webhook_url is None: | |
| raise ValueError("webhook_url cannot be None") |
| response = requests.post(self.webhook_url, json=payload) |
Related to #76
Metadata
Metadata
Assignees
Labels
No labels