slackapi / bolt-js

A framework to build Slack apps using JavaScript
https://slack.dev/bolt-js
MIT License
2.73k stars 390 forks source link

Have code suggestion log message for unmatched request patterns #954

Open seratch opened 3 years ago

seratch commented 3 years ago

Description

As we implemented in Python and Java, we can provide the similar guidance log messages in Bolt for JS.

$ npx node app.js
⚡️ Bolt app is running!

Unhandled request ({"event": {"type": "message"}, "type": "event_callback"})
---
[Suggestion] You can handle this type of event with the following listener function:

app.event("message", async ({ body, logger }) => {
  logger.info(body);
});

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

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

TheManWhoStaresAtCode commented 2 years ago

As I was debugging my event listener in the app for quite some time and I think this functionality would have helped me a lot I would love to contribute here. However, I'm quite unsure where I need to do the required adjustments - where is this statement Unhandled request ({"event": {"type": "message"}, "type": "event_callback"}) actually logged?

Apart from this starting point, I checked the python implementation here and would have implemented it very similar also here. Is this what was intended by you?

seratch commented 2 years ago

@TheManWhoStaresAtCode Yes, this issue is for implementing the same (or mostly the same) thing with bolt-python / bolt-java. Checking the test code may be also helpful. https://github.com/slackapi/bolt-python/blob/main/tests/slack_bolt/logger/test_unmatched_suggestions.py

TheManWhoStaresAtCode commented 2 years ago

Ok thanks will also check this test code. However, I still don't know where to put the respective code in the TS project. Can you point me at least to the proper file?

seratch commented 2 years ago

Although I haven't taken time to thoroughly think about the best design yet, in the case of bolt-js, the unhandled request error logging is done on the receiver side. Thus, you can place a reusable (= it does not depend on any specific modules/packages such as Node's http module interface) utility as a new file under the receivers directory and import it in each receiver.