松弛机器人发送图像 [英] Slack bot send an image

查看:70
本文介绍了松弛机器人发送图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一种休闲机器人.我正在实现通知功能,它将每隔一小时发送一次通知.当前,我在通知中发送普通文本,但是我需要将图像与文本一起发送.可以发送图像吗?

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?

推荐答案

您可以将图像作为邮件附件的一部分发送.那可以是完整图像或缩略图.

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

只需为完整图像或添加 image_url 属性缩略图的href ="https://api.slack.com/docs/message-attachments#thumb_url" rel ="noreferrer"> thumb_url 属性,其中包含指向附件及其图像的URL将显示在您的消息下方.您还可以通过添加多个附件来发送多张图像.

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.

示例附件:(基于官方的Slack文档示例)

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"
        }
    ]
}

这适用于所有发送消息的方法,例如API方法,传入的Webhook,对斜杠命令的响应等.

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

有关附件的正式Slack文档,请参见此处.

See here for the official Slack documentation for attachments.

这篇关于松弛机器人发送图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆