Repository navigation
refactor: register listeners with decorators and load them automatically - #95
Draft
WilliamBergamin wants to merge 9 commits into
Draft
WilliamBergamin wants to merge 9 commits into
WilliamBergamin wants to merge 9 commits into
Conversation
Each listener now decorates its own callback with @app.<kind>(...) and bolt_app.py imports every module under listeners/ with walk_packages, so adding a listener means adding a file instead of editing register() functions. bolt_app.py owns the App for both Socket Mode and OAuth: the OAuth settings turn on when SLACK_CLIENT_ID is set, and app_oauth.py is now a thin starter you rename to app.py. Tests turn off token verification through SLACK_TOKEN_VERIFICATION_ENABLED. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Each entry file builds its own App again and passes it to load_listeners, which sets listeners.app before importing the listener modules. Listeners decorate with `from listeners import app`, and since the listeners package is never __main__ there is one App whether the app starts from app.py, slack run, or app_oauth.py. Switching to OAuth is now: delete app.py and rename app_oauth.py to app.py. This drops bolt_app.py, the env-switched OAuth settings, and the token verification flag; tests build their own App in conftest. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
… a plain walker The entry file now hands its App over with `listeners.app = app` before calling `listeners.load_listeners()`, so load_listeners only walks the package and the happy path reads as two plain lines. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
listeners/__init__.py now builds the default App from SLACK_BOT_TOKEN, so app.py only imports app and load_listeners. Token verification is deferred to the first request so importing listeners makes no API call. app_oauth.py overrides listeners.app with its OAuth app before loading the listeners, and tests set SLACK_BOT_TOKEN in pytest_configure. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
This reverts commit bd0bd06. The App belongs in the entry file, so app.py builds it with token verification on and hands it to the listeners with `listeners.app = app`. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
…ation Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
…isteners Listener modules no longer import a shared listeners.app that app.py must set first. Decorators record onto a registry, and load_listeners(app) applies them, so any number of App instances can load the same listeners (for example in tests). Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
load_listeners(app) stores the app as listeners.app and then imports every listener module, so each listener file imports the app and decorates its callback directly. Drops the registry, which added more indirection than the starter template needs. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
The listener and OAuth sections on main stay accurate with decorator listeners, and app_oauth.py still runs on its own. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This pull request lets each listener register itself with a decorator, so adding a listener is just adding a file.
app.pycreates the app and callsload_listeners(app), which shares it aslisteners.appand imports every module underlisteners/.register()functions in eachlisteners/*/__init__.pyare removed.app_oauth.pyworks the same way. To use OAuth, deleteapp.pyand renameapp_oauth.pytoapp.py.Testing
SLACK_BOT_TOKENandSLACK_APP_TOKEN, runslack run, and confirm the App Home tab,/sample-command, the "hi" message, the shortcut, and the modal all still work.app.py, renameapp_oauth.pytoapp.py, setSLACK_CLIENT_ID,SLACK_CLIENT_SECRET, andSLACK_SIGNING_SECRET, then runpython3 app.pybehindngrok http 3000. Install through/slack/installand confirm the listeners respond.🤖 Generated with Claude Code