async def test_lazy(self): async def just_ack(ack): await ack() async def async1(say): await asyncio.sleep(0.3) await say(text="lazy function 1") async def async2(say): await asyncio.sleep(0.5) await say(text="lazy function 2") app = AsyncApp( client=self.web_client, signing_secret=self.signing_secret, ) app.action("a")( ack=just_ack, lazy=[async1, async2], ) request = self.build_valid_request() response = await app.async_dispatch(request) assert response.status == 200 await asyncio.sleep(1) # wait a bit assert self.mock_received_requests["/chat.postMessage"] == 2
async def test_default(self): async def failing_listener(): raise Exception("Something wrong!") app = AsyncApp(client=self.web_client, signing_secret=self.signing_secret,) app.action("a")(failing_listener) request = self.build_valid_request() response = await app.async_dispatch(request) assert response.status == 500
async def test_custom(self): async def error_handler(logger, payload, response): logger.info(payload) response.headers["x-test-result"] = ["1"] async def failing_listener(): raise Exception("Something wrong!") app = AsyncApp(client=self.web_client, signing_secret=self.signing_secret,) app.error(error_handler) app.action("a")(failing_listener) request = self.build_valid_request() response = await app.async_dispatch(request) assert response.status == 500 assert response.headers["x-test-result"] == ["1"]
def test_listener_registration_error(self): app = AsyncApp(signing_secret="valid", token="xoxb-xxx") with pytest.raises(BoltError): app.action({"type": "invalid_type", "action_id": "a"})(self.simple_listener)
def test_non_coroutine_func_listener(self): app = AsyncApp(signing_secret="valid", token="xoxb-xxx") with pytest.raises(BoltError): app.action("a")(self.non_coro_func)
] } ) @app.view("view-id") async def handle_view_submission(ack, body, logger): await ack() logger.info(body["view"]["state"]["values"]) async def ack_button_click(ack, respond): await ack() await respond("Loading ...") async def respond_5_seconds_later(respond): await asyncio.sleep(5) await respond("Completed!") app.action("a")(ack=ack_button_click, lazy=[respond_5_seconds_later]) if __name__ == "__main__": app.start(3000) # pip install slack_bolt # export SLACK_SIGNING_SECRET=*** # export SLACK_BOT_TOKEN=xoxb-*** # python modals_app.py