def test_handle_callback_using_options(self): def success(args: SuccessArgs) -> BoltResponse: assert args.request is not None return BoltResponse(status=200, body="customized") def failure(args: FailureArgs) -> BoltResponse: assert args.request is not None assert args.reason is not None return BoltResponse(status=502, body="customized") oauth_flow = OAuthFlow( client=WebClient(base_url=self.mock_api_server_base_url), settings=OAuthSettings( client_id="111.222", client_secret="xxx", scopes=["chat:write", "commands"], installation_store=FileInstallationStore(), state_store=FileOAuthStateStore(expiration_seconds=120), callback_options=CallbackOptions(success=success, failure=failure), ), ) state = oauth_flow.issue_new_state(None) req = BoltRequest( body="", query=f"code=foo&state={state}", headers={ "cookie": [f"{oauth_flow.settings.state_cookie_name}={state}"] }, ) resp = oauth_flow.handle_callback(req) assert resp.status == 200 assert resp.body == "customized" state = oauth_flow.issue_new_state(None) req = BoltRequest( body="", query=f"code=foo&state=invalid", headers={ "cookie": [f"{oauth_flow.settings.state_cookie_name}={state}"] }, ) resp = oauth_flow.handle_callback(req) assert resp.status == 502 assert resp.body == "customized"
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=[ "app_mentions:read", "channels:history", "im:history", "chat:write" ], 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), ), ) @app.command("/hello-bolt-python") def test_command(body, respond, client, ack, logger): logger.info(body) ack("Thanks!") respond(blocks=[{ "type": "section", "block_id": "b", "text": { "type": "mrkdwn", "text": "You can add a button alongside text in your message. ",