Files
windmill/community/scripts/u/bot/message_slack.py
T
Ruben Fiszel 2e132878e4 first commit
2022-05-05 04:25:58 +02:00

24 lines
616 B
Python
Executable File

import os
import wmill
from slack_sdk.web.client import WebClient
def main(
slack_resource: dict,
text: str,
channel: str = None,
user: str = None,
):
slack_client = WebClient(token=slack_resource["token"])
if channel == "":
channel = None
if user == "":
user = None
if channel is None and user is None or (channel is not None and user is not None):
raise Exception("one and only one of channel or user need to be set")
if user is not None:
channel = "@{}".format(user)
slack_client.chat_postMessage(channel=channel, text=text)