且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

通过Slack API或传入Webhook发送消息时,可以使用文件路径代替url作为`image_url`吗?

更新时间:2023-01-15 16:26:26

1)否.如前所述,无法使用文件路径直接在邮件中包含图像.唯一的方法是为图像文件提供公共URL.

1) No. As I mentioned earlier its not possible to use a file path to directly include an image in a message. The only way is to provide a public URL to an image file.

2)是,您可以使用上载到Slack的 files.upload 您的讯息.而且您不必在任何频道***享它们.

2) Yes, you can use files.upload you uploaded to Slack in your messages. And you do not have to share them in any channel do it.

基本方法是:

  • 使用 files.upload 将图像上传到Slack.而且,如果您不使用该API调用提供任何通道,则该文件将不会在任何通道***享.您将获得包含文件对象.上传的图片文件的文件ID.

  • Upload your image to Slack with files.upload. And if you do not provide any channels with that API call the file will not be shared in any channel. You will get the file object incl. the file ID of the uploaded image file.

调用 files.sharedPublicURL ,以通过提供以下内容将该文件公开文件ID

Call files.sharedPublicURL to make that file public by providing the file ID

您的图像文件现已公开,您可以使用文件对象的permalink_public在邮件中包含该图像.但是,您仍然需要根据从permalink_public获得的URL构造该图像的直接URL.查看这篇文章有关如何获取图片的直接URL.

Your image file is now public and you can use the permalink_public of the file object to include that image in message. However, you still need to construct the direct URL for that image from the URL you get from permalink_public. Check out this post on how to get the direct URL for the image.