2021-09-23 10:15:02 +02:00
|
|
|
import os
|
|
|
|
from slack import WebClient
|
|
|
|
from slack.errors import SlackApiError
|
|
|
|
|
2021-10-01 14:52:12 +02:00
|
|
|
def notify_slack(msg, slack_channel):
|
2021-09-23 10:15:02 +02:00
|
|
|
slack_token=os.environ.get('SLACK_API_TOKEN','no slack token in env')
|
|
|
|
slack_client=WebClient(slack_token)
|
|
|
|
if slack_channel is not None:
|
|
|
|
try:
|
|
|
|
return slack_client.chat_postMessage(
|
|
|
|
channel=slack_channel,
|
|
|
|
text=msg)
|
|
|
|
except SlackApiError as e:
|
|
|
|
print(f"Could not notify slack: {e.response['error']}")
|