n8n icon indicating copy to clipboard operation
n8n copied to clipboard

Slack Trigger node throws errors on `File Shared` event

Open krzysztof-pyrzyk-ah opened this issue 1 year ago • 9 comments

Bug Description

Slack Trigger node throws erros when listening on File Shared event:

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 Workflow.runWebhook (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/dist/Workflow.js:660:38) at Object.executeWebhook (/usr/local/lib/node_modules/n8n/dist/webhooks/webhook-helpers.js:144:48) at processTicksAndRejections (node:internal/process/task_queues:95:5) at /usr/local/lib/node_modules/n8n/dist/webhooks/test-webhooks.js:101:37.

image

This trigger fails on files of any type or size.

Slack App Event Subscription and Scopes are configured properly.

To Reproduce

  1. Configure Slack App with all recommended scopes and Event Subscription on file sharing event.
  2. Add Slack Trigger node to a workflow and make it listen on file sharing.
  3. Tets the trigger.
  4. Post file on Slack.
  5. See described error.

Expected behavior

Uploaded file is being captured by the treigger propery and is available as an output from the node.

Operating System

Oracle Linux 9

n8n Version

1.69.2

Node.js Version

20.18.0

Database

SQLite (default)

Execution mode

main (default)

krzysztof-pyrzyk-ah avatar Dec 01 '24 23:12 krzysztof-pyrzyk-ah

Hey @krzysztof-pyrzyk-ah,

We have created an internal ticket to look into this which we will be tracking as "GHC-541"

Joffcom avatar Dec 01 '24 23:12 Joffcom

Hey @Joffcom Is this resolved? I am getting same error.

DeepakJaiz avatar Apr 01 '25 12:04 DeepakJaiz

Getting the same error

andreygargul avatar Apr 10 '25 19:04 andreygargul

Is there an alternative here?

wanshot avatar Apr 21 '25 14:04 wanshot

This is happening because the file_share event uses the channel_id attribute and the existing trigger code doesn't handle it. I've posted about this here: https://community.n8n.io/t/slack-trigger-throwing-error-on-audio-file-create/92364/3

I am unable to build n8n, so can't test this out, but something like this diff should fix the problem if anyone is up for testing it locally and creating a pull request:

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

esjewett avatar May 02 '25 05:05 esjewett

I can validate that the slack trigger is successful if the above change happens as suggested by @esjewett . I built n8n locally using the above change and validated.

Image

sfc-gh-puneet-lakhanpal avatar May 15 '25 19:05 sfc-gh-puneet-lakhanpal

Getting the same error. Also noticed its inconsistent sometimes it works and other times it does not.

josediaz1208 avatar May 27 '25 16:05 josediaz1208

the same error, version [email protected]

igdr avatar Jun 13 '25 07:06 igdr

I was able to fix the error and use it in my local environment. However, it was a long process. Can we please fix this ?

Here's what i did on my end to get this working -

Fork the n8n repo and git clone it to your local. On mac: set it up like this: brew install node@22 echo 'export PATH="/opt/homebrew/opt/node@22/bin:$PATH"' >> /Users/<USERNAME>/.zshrc brew install corepack corepack enable corepack prepare pnpm --activate conda create -n n8n python=3.10 conda activate n8n pip install setuptools echo "python=/opt/anaconda3/envs/n8n/bin/python" >> .npmrc pnpm install

I made the change as documented here - https://github.com/n8n-io/n8n/issues/11994#issuecomment-2846344075

then built a new docker image like below: Modified the line number 11 and 12 in docker/images/n8n/Dockerfile as below: ENV NODE_OPTIONS='--max-old-space-size=16384' RUN pnpm build || (echo "Build failed, retrying with more debugging" && NODE_OPTIONS='--max-old-space-size=16384' pnpm build)

Then run docker build --platform linux/amd64 -t n8ncustom -f docker/images/n8n/Dockerfile .

and then use the FROM docker.io/library/n8ncustom:latest to create whatever docker container you need

sfc-gh-puneet-lakhanpal avatar Jun 13 '25 07:06 sfc-gh-puneet-lakhanpal

Cmon guys this such an easy fix please follow up on this @Joffcom

falzfalzfalz avatar Jun 24 '25 21:06 falzfalzfalz

I tried to implement automatic invoice processing by allowing user to upload their invoices onto slack. This is a blocking factor.

JohnYeung-dojjy avatar Jun 25 '25 03:06 JohnYeung-dojjy

Hi! I was able to reproduce this issue in my local environment and got the same error "Cannot read properties of undefined (reading 'channel')" at first. Then I applied the code changes suggested by @esjewett, build, tested again in a production mode, and it worked perfectly. I’m going to open a PR to fix this problem for Slack users who want to use this functionality in n8n. Hope this helps!

Chesars avatar Aug 16 '25 18:08 Chesars