def test_send(self): client = WebhookClient("http://localhost:8888") resp: WebhookResponse = client.send(text="hello!") self.assertEqual(200, resp.status_code) self.assertEqual("ok", resp.body) resp = client.send(text="hello!", response_type="in_channel") self.assertEqual("ok", resp.body)
def test_send_blocks(self): client = WebhookClient("http://localhost:8888") resp = client.send( text="hello!", response_type="ephemeral", blocks=[ SectionBlock(text="Some text"), ImageBlock(image_url="image.jpg", alt_text="an image") ] ) self.assertEqual("ok", resp.body) resp = client.send( text="hello!", response_type="ephemeral", blocks=[ { "type": "section", "text": { "type": "mrkdwn", "text": "This is a mrkdwn section block :ghost: *this is bold*, and ~this is crossed out~, and <https://google.com|this is a link>" } }, { "type": "divider" }, { "type": "section", "text": { "type": "mrkdwn", "text": "Pick a date for the deadline." }, "accessory": { "type": "datepicker", "initial_date": "1990-04-28", "placeholder": { "type": "plain_text", "text": "Select a date", } } } ] ) self.assertEqual("ok", resp.body) resp = client.send( text="hello!", response_type="ephemeral", blocks=[ SectionBlock(text="Some text"), ImageBlock(image_url="image.jpg", alt_text="an image") ] ) self.assertEqual("ok", resp.body)
def test_send_with_url_unfurl_opts_issue_1045(self): client = WebhookClient("http://localhost:8888") resp: WebhookResponse = client.send( text="<https://imgs.xkcd.com/comics/1991_and_2021_2x.png|XKCD>", unfurl_links=False, unfurl_media=False, ) self.assertEqual(200, resp.status_code) self.assertEqual("ok", resp.body)
def test_send_attachments(self): client = WebhookClient("http://localhost:8888") resp = client.send( text="hello!", response_type="ephemeral", attachments=[ { "color": "#f2c744", "blocks": [ { "type": "section", "text": { "type": "mrkdwn", "text": "This is a mrkdwn section block :ghost: *this is bold*, and ~this is crossed out~, and <https://google.com|this is a link>", }, }, {"type": "divider"}, { "type": "section", "text": { "type": "mrkdwn", "text": "Pick a date for the deadline.", }, "accessory": { "type": "datepicker", "initial_date": "1990-04-28", "placeholder": { "type": "plain_text", "text": "Select a date", }, }, }, ], } ], ) self.assertEqual("ok", resp.body) resp = client.send( text="hello!", response_type="ephemeral", attachments=[ Attachment( text="attachment text", title="Attachment", fallback="fallback_text", pretext="some_pretext", title_link="link in title", fields=[ AttachmentField( title=f"field_{i}_title", value=f"field_{i}_value" ) for i in range(5) ], color="#FFFF00", author_name="John Doe", author_link="http://johndoeisthebest.com", author_icon="http://johndoeisthebest.com/avatar.jpg", thumb_url="thumbnail URL", footer="and a footer", footer_icon="link to footer icon", ts=123456789, markdown_in=["fields"], ) ], ) self.assertEqual("ok", resp.body)