0

Send message to Slack

by
Published Oct 28, 2025

Send message to Slack. When you call the function you can call it like so: ``` import wmill from f.slack_bot.send_message_to_slack import send_message_to_slack slack = wmill.get_resource("f/slack_bot/bot_token") send_message_to_slack(channel_id=slack_channel, text=slack_message, slack=slack) ```

Script slack
  • Submitted by rasul kireev249 Python3
    Created 238 days ago
    1
    from typing import TypedDict
    2
    
    
    3
    from slack_sdk import WebClient
    4
    from slack_sdk.errors import SlackApiError
    5
    
    
    6
    class Slack(TypedDict):
    7
        token: str
    8
    
    
    9
    def send_message_to_slack(channel_id: str, text: str, slack: Slack):
    10
        client = WebClient(token=slack['token'])
    11
        try:
    12
            response = client.chat_postMessage(
    13
                channel=channel_id,
    14
                text=text
    15
            )
    16
            print(f"Message sent: {response['ts']}")
    17
        except SlackApiError as e:
    18
            print(f"Error sending message: {e.response['error']}")
    19
                    
    20
        except Exception as e:
    21
            print(f"Failed to send Slack message: {type(e).__name__}: {str(e)}")