Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use slack token as alternative to webhook #89

Open
nitrocode opened this issue May 28, 2024 · 0 comments
Open

Use slack token as alternative to webhook #89

nitrocode opened this issue May 28, 2024 · 0 comments

Comments

@nitrocode
Copy link
Contributor

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

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)

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant