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

New event type: 'retry'

Open aoberoi opened this issue 9 years ago • 2 comments

Description

I'd like to propose a new event type that the SlackEventAdapter could emit: retry.

Currently, the only way to be informed that an event is a retry is to use the includeHeaders option and then in each event handler inspect the headers argument. This would have to be done in each event type's handler.

My hypothesis is that the use cases for knowing about retries are usually across all event types, and therefore we could emit it one new event type. The idea is that one incoming HTTP request from Slack's Events API would emit both a retry event and the named event the request contains (if the request was a retry).

Before:

function handleRetry (event, headers) {
  if (headers['x-slack-retry-num']) {
    // do some handling
    console.log(`event ${event.type} retried ${headers['x-slack-retry-num']} times because ${headers['x-slack-retry-reason']}`);
  }
}

slackEvents.on('message', (event, headers) => {
  handleRetry(event, headers);

  // do some handling
  console.log(`user ${event.user} said ${event.text}`);
});

slackEvents.on('group_open', (event, headers) => {
  handleRetry(event, headers);

  // do some handling
  console.log(`user ${event.user} opened private channel ${event.channel}`);
});

After:

slackEvents.on('retry', (retry) => {
  // do some handling
  console.log(`event ${retry.event.type} retried ${retry.num} times because ${retry.reason}`);
});

slackEvents.on('message', (event) => {
  // do some handling
  console.log(`user ${event.user} said ${event.text}`);
});

slackEvents.on('group_open', (event) => {
  console.log(`user ${event.user} opened private channel ${event.channel}`);
});

Open questions:

  • Would the waitForResponse option interact with the retry event in any special way? It seems unlikely given that the hypothesis is that you'd want to handle the real event in a different handler, and that handler would be given the respond() callback, and your app should only invoke it once.
  • Would the includeHeaders and includeBody options have an effect on this event? It seems reasonable.

It would be fantastic to get some feedback on this issue, especially if you can bring up use cases where you'd want to know about retries and what you might do with them.

What type of issue is this? (place an x in one of the [ ])

  • [ ] bug
  • [x] enhancement (feature request)
  • [ ] question
  • [ ] documentation related
  • [ ] testing related
  • [ ] discussion

Requirements

  • [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 Mar 03 '17 00:03 aoberoi

🤔

Roach avatar Mar 03 '17 00:03 Roach

Opened a new issue for this in the new parent repository at https://github.com/slackapi/node-slack-sdk/issues/813

shaydewael avatar Jul 15 '19 21:07 shaydewael