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')}")