ms_autoqc.SlackNotifications
1import ssl 2import ms_autoqc.DatabaseFunctions as db 3from slack_sdk import WebClient 4from slack_sdk.errors import SlackApiError 5 6def send_message(message): 7 8 """ 9 Posts a message to the Slack channel registered for notifications in Settings > General. 10 11 For details on the Slack API, see: https://slack.dev/python-slack-sdk/ 12 13 Args: 14 message (str): Message to send to the Slack channel 15 16 Returns: 17 Response object on success, or Error object on failure 18 """ 19 20 # SSL 21 ssl_context = ssl.create_default_context() 22 ssl_context.check_hostname = False 23 ssl_context.verify_mode = ssl.CERT_NONE 24 25 # Retrieve Slack bot token and Slack channel 26 slack_token = db.get_slack_bot_token() 27 client = WebClient(token=slack_token, ssl=ssl_context) 28 29 # Send Slack message 30 try: 31 slack_channel = db.get_slack_channel() 32 response = client.chat_postMessage(channel=slack_channel, text=message) 33 return response 34 except SlackApiError as error: 35 print("Slack API error:", error) 36 return error
def
send_message(message):
7def send_message(message): 8 9 """ 10 Posts a message to the Slack channel registered for notifications in Settings > General. 11 12 For details on the Slack API, see: https://slack.dev/python-slack-sdk/ 13 14 Args: 15 message (str): Message to send to the Slack channel 16 17 Returns: 18 Response object on success, or Error object on failure 19 """ 20 21 # SSL 22 ssl_context = ssl.create_default_context() 23 ssl_context.check_hostname = False 24 ssl_context.verify_mode = ssl.CERT_NONE 25 26 # Retrieve Slack bot token and Slack channel 27 slack_token = db.get_slack_bot_token() 28 client = WebClient(token=slack_token, ssl=ssl_context) 29 30 # Send Slack message 31 try: 32 slack_channel = db.get_slack_channel() 33 response = client.chat_postMessage(channel=slack_channel, text=message) 34 return response 35 except SlackApiError as error: 36 print("Slack API error:", error) 37 return error
Posts a message to the Slack channel registered for notifications in Settings > General.
For details on the Slack API, see: https://slack.dev/python-slack-sdk/
Arguments:
- message (str): Message to send to the Slack channel
Returns:
Response object on success, or Error object on failure