async def test_view_update(self): ack = AsyncAck() response: BoltResponse = await ack( response_action="update", view={ "type": "modal", "callbAsyncAck_id": "view-id", "title": { "type": "plain_text", "text": "My App", }, "close": { "type": "plain_text", "text": "Cancel", }, "blocks": [{ "type": "divider", "block_id": "b" }], }, ) assert (response.status, response.body) == ( 200, '{"response_action": "update", ' '"view": {' '"type": "modal", ' '"callbAsyncAck_id": "view-id", ' '"title": {"type": "plain_text", "text": "My App"}, ' '"close": {"type": "plain_text", "text": "Cancel"}, ' '"blocks": [{"type": "divider", "block_id": "b"}]' "}" "}", )
async def test_view_update_2(self): ack = AsyncAck() response: BoltResponse = await ack( response_action="update", view=View( type="modal", callback_id="view-id", title=PlainTextObject(text="My App"), close=PlainTextObject(text="Cancel"), blocks=[DividerBlock(block_id="b")], ), ) assert (response.status, response.body) == ( 200, "" '{"response_action": "update", ' '"view": {' '"blocks": [{"block_id": "b", "type": "divider"}], ' '"callback_id": "view-id", ' '"close": {"text": "Cancel", "type": "plain_text"}, ' '"title": {"text": "My App", "type": "plain_text"}, ' '"type": "modal"' "}" "}", )
async def test_response_type(self): ack = AsyncAck() response: BoltResponse = await ack(text="foo", response_type="in_channel") assert (response.status, response.body) == ( 200, '{"text": "foo", "response_type": "in_channel"}', )
async def run_ack_function_asynchronously( ack: AsyncAck, request: AsyncBoltRequest, response: BoltResponse, ): try: await listener.run_ack_function(request=request, response=response) except Exception as e: # The default response status code is 500 in this case. # You can customize this by passing your own error handler. if response is None: response = BoltResponse(status=500) response.status = 500 if ack.response is not None: # already acknowledged response = None await self.listener_error_handler.handle( error=e, request=request, response=response, ) ack.response = response finally: await self.listener_completion_handler.handle( request=request, response=response)
async def test_option_groups(self): ack = AsyncAck() response: BoltResponse = await ack( text="foo", option_groups=self.sample_option_groups ) assert response.status == 200 assert response.body.startswith('{"option_groups":')
async def test_blocks(self): ack = AsyncAck() response: BoltResponse = await ack(text="foo", blocks=[{"type": "divider"}]) assert (response.status, response.body) == ( 200, '{"text": "foo", "blocks": [{"type": "divider"}]}', )
async def test_options(self): ack = AsyncAck() response: BoltResponse = await ack(text="foo", options=self.sample_options) assert response.status == 200 assert ( response.body == '{"options": [{"text": {"type": "plain_text", "text": "Maru"}, "value": "maru"}]}' )
async def test_attachments(self): ack = AsyncAck() response: BoltResponse = await ack(text="foo", attachments=self.sample_attachments) assert (response.status, response.body) == ( 200, '{"text": "foo", ' '"attachments": [{"fallback": "Plain-text summary of the attachment.", "color": "#2eb886", "pretext": "Optional text that appears above the attachment block", "author_name": "Bobby Tables", "author_link": "http://flickr.com/bobby/", "author_icon": "http://flickr.com/icons/bobby.jpg", "title": "Slack API Documentation", "title_link": "https://api.slack.com/", "text": "Optional text that appears within the attachment", "fields": [{"title": "Priority", "value": "High", "short": false}], "image_url": "http://my-website.com/path/to/image.jpg", "thumb_url": "http://example.com/path/to/thumb.png", "footer": "Slack API", "footer_icon": "https://platform.slack-edge.com/img/default_application_icon.png", "ts": 123456789}]' "}", )
async def test_dialog_errors(self): expected_body = '{"errors": [{"name": "loc_origin", "error": "Pickup Location must be longer than 3 characters"}]}' errors = [{ "name": "loc_origin", "error": "Pickup Location must be longer than 3 characters", }] ack = AsyncAck() response: BoltResponse = await ack(errors=errors) assert (response.status, response.body) == (200, expected_body) response: BoltResponse = await ack({"errors": errors}) assert (response.status, response.body) == (200, expected_body)
def ack(self) -> AsyncAck: """`ack()` function for this request. @app.action("button") async def handle_button_clicks(context): await context.ack() # You can access "ack" this way too. @app.action("button") async def handle_button_clicks(ack): await ack() Returns: Callable `ack()` function """ if "ack" not in self: self["ack"] = AsyncAck() return self["ack"]
async def test_view_errors(self): ack = AsyncAck() response: BoltResponse = await ack( response_action="errors", errors={ "block_title": "Title is required", "block_description": "Description must be longer than 10 characters", }, ) assert (response.status, response.body) == ( 200, '{"response_action": "errors", ' '"errors": {' '"block_title": "Title is required", ' '"block_description": "Description must be longer than 10 characters"' "}" "}", )
def ack(self) -> AsyncAck: if "ack" not in self: self["ack"] = AsyncAck() return self["ack"]
async def test_text(self): ack = AsyncAck() response: BoltResponse = await ack(text="foo") assert (response.status, response.body) == (200, "foo")