def test_basic_json(self): self.elements = [ ImageElement( image_url= "https://api.slack.com/img/blocks/bkb_template_images/palmtree.png", alt_text="palmtree"), PlainTextObject(text="Just text"), ] e = { "elements": [ { "type": "image", "image_url": "https://api.slack.com/img/blocks/bkb_template_images/palmtree.png", "alt_text": "palmtree" }, { "type": "plain_text", "text": "Just text" }, ], "type": "context", } d = ContextBlock(elements=self.elements).to_dict() self.assertDictEqual(e, d) with self.assertRaises(SlackObjectFormationError): ContextBlock(elements=self.elements * 6).to_dict()
def test_document(self): input = { "type": "context", "elements": [ { "type": "image", "image_url": "https://image.freepik.com/free-photo/red-drawing-pin_1156-445.jpg", "alt_text": "images", }, {"type": "mrkdwn", "text": "Location: **Dogpatch**"}, ], } self.assertDictEqual(input, ContextBlock(**input).to_dict()) self.assertDictEqual(input, Block.parse(input).to_dict())
def context(self, *, elements: List[InteractiveElement], block_id: Optional[str] = None): """Displays message context, which can include both images and text. https://api.slack.com/reference/block-kit/blocks#context Args: elements: Up to 10 ImageElements and TextObjects block_id: ID to be used for this block - autogenerated if left blank. Cannot exceed 255 characters. """ self._blocks.append(ContextBlock(elements=elements, block_id=block_id)) return self
def test_home_tab_construction(self): home_tab_view = View( type="home", blocks=[ SectionBlock(text=MarkdownTextObject( text="*Here's what you can do with Project Tracker:*"), ), ActionsBlock(elements=[ ButtonElement( text=PlainTextObject(text="Create New Task", emoji=True), style="primary", value="create_task", ), ButtonElement( text=PlainTextObject(text="Create New Project", emoji=True), value="create_project", ), ButtonElement( text=PlainTextObject(text="Help", emoji=True), value="help", ), ], ), ContextBlock(elements=[ ImageElement( image_url= "https://api.slack.com/img/blocks/bkb_template_images/placeholder.png", alt_text="placeholder", ), ], ), SectionBlock( text=MarkdownTextObject(text="*Your Configurations*"), ), DividerBlock(), SectionBlock( text=MarkdownTextObject( text= "*#public-relations*\n<fakelink.toUrl.com|PR Strategy 2019> posts new tasks, comments, and project updates to <fakelink.toChannel.com|#public-relations>" ), accessory=ButtonElement( text=PlainTextObject(text="Edit", emoji=True), value="public-relations", ), ), ], ) home_tab_view.validate_json()
def update_message(self, request: GladosRequest, **kwargs): message = Message( text=request.json.message, blocks=[ ContextBlock(elements=[ MarkdownTextObject( text= f"Message Updated: {datetime.now().isoformat(sep=' ', timespec='minutes')}" ) ]), SectionBlock(text=MarkdownTextObject( text=request.json.message)), ], ) return self.bot.update_message(channel=request.json.channel, ts=request.json.ts, message=message)
def test_basic_json(self): d = ContextBlock(elements=self.elements).to_dict() e = { "elements": [ { "type": "image", "image_url": "http://google.com", "alt_text": "google", }, { "type": "plain_text", "emoji": True, "text": "Just text" }, ], "type": "context", } self.assertDictEqual(d, e)
def test_elements_length(self): with self.assertRaises(SlackObjectFormationError): ContextBlock(elements=self.elements * 6).to_dict()