How to send base64 encoded images to slack using webhook urls?

42 views Asked by At

I was trying to send a base64 encoded image onto a slack channel using post request to the webhook url. Please refer to the following snippet

slack_webhook_url = "<webhook_url>"

    message = f"<test message>"

    payload = {
        "text": message,
        "attachments": [
            {
                "fallback": "Image Attachment",
                "text": "Image Attachment",
                "image_url": f"data:image/png;base64,{<base64_encoding>}",
            }
        ]
    }

    response = requests.post(slack_webhook_url, json=payload)

    if response.status_code == 200:
        print(f"Slack alert sent")
    else:
        print(f"Failed to send Slack alert . Status code: {response.status_code}")

How can I make this to work?

I even tried writing the file and then attaching it as a file but still that didn't work. Im looking for a method to directly pass this to the slack channel.

0

There are 0 answers