node-slack-events-api icon indicating copy to clipboard operation
node-slack-events-api copied to clipboard

Listen for any event

Open aoberoi opened this issue 8 years ago • 3 comments

Description

You might want to structure an application such that all incoming events are handled by the same function. Maybe you want to use the signature verification facilities of this package, but want to dispatch to your own routing system. Or maybe your application forwards all events on to another micro-service or system. Maybe your application wants to log all events it sees, or implement some other form of "middleware" on event processing.

It would be useful to design a solution where all the mentioned use cases can be addressed. At this point, I'm not proposing a specific API, but the maintainers are interested in hearing proposals for APIs from the community.

Requirements (place an x in each of the [ ])

  • [x] I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • [x] I've read and agree to the Code of Conduct.
  • [x] I've searched for any related issues and avoided creating a duplicate issue.

aoberoi avatar Sep 04 '18 23:09 aoberoi

I would like to upvote this idea as if I have for example logic for message and app_mention events that should be handled as one single function, I can't group the code to handle the logic. I'm stuck with the situation when both functions are called and there is no way to call the function like: slackEvents.on(['app_mention', 'message'], async (message) => { A bug is following:

  • user write in a pm to bot with mentioning structure -> @bot can you tell me?. In my bot configurations, I need to track mentioning and private messaging. hence I will get a hit of 2 events in my server instead of availability to catch single response logic.

osapishchuk avatar Dec 05 '18 10:12 osapishchuk

@Gektorian thanks for the interest. for your specific case i think you should be able to do something like the following:

slackEvents.on('app_mention', mentionListener);
slackEvents.on('message', mentionListener);

function messageListener(event) {
  // both event types will trigger this function
}

It seems like what you might want is possibly RegEx event type matching, so that you could express \app_mention|message\. Is that more likely to fit your need?

aoberoi avatar Dec 14 '18 02:12 aoberoi

https://github.com/slackapi/node-slack-sdk/issues/819

shaydewael avatar Jul 16 '19 20:07 shaydewael