I ended up using the Slack Bolt library which supports all the new slack features and events.
By doing that you gain access to the full message body
, which also includes the event
attribute, in which you can find files
array.
Code sample:
const { App } = require('@slack/bolt');
const app = new App({
token: process.env.SLACK_BOT_TOKEN,
signingSecret: process.env.SLACK_SIGNING_SECRET,
socketMode: true,
appToken: process.env.SLACK_APP_TOKEN
});
// Listens to incoming messages that contain "hello"
app.message('hello', async ({ message, say, logger, body, event }) => {
// notice event.files
logger.info('Body', body, 'Files', event.files);
await say(`Hey there <@${message.user}>!`);
});
This message will react to any message containing "hello", log files
array within event
and reply with a friendly message.
Example files
array logged by the logger (3 seconds voice memo in this case):
[
{
id: '<file-id>',
created: 1671452738,
timestamp: 1671452738,
name: 'audio_message.webm',
title: 'audio_message.webm',
mimetype: 'audio/webm',
filetype: 'webm',
pretty_type: 'WebM',
user: '<user-id>',
user_team: '<team-id>',
editable: false,
size: 39033,
mode: 'hosted',
is_external: false,
external_type: '',
is_public: false,
public_url_shared: false,
display_as_bot: false,
username: '',
subtype: 'slack_audio',
transcription: { status: 'processing' },
url_private: 'https://files.slack.com/files-tmb/<ids>/audio_message_audio.mp4',
url_private_download: 'https://files.slack.com/files-tmb/<ids>/download/audio_message_audio.mp4',
duration_ms: 2421,
aac: 'https://files.slack.com/files-tmb/<ids>/audio_message_audio.mp4',
audio_wave_samples: [
1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 12, 37, 47, 54, 62, 68, 79, 80, 58,
39, 30, 22, 18, 46, 82, 87, 90, 94, 100, 96, 72,
51, 76, 77, 62, 38, 47, 51, 51, 60, 68, 70, 60,
52, 42, 54, 66, 62, 61, 63, 50, 53, 55, 58, 47,
40, 36, 32, 27, 23, 16, 11, 6, 4, 4, 4, 3,
2, 2, 4, 5, 4, 3, 3, 3, 2, 2, 2, 2,
1, 1, 1, 1
],
media_display_type: 'audio',
permalink: 'https://<workplace-id>.slack.com/files/<file-id>/audio_message.webm',
permalink_public: 'https://slack-files.com/<file-id>',
has_rich_preview: false,
file_access: 'visible'
}
]
I couldn't find any specific documentation about sending files to a slack bot, hopefully that helps.