High Level Description
-
I receive Slack webhooks with a JSON payload when a message is posted into our Slack workspace. A JSON payload example is below.
-
I simply want to loop over each file inside the files array (body->event->files->file[0] and so forth) so that I can download/save each file locally on our server for long term retention.
What I Need Help With
I believe I need a splitoutitems.itemlist node, pass it the json struct for the files and then I can iterate over each file, run a download node/save node etc.
However, I’ve been trying to do it using various methods based on examples I’ve found here and I can’t get it to work correctly.
What would be the correct node(s) to be able to iterate over each body->event->file and save each one using the permalink_public element inside of each file?
THANK YOU IN ADVANCE!
JSON Payload Sample
[
{
"headers": {
"host": "hotshot.app.n8n.cloud",
"x-request-id": "4f2fb4c14259326f060bb81dde0157e0",
"x-real-ip": "52.87.250.142",
"x-forwarded-for": "52.87.250.142",
"x-forwarded-host": "hotshot.app.n8n.cloud",
"x-forwarded-port": "443",
"x-forwarded-proto": "https",
"x-forwarded-scheme": "https",
"x-scheme": "https",
"content-length": "5656",
"user-agent": "Slackbot 1.0 (+https://api.slack.com/robots)",
"accept": "*/*",
"content-type": "application/json",
"x-slack-signature": "v0=b7ff6b48e2cf472a377892c0b0cce101b638443448cf6399cac89af2cbf2611e",
"x-slack-request-timestamp": "1696361635"
},
"params": {},
"query": {},
"body": {
"token": "XwhSCzLcPdtHg0OG1IfYe4pa",
"team_id": "T04TVFW6U1F",
"context_team_id": "T04TVFW6U1F",
"context_enterprise_id": null,
"api_app_id": "A05PR43AL6L",
"event": {
"type": "message",
"text": "Delivered",
"files": [
{
"id": "F05UX37CXE4",
"created": 1696361627,
"timestamp": 1696361627,
"name": "20231003_143304.jpg",
"title": "20231003_143304.jpg",
"mimetype": "image/jpeg",
"filetype": "jpg",
"pretty_type": "JPEG",
"user": "U04PD567JNN",
"user_team": "T03TVFW8U1F",
"editable": false,
"size": 737557,
"mode": "hosted",
"is_external": false,
"external_type": "",
"is_public": false,
"public_url_shared": false,
"display_as_bot": false,
"username": "",
"url_private": "https://files.slack.com/files-pri/T04TVFW6U1F-F05UX37CXE1/20231003_143304.jpg",
"url_private_download": "https://files.slack.com/files-pri/T04TVFW6U1F-F05UX37CXE1/download/20231003_143304.jpg",
"media_display_type": "unknown",
"thumb_64": "https://files.slack.com/files-tmb/T04TVFW6U1F-F05UX37CXE1-6f5a931b23/20231003_143304_64.jpg",
"thumb_80": "https://files.slack.com/files-tmb/T04TVFW6U1F-F05UX37CXE1-6f5a931b23/20231003_143304_80.jpg",
"thumb_360": "https://files.slack.com/files-tmb/T04TVFW6U1F-F05UX37CXE1-6f5a931b23/20231003_143304_360.jpg",
"thumb_360_w": 162,
"thumb_360_h": 360,
"thumb_480": "https://files.slack.com/files-tmb/T04TVFW6U1F-F05UX37CXE1-6f5a931b23/20231003_143304_480.jpg",
"thumb_480_w": 216,
"thumb_480_h": 480,
"thumb_160": "https://files.slack.com/files-tmb/T04TVFW6U1F-F05UX37CXE1-6f5a931b23/20231003_143304_160.jpg",
"thumb_720": "https://files.slack.com/files-tmb/T04TVFW6U1F-F05UX37CXE1-6f5a931b23/20231003_143304_720.jpg",
"thumb_720_w": 324,
"thumb_720_h": 720,
"thumb_800": "https://files.slack.com/files-tmb/T04TVFW6U1F-F05UX37CXE1-6f5a931b23/20231003_143304_800.jpg",
"thumb_800_w": 800,
"thumb_800_h": 1778,
"thumb_960": "https://files.slack.com/files-tmb/T04TVFW6U1F-F05UX37CXE1-6f5a931b23/20231003_143304_960.jpg",
"thumb_960_w": 432,
"thumb_960_h": 960,
"thumb_1024": "https://files.slack.com/files-tmb/T04TVFW6U1F-F05UX37CXE1-6f5a931b23/20231003_143304_1024.jpg",
"thumb_1024_w": 461,
"thumb_1024_h": 1024,
"original_w": 1800,
"original_h": 4000,
"thumb_tiny": "AwAwABWFSAOR06VNa8yn6Gq4zyKntRukYH0osBbxRilz6ijNAGZP8s7gdM5qayP71s/3ahZsvgopA43GpkUDkAbTj5h0NMC4etFU55l3hkfORyPSo/PPrSAtU309Ac0tIaAI5o0ZsxqFz1qPyff9Km6UUAf/2Q==",
"permalink": "https://hotshotdelivery.slack.com/files/U04PD567JNL/F05UX37CXE1/20231003_143304.jpg",
"permalink_public": "https://slack-files.com/T04TVFW6U1F-F05UX37CXE1-8b92db02bd",
"has_rich_preview": false,
"file_access": "visible"
},
{
"id": "F06090T343S",
"created": 1696361629,
"timestamp": 1696361629,
"name": "20231003_143249.jpg",
"title": "20231003_143249.jpg",
"mimetype": "image/jpeg",
"filetype": "jpg",
"pretty_type": "JPEG",
"user": "U04PD567JNL",
"user_team": "T04TVFW6U1F",
"editable": false,
"size": 604986,
"mode": "hosted",
"is_external": false,
"external_type": "",
"is_public": false,
"public_url_shared": false,
"display_as_bot": false,
"username": "",
"url_private": "https://files.slack.com/files-pri/T04TVFW6U1F-F06090T343S/20231003_143249.jpg",
"url_private_download": "https://files.slack.com/files-pri/T04TVFW6U1F-F06090T343S/download/20231003_143249.jpg",
"media_display_type": "unknown",
"thumb_64": "https://files.slack.com/files-tmb/T04TVFW6U1F-F06090T343S-4ee942794a/20231003_143249_64.jpg",
"thumb_80": "https://files.slack.com/files-tmb/T04TVFW6U1F-F06090T343S-4ee942794a/20231003_143249_80.jpg",
"thumb_360": "https://files.slack.com/files-tmb/T04TVFW6U1F-F06090T343S-4ee942794a/20231003_143249_360.jpg",
"thumb_360_w": 162,
"thumb_360_h": 360,
"thumb_480": "https://files.slack.com/files-tmb/T04TVFW6U1F-F06090T343S-4ee942794a/20231003_143249_480.jpg",
"thumb_480_w": 216,
"thumb_480_h": 480,
"thumb_160": "https://files.slack.com/files-tmb/T04TVFW6U1F-F06090T343S-4ee942794a/20231003_143249_160.jpg",
"thumb_720": "https://files.slack.com/files-tmb/T04TVFW6U1F-F06090T343S-4ee942794a/20231003_143249_720.jpg",
"thumb_720_w": 324,
"thumb_720_h": 720,
"thumb_800": "https://files.slack.com/files-tmb/T04TVFW6U1F-F06090T343S-4ee942794a/20231003_143249_800.jpg",
"thumb_800_w": 800,
"thumb_800_h": 1778,
"thumb_960": "https://files.slack.com/files-tmb/T04TVFW6U1F-F06090T343S-4ee942794a/20231003_143249_960.jpg",
"thumb_960_w": 432,
"thumb_960_h": 960,
"thumb_1024": "https://files.slack.com/files-tmb/T04TVFW6U1F-F06090T343S-4ee942794a/20231003_143249_1024.jpg",
"thumb_1024_w": 461,
"thumb_1024_h": 1024,
"original_w": 1800,
"original_h": 4000,
"thumb_tiny": "AwAwABWIcnrTnOQMtnHFSLAr5KscA0v2cAZ3GizEOieIIBnB75FP82L+8KqsMNgE0nNFwJYXAQ4z1qVjjIAPI61XQAZBOKkLrnOe1WnoDWpEwyx4zSbT/dNW4AAm7u1S5qLDM/cMU5QWYDHWojyQQOKt24GC1ICVVCqFHQUtFFMD/9k=",
"permalink": "https://hotshotdelivery.slack.com/files/U04PD567JNL/F06090T343S/20231003_143249.jpg",
"permalink_public": "https://slack-files.com/T04TVFW6U1F-F06090T343S-43b45728e6",
"has_rich_preview": false,
"file_access": "visible"
}
],
"upload": false,
"user": "U04PD567JNL",
"ts": "1696361635.105269",
"blocks": [
{
"type": "rich_text",
"block_id": "GO/U",
"elements": [
{
"type": "rich_text_section",
"elements": [
{
"type": "text",
"text": "Packed"
}
]
}
]
}
],
"client_msg_id": "9b72804d-a197-4761-8f20-5909cc0b8705",
"thread_ts": "1696354306.191189",
"parent_user_id": "U05RD458PLZ",
"channel": "C04J69GP70D",
"subtype": "file_share",
"event_ts": "1696361635.105269",
"channel_type": "group"
},
"type": "event_callback",
"event_id": "Ev05UTBGR6TY",
"event_time": 1696361635,
"authorizations": [
{
"enterprise_id": null,
"team_id": "T04TVFW6U1F",
"user_id": "U06PD458PLZ",
"is_bot": true,
"is_enterprise_install": false
}
],
"is_ext_shared_channel": false,
"event_context": "4-eyJldCI6Im1lc3NhZ2UiLCJ0bWQiOiJUMDNUVkZXN1UxRiIsImFpZCI6IkEwNVBRNDNBTDZMIiwiY2lkIjoiQzA0SjY4R1A3MEQifQ"
}
}
]