Slack Trigger node throws errors on `File Shared` event
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.
This trigger fails on files of any type or size.
Slack App Event Subscription and Scopes are configured properly.
To Reproduce
- Configure Slack App with all recommended scopes and Event Subscription on file sharing event.
- Add Slack Trigger node to a workflow and make it listen on file sharing.
- Tets the trigger.
- Post file on Slack.
- 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)
Hey @krzysztof-pyrzyk-ah,
We have created an internal ticket to look into this which we will be tracking as "GHC-541"
Hey @Joffcom Is this resolved? I am getting same error.
Getting the same error
Is there an alternative here?
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) {
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.
Getting the same error. Also noticed its inconsistent sometimes it works and other times it does not.
the same error, version [email protected]
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
Cmon guys this such an easy fix please follow up on this @Joffcom
I tried to implement automatic invoice processing by allowing user to upload their invoices onto slack. This is a blocking factor.
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!