it works fine if i do a bot mention and send text.
What is the error message (if any)?
n8n version
1.84.1 (Self Hosted)
Stack trace
TypeError: Cannot read properties of undefined (reading 'channel') at WebhookContext.webhook (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Slack/SlackTrigger.node.js:299:76) at WebhookService.runWebhook (/usr/local/lib/node_modules/n8n/dist/webhooks/webhook.service.js:181:39) at Object.executeWebhook (/usr/local/lib/node_modules/n8n/dist/webhooks/webhook-helpers.js:196:92) at processTicksAndRejections (node:internal/process/task_queues:95:5) at /usr/local/lib/node_modules/n8n/dist/webhooks/test-webhooks.js:112:37
The error Cannot read properties of undefined (reading 'channel') occurs because the SlackTrigger node expects a channel property in the event payload when a file is created. However, Slack’s file_created event doesn’t include event.channel directly. Instead, the channel info is nested inside event.file.channels[].
Why This Happens
For app_mention events: Slack sends event.channel directly.
For file_created events: The channel ID is stored in event.file.channels[0].
The SlackTrigger node assumes event.channel exists for all events, which isn’t true for files.
The Fix (Workaround)
1. Add a Function Node to Handle file_created Events
After the SlackTrigger node, add a Function Node to reformat the data:
// Check if it's a file_created event
if ($json.body.event.type === 'file_created') {
// Extract channel from the file's first shared channel
const channel = $json.body.event.file.channels[0] || 'unknown_channel';
// Rebuild the payload to match what n8n expects
return {
event: {
...$json.body.event,
channel: channel,
},
file: $json.body.event.file
};
}
// For other events (like app_mention), pass data as-is
return $json;
2. Update Subsequent Nodes
Modify nodes that use {{ $json.event.channel }} to handle the reformatted data from the Function Node.
Prevent Future Errors
Filter Events Early: Add an IF Node after the SlackTrigger to skip non-file events:
{{ $json.body.event.type === 'file_created' }}
Error Handling: Add a Catch Node to log errors and avoid workflow crashes.
Full Workflow Example
SlackTrigger (file_created) → IF Node (filter file_created) → Function Node (fix channel) → Your Logic
Still Stuck?
Verify Slack Permissions: Ensure your Slack app has files:read scope.
Test with a Public File: Upload the audio file to a public channel (not DMs).
Check for File Metadata: Use a Debug Node to inspect the raw payload from Slack.
Need more help? Share a screenshot of the Slack event payload (hide sensitive data) or drop a comment below!
Catch you later!
Dandy
P.S. If you’re feeling adventurous, you could also modify the SlackTrigger.node.js code directly (not recommended for production!). But the Function Node fix above is safer.
I’m having the same problem and I’m a little confused about the answer given here, since the trigger node itself fails. Putting another node after it doesn’t seem like a solution that will work.
It looks to me like this diff would fix the problem with the file_share event, which expects a channel_id and would at least lead to an undefined value instead of an exception for file creation (that event doesn’t seem to provide a channel). Unfortunately I’m currently unable to build n8n locally as I have an out of memory error and don’t have time to work through it. If anyone has a working build system and would be up for testing this and submitting a pull request, that’d be a life-saver.
--- a/packages/nodes-base/nodes/Slack/SlackTrigger.node.ts
+++ b/packages/nodes-base/nodes/Slack/SlackTrigger.node.ts
@@ -343,7 +343,10 @@ export class SlackTrigger implements INodeType {
}
if (eventType !== 'team_join') {
- eventChannel = req.body.event.channel ?? req.body.event.item.channel;
+ eventChannel =
+ req.body.event.channel ??
+ req.body.event.item?.channel ??
+ req.body.event.channel_id;
// Check for single channel
if (!watchWorkspace) {