from slack_sdk import WebClient from slack_sdk.models.blocks import HeaderBlock, SectionBlock, DividerBlock class SlackClient: def __init__(self, slack_token, header="bigtable-scaler"): self.slack_client = WebClient(token=slack_token) self.header = header self.default_blocks = [HeaderBlock(text=self.header)] def post_message(self, channel: str, blocks: list[str], icon_emoji: str) -> None: sections = [ b for block in blocks for b in (SectionBlock(text=block), DividerBlock()) ] applied_blocks = self.default_blocks + sections self.slack_client.chat_postMessage(channel=channel, blocks=applied_blocks, text=self.header, icon_emoji=icon_emoji) def post_success_message(self, channel: str, blocks: list[str]) -> None: self.post_message(channel, blocks, ':done:') def post_error_message(self, channel: str, blocks: list[str]) -> None: self.post_message(channel, blocks, ':fire_engine:')