slackapi / node-slack-interactive-messages

Slack Buttons, Menus, and Dialogs made simpler for Node
MIT License
133 stars 41 forks source link

slackMessages inside or outside slackEvents ? #19

Closed kursusHC closed 7 years ago

kursusHC commented 7 years ago

Description

Hi, I am using both interactive-messages and events-api in my code. I was wondering what is the best way to organize the listeners. What is the proper way between

slackEvents.on('message', (event) => {
    slackMessages.action('callback_id', (payload) => {
        // ... 
    });
}); 

and

slackMessages.action('callback_id', (payload) => {
    // ... 
});
slackEvents.on('message', (event) => {
    // ... 
});

I may have noticed that on my poor quality development server (localtunnel) the first one works slightly better, but it might be totally unrelated.

Thank you for your input.

Requirements

aoberoi commented 7 years ago

here's the difference: if you do it the first way, your application is opting not to deal with any actions with that callback_id until after the first message event arrives. while if you do it the second way, your application is ready to respond to that action right away.

so my advice for most cases is this: use the second way unless your matcher (callback_id or a matching object) is dynamic. by dynamic i mean composed RegEx(s), or string(s) built from that specific message event. that's pretty advanced, and if you're not doing that, then your application will benefit from being able to resume from a restart without the risk of the action handler not being registered in time.

aoberoi commented 7 years ago

closing, but feel free to keep commenting.