10

I am developing a bot for slack. I am implementing a notification functionality, where it will send a notification for every one hour. Currently, I am sending normal text in notification, but I need to send an image along with text. Is it possible to send an image?

Nagarjuna Reddy
  • 4,083
  • 14
  • 41
  • 85

1 Answers1

9

You can send images as part of the attachments of a message. That can be either a full image or a thumbnail.

Just add the image_url property for full images or the thumb_url property for a thumbnail image with a url to an image to your attachment and it will be displayed under your message. You can also send multiple images through adding multiple attachments.

Example attachment: (based on official Slack documentation example)

{
    "attachments": [
        {
            "fallback": "Required plain-text summary of the attachment.",
            "text": "Optional text that appears within the attachment",
            "image_url": "http://my-website.com/path/to/image.jpg",
            "thumb_url": "http://example.com/path/to/thumb.png"
        }
    ]
}

This works with all approaches for sending message, e.g. API method, Incoming webhook, response to slash commands etc.

See here for the official Slack documentation for attachments.

Erik Kalkoken
  • 30,467
  • 8
  • 79
  • 114
  • 1
    @NNR If this answer solved your question please consider marking it as solved. Thank you! – Erik Kalkoken Mar 17 '17 at 23:14
  • 2
    I'm trying to do this with "Slackbot Responses" and it's not working. Is this intended to be used with an external API? – 0xSheepdog Dec 17 '17 at 22:11
  • yes - that is how the API can do it. If you want to edit slackbot custom responses and display an image, look at markdown for slack – Marc Maxmeister Apr 16 '18 at 01:05
  • 1
    @ErikKalkoken Do u know if it is possible to use a file path instead of url as `image_url`? – Wlad Jul 29 '19 at 19:45
  • 3
    No, that will not work. It has to be a public URL for an image file. You can however first upload a file to Slack and then use that for your message. See here for details: https://stackoverflow.com/questions/57253156/how-to-use-the-permalink-public-url-of-an-uploaded-image-to-include-it-in-a-mess – Erik Kalkoken Jul 29 '19 at 19:50