terraform-aws-clickops-notifier icon indicating copy to clipboard operation
terraform-aws-clickops-notifier copied to clipboard

Use slack token as alternative to webhook

Open nitrocode opened this issue 8 months ago • 0 comments

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

https://github.com/cloudandthings/terraform-aws-clickops-notifier/blob/be9694cda07dbe74fad9e332723be3b38bb5267b/clickopsnotifier/app.py#L57-L64

https://github.com/cloudandthings/terraform-aws-clickops-notifier/blob/be9694cda07dbe74fad9e332723be3b38bb5267b/clickopsnotifier/messenger.py#L10-L15

https://github.com/cloudandthings/terraform-aws-clickops-notifier/blob/be9694cda07dbe74fad9e332723be3b38bb5267b/clickopsnotifier/messenger.py#L63

Related to #76

nitrocode avatar May 28 '24 21:05 nitrocode