> ## Documentation Index
> Fetch the complete documentation index at: https://systematica.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Slack

> systematica.tools.messengers.slack

## `SlackMessenger`

```python theme={null}
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](https://api.slack.com/methods). 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`

```python theme={null}
send(
    self,
    message: str,
    channel: str = None,
)
```

Send a message to Slack and log it.

**Parameters**:

| Name      | Type  | Default | Description                                                                                              |
| --------- | ----- | ------- | -------------------------------------------------------------------------------------------------------- |
| `message` | `str` | `--`    | The message to send.                                                                                     |
| `channel` | `str` | `None`  | The Slack channel to send messages to. If not None, overwrite the class level channel. Defaults to None. |

**Raises**:

| Type            | Description                                                  |
| --------------- | ------------------------------------------------------------ |
| `SlackApiError` | If the Slack API returns an error while sending the message. |

#### `upload`

```python theme={null}
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**:

| Name              | Type   | Default | Description                                                                                              |
| ----------------- | ------ | ------- | -------------------------------------------------------------------------------------------------------- |
| `fig`             | `type` | `--`    | The figure to upload. Typically a Plotly figure object.                                                  |
| `title`           | `str`  | `None`  | The title of the uploaded file, by default None.                                                         |
| `initial_comment` | `str`  | `None`  | An initial comment to include with the uploaded file, by default None.                                   |
| `width`           | `int`  | `800`   | The width of the figure in pixels, by default 800.                                                       |
| `height`          | `int`  | `1000`  | The height of the figure in pixels, by default 1000.                                                     |
| `channel`         | `str`  | `None`  | The Slack channel to send messages to. If not None, overwrite the class level channel. Defaults to None. |
