Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Slack's "file_shared" event not triggered in channels #428

Closed
christian-bick opened this issue Sep 30, 2016 · 5 comments
Closed

Slack's "file_shared" event not triggered in channels #428

christian-bick opened this issue Sep 30, 2016 · 5 comments

Comments

@christian-bick
Copy link

I'm using botkit 0.2.2 with Slack via the RTM-API and want to my bot to react to files being uploaded/shared by users in groups and channels.

The following code works fine for listening to "file_shared" events in groups:

controller.on('file_shared', (bot, file) => {
  console.log(file.file_id);
});

But when a file is uploaded/shared in a channel then the event is not being triggered.

According to the Slack API, the "file_shared" event is the one that should be triggered in my use case. I also tried other event types like "file_created" and "file_public" to make sure that I don't misinterpret anything but as expected that didn't work as well.

I'm running botkit on node 6.5 within in a multi-team setup managed by beepboop-botkit.

@xuanvinh2005
Copy link

I have the same problem with latest master, it even doesn't not work in groups

@jonchurch
Copy link
Contributor

jonchurch commented Nov 4, 2016

@christian-bick Try listening to file_share (exactly the same minus the letter d) to see if you receive it more reliably. They are two different types of events, and the slack docs does not easily differentiate between the two. Ran into these twin events while testing my fork of the Events API, and was confused for a while. I asked their support about it last week, they said they would update the docs perhaps to make it more clear.

EDIT: To clarify, file_shared is an official Slack API event, docs here and file_share is a message subtype, which botkit fires off as an event. See Slack docs for message subtypes

file_share I think is the message that gets sent into a chat, the visible one. Two things happen when files are shared, a file_shared event is fired by Slack and a message is sent into the destination chat (firing a message event). It seems right now it is more reliable to listen for the file_share event (at least in my limited testing).

Oddly enough, the file_share json data contains waaaay more metadata than a file_shared even. The file_shared event only has the file_id to be used with the slack file API to lookup the associated metadata and url.

I think this is one of the many quirks of the RTM api, while trying to replicate your issue I ran into some inconsistency in file_shared being triggered. Hopefully a move to Events API makes things more stable!

Please do report back if this solves your issue 😄

@peterswimm
Copy link
Contributor

@christian-bick Did it fix your issue?

@xuanvinh2005
Copy link

I fixed my issue,

Thanks

@peterswimm
Copy link
Contributor

Closing as resolved

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants