Slack trigger throwing error on audio file create

Describe the problem/error/question

n8n throws an error when audio file is created on slack. Cannot read properties of undefined (reading ‘channel’)

slack bot event subscriptions:
app_mention, file_change, file_created, file_deleted, file_public, file_shared, file_unshared.

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

Please share your workflow

{
“nodes”: [
{
“parameters”: {
“trigger”: [
“any_event”
],
“watchWorkspace”: true,
“options”: {}
},
“type”: “n8n-nodes-base.slackTrigger”,
“typeVersion”: 1,
“position”: [
0,
0
],
“id”: “d7dec3ee-1e4e-44e4-a690-aaaefd59c9fb”,
“name”: “Slack Trigger”,
“webhookId”: “caeb427a-bc34-4777-a060-294caed51584”,
“credentials”: {
“slackApi”: {
“id”: “Hlx2D3Y9YUO4GL7u”,
“name”: “Slack account”
}
}
}
],
“connections”: {},
“pinData”: {},
“meta”: {
“templateCredsSetupCompleted”: true,
“instanceId”: “140aae7712f94af4d3310ad320195dd2d44d5d17781e6b79cf28327c69831591”
}
}

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

  • n8n version: 1.84.1 (Self Hosted)
  • Database (default: SQLite): default
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): docker and ngrok
  • Operating system: macos

Step-by-Step Explanation and Solution:

Understanding the Error

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?

  1. Verify Slack Permissions: Ensure your Slack app has files:read scope.
  2. Test with a Public File: Upload the audio file to a public channel (not DMs).
  3. 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. :wink:

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) {

Was this fixed?
I am having the same error when I upload a file in Slack channel