-
Notifications
You must be signed in to change notification settings - Fork 17
/
app_oauth.py
50 lines (39 loc) · 1.6 KB
/
app_oauth.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import logging
import os
from slack_bolt import App, BoltResponse
from slack_bolt.oauth.callback_options import CallbackOptions, SuccessArgs, FailureArgs
from slack_bolt.oauth.oauth_settings import OAuthSettings
from slack_sdk.oauth.installation_store import FileInstallationStore
from slack_sdk.oauth.state_store import FileOAuthStateStore
from listeners import register_listeners
logging.basicConfig(level=logging.DEBUG)
# Callback to run on successful installation
def success(args: SuccessArgs) -> BoltResponse:
# Call default handler to return an HTTP response
return args.default.success(args)
# return BoltResponse(status=200, body="Installation successful!")
# Callback to run on failed installation
def failure(args: FailureArgs) -> BoltResponse:
return args.default.failure(args)
# return BoltResponse(status=args.suggested_status_code, body=args.reason)
# Initialization
app = App(
signing_secret=os.environ.get("SLACK_SIGNING_SECRET"),
installation_store=FileInstallationStore(),
oauth_settings=OAuthSettings(
client_id=os.environ.get("SLACK_CLIENT_ID"),
client_secret=os.environ.get("SLACK_CLIENT_SECRET"),
scopes=["channels:history", "chat:write", "commands"],
user_scopes=[],
redirect_uri=None,
install_path="/slack/install",
redirect_uri_path="/slack/oauth_redirect",
state_store=FileOAuthStateStore(expiration_seconds=600),
callback_options=CallbackOptions(success=success, failure=failure),
),
)
# Register Listeners
register_listeners(app)
# Start Bolt app
if __name__ == "__main__":
app.start(3000)