I am trying to post a message with private Slack File using Incoming Webhook.
Steps taken :
Request Body :
{
"text": "Danny Torrence left a 1 star review for your property.",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Danny Torrence left the following review for your property:"
}
},
{
"type": "section",
"block_id": "section567",
"text": {
"type": "mrkdwn",
"text": "<https://example.com|Overlook Hotel> \n :star: \n Doors had too many axe holes, guest in room 237 was far too rowdy, whole place felt stuck in the 1920s."
},
"accessory": {
"type": "image",
"image_url": "https://is5-ssl.mzstatic.com/image/thumb/Purple3/v4/d3/72/5c/d3725c8f-c642-5d69-1904-aa36e4297885/source/256x256bb.jpg",
"alt_text": "Haunted hotel image"
}
},
{
"type": "section",
"block_id": "section789",
"fields": [
{
"type": "mrkdwn",
"text": "*Average Rating*\n1.0"
}
]
},
{
"type": "image",
"title": {
"type": "plain_text",
"text": "Please enjoy this photo of a kitten"
},
"block_id": "image4",
"slack_file": {
"url": "https://files.slack.com/files-pri/00000000000-00000000000/testphoto.jpg"
},
"alt_text": "An incredibly cute kitten."
}
]
}
One thing I haven't tried is using sharedPublicURL
API, however what I am expecting is not to share the file publicly.
I found an article from Slack related to what I expect : https://slack.com/blog/developers/uploading-private-images-blockkit
so, my question is :
Quite new to Slack App Integration, if you need more info, please tell me. Thank you.
Here is what I have tried :
After days of research and testing, seems Incoming Webhooks App (bot) doesn't have the permission to access the file my bot has uploaded (I used the same bot when uploading file and for triggering Webhook). I even tried to upload the file to the bot itself by sharing it to the bot Channel ID
, but still fails.
My assumption is based on Slack's article above :
As such, ensure that the user (or app) that is posting blocks containing secure image elements has access to the underlying file. For example, say your app uploads a file using a user token (i.e. acts on behalf of a specific user) but posts a message with a secure image element leveraging that file using a bot token (i.e. posts a message as the app), or vice versa. In this situation, the user who uploaded the file did not give explicit permissions to the app to view the file! Try to use the same token to upload files as well as display messages containing them.
I decided to find an alternative by using chat.postMessage
API here and now it's working well.