nglcobdai_utils.Slack

class Slack(token: str)[source]

Bases: object

A class to interact with Slack API for sending messages and uploading files.

client

The Slack WebClient instance to interact with Slack API.

Type:

WebClient

channels

A list of channels retrieved from Slack.

Type:

list

__init__(token: str)[source]

Initialize the Slack class with an API token.

Parameters:

token (str) – The Slack API token.

get_channels(exclude_archived=True, **kwargs)[source]

Retrieve the list of channels from Slack.

Parameters:
  • exclude_archived (bool) – Whether to exclude archived channels (default: True).

  • **kwargs – Additional keyword arguments passed to the Slack API.

Returns:

A list of channels.

Return type:

list

get_channel_id(channel: str)[source]

Retrieve the ID of a specific Slack channel by its name.

Parameters:

channel (str) – The name of the Slack channel.

Returns:

The ID of the Slack channel if found, otherwise None.

Return type:

str

post_text(channel: str, text: str, **kwargs)[source]

Post a text message to a Slack channel.

Parameters:
  • channel (str) – The name of the Slack channel.

  • text (str) – The message to be posted.

  • **kwargs – Additional keyword arguments passed to the Slack API.

Returns:

The Slack API response.

Return type:

dict

post_file(channel: str, files: list, **kwargs)[source]

Upload a file to a Slack channel.

Parameters:
  • channel (str) – The name of the Slack channel.

  • files (List[Dict]) – A list of dictionaries containing file information.

  • **kwargs – Additional keyword arguments passed to the Slack API.

Example

>>> slack.post_file("general", [{"file": "README.md", "title": "README"}])
Returns:

The Slack API response.

Return type:

dict