File size: 854 Bytes
6f15a44
 
a9fc5f5
6f15a44
 
a9fc5f5
 
6f15a44
 
 
 
a9fc5f5
6f15a44
 
 
 
 
 
 
 
 
 
 
 
a9fc5f5
6f15a44
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from slack_sdk import WebClient
from slack_sdk.errors import SlackApiError

SLACK_BOT_TOKEN = os.getenv("SLACK_BOT_TOKEN")
SLACK_BOT_CHANNEL_ID = os.getenv("SLACK_BOT_CHANNEL_ID")


def send_slack_message_with_image(
    title: str, filename: str, message: str, file_path: str
):
    client = WebClient(token=SLACK_BOT_TOKEN)

    try:
        response = client.files_upload_v2(
            channel=SLACK_BOT_CHANNEL_ID,
            initial_comment=message,
            file=file_path,
            title=title,
            filename=filename,
        )
        if response.get("ok"):
            print("Message with image sent successfully!")
        else:
            print("Failed to send message with image:", response)

    except SlackApiError as e:
        # Handle Slack-specific errors
        print(f"Slack API Error: {e.response.get('error')}")