Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slack bot send an image

Tags:

bots

slack-api

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?

like image 983
Nagarjuna Reddy Avatar asked Mar 07 '17 11:03

Nagarjuna Reddy


People also ask

Can Slackbot respond with an image?

Slack bots are limited by the Slack API to specific formats: text, images, and special controls.

How do I embed a message in Slack?

Hover over the message you'd like to share. Click the three dots icon and choose Copy link. Paste the link into the message field, add text of your own if you'd like, and press Enter to send it.

Can Slack bots send DMS?

You may see Slackbot in channels throughout your workspace, delivering reminders and automated messages for you and your teammates. When there's a reminder or a message just for you, Slackbot will send you a DM. You can access your DM with Slackbot the same way you would find a DM with anyone else in your workspace.


1 Answers

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.

like image 194
Erik Kalkoken Avatar answered Oct 05 '22 01:10

Erik Kalkoken