Skip to main content

SlackMessenger

SlackMessenger(
    template: str,
    channel: str = 'C08KQFF50GH',
    token: str = None,
    logger: systematica.generic.loggers.Logger = None,
    slack_client: slack_sdk.web.client.WebClient = None,
)
A messenger class for sending messages to Slack. Method generated by attrs for class SlackMessenger.

Ancestors

  • systematica.tools.messengers.base.BaseMessenger
  • abc.ABC
  • systematica.generic.loggers.Logger

Instance variables

  • channel: str: The Slack channel to send messages to. Defaults to ‘#systematica-workflow’
  • logger: systematica.generic.loggers.Logger: Custom logger.
  • slack_client: slack_sdk.web.client.WebClient: A WebClient allows apps to communicate with the Slack Platform Web API. The Slack Web API is an interface for querying information from and enacting change in a Slack workspace.
  • template: str: Template name.
  • token: str: Slack API token.

Methods

send

send(
    self,
    message: str,
    channel: str = None,
)
Send a message to Slack and log it. Parameters:
NameTypeDefaultDescription
messagestr--The message to send.
channelstrNoneThe Slack channel to send messages to. If not None, overwrite the class level channel. Defaults to None.
Raises:
TypeDescription
SlackApiErrorIf the Slack API returns an error while sending the message.

upload

upload(
    self,
    fig: type,
    title: str = None,
    initial_comment: str = None,
    width: int = 800,
    height: int = 1000,
    channel: str = None,
)
Upload a figure to Slack and log the operation:
  • Converts the figure to a PNG image in memory before uploading.
  • Uses the Slack Web API to upload the file to the specified channel.
  • Logs the success or failure of the upload operation.
Parameters:
NameTypeDefaultDescription
figtype--The figure to upload. Typically a Plotly figure object.
titlestrNoneThe title of the uploaded file, by default None.
initial_commentstrNoneAn initial comment to include with the uploaded file, by default None.
widthint800The width of the figure in pixels, by default 800.
heightint1000The height of the figure in pixels, by default 1000.
channelstrNoneThe Slack channel to send messages to. If not None, overwrite the class level channel. Defaults to None.