Slack bot send an image

笑着哭i 提交于 2019-12-10 15:07:16

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/42647024/slack-bot-send-an-image

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!