# Slack

{% hint style="info" %}
The following documentation is for **Slack v2.0.0** *(BDK)*.
{% endhint %}

## Overview

Slack is a leading business communication platform featuring channels, direct messaging, and integrations. This integration allows automated message sending, channel management, file sharing, and team notification workflows. Enhance team communication and streamline collaborative work processes.

## Prerequisites

### 1. Required Books

The following Book(s) need to be added to your agent so it can learn and understand the automation procedures defined within them:

* **Slack**

#### How to Add the Book(s)

1. Go to **Books** → **All Books**.
2. Search for the name of the book and click on it.
3. Click on <kbd>**Install**</kbd> or <kbd>**Add Connection**</kbd> to add the book to your agent.
4. If adding a connection, you'll be prompted for [**connectivity**](#connectivity) details.

## Connectivity

This section outlines the available methods for connecting to the Book, along with the required configuration details for each.

### Connect using Token

Connect to an API using the provided API key.

| Label | Description     | Type        |
| ----- | --------------- | ----------- |
| Token | The Slack token | `sensitive` |

### Configuration

The following table details all the available configuration options for this book.

| Concept    | Description                                       | Type     | Default Value |
| ---------- | ------------------------------------------------- | -------- | ------------- |
| `timeout`  | Timeout in seconds when making API calls to Slack | `number` | 30            |
| `timezone` | Timezone info for the slack API call              | `text`   | Etc/UTC       |

Configuration can be set or retrieved as shown in the following examples:

```generic
the department's Slack's timeout is 30
```

```generic
the department's Slack's timezone is Etc/UTC
```

## Procedures

### to read the (item's messages)

![FILTER - CAPABLE](https://img.shields.io/static/v1?label=FILTER\&message=CAPABLE\&color=blue)

Read messages from a channel.

**Input Concepts**

| Concept | Description                               | Type                            | Required | Default Value |
| ------- | ----------------------------------------- | ------------------------------- | -------- | ------------- |
| `item`  | The channel or user to read messages from | `slack channel` or `slack user` | Yes      | (no default)  |

**Output Concepts**

| Concept                             | Description                             | Type            |
| ----------------------------------- | --------------------------------------- | --------------- |
| [`item's messages`](#slack-message) | List of messages retrieved successfully | `slack message` |

**Examples**

Read messages from Slack

```generic
retrieve a channel from slack
    the channel name is "general"
read the channel's messages whose timestamp is lower than "2023-01-01"
```

### to retrieve a (channel) from slack

Retrieve a channel from Slack.

**Input Concepts**

| Concept        | Description                         | Type   | Required | Default Value |
| -------------- | ----------------------------------- | ------ | -------- | ------------- |
| `channel name` | The name of the channel to retrieve | `text` | Yes      | (no default)  |

**Output Concepts**

| Concept                     | Description                                   | Type            |
| --------------------------- | --------------------------------------------- | --------------- |
| [`channel`](#slack-channel) | Details of the channel retrieved successfully | `slack channel` |

**Examples**

Retrieve the channel from Slack

```generic
retrieve the channel from slack
    the channel name is "general"
```

### to retrieve a (user) from slack

Retrieve a user from Slack.

**Input Concepts**

| Concept     | Description                      | Type   | Required | Default Value |
| ----------- | -------------------------------- | ------ | -------- | ------------- |
| `user name` | The name of the user to retrieve | `text` | Yes      | (no default)  |

**Output Concepts**

| Concept               | Description                                | Type         |
| --------------------- | ------------------------------------------ | ------------ |
| [`user`](#slack-user) | Details of the user retrieved successfully | `slack user` |

**Examples**

Retrieve the user from Slack

```generic
retrieve the user from slack
    the user name is "John Doe"
```

### to send message to an item

Send a message to a channel or user.

**Input Concepts**

| Concept                            | Description                                | Type                                                                                                                                                                     | Required | Default Value |
| ---------------------------------- | ------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------- | ------------- |
| `item`                             | The channel or user to send the message to | `slack channel` or `slack user`                                                                                                                                          | Yes      | (no default)  |
| `message`                          | The message to send                        | `text`                                                                                                                                                                   | Yes      | (no default)  |
| `blocks`                           | The blocks to send                         | `slack action block` or `slack context block` or `slack divider block` or `slack header block` or `slack image block` or `slack markdown block` or `slack section block` | No       | (no default)  |
| [`attachments`](#slack-attachment) | The attachments to send                    | `slack attachment`                                                                                                                                                       | No       | (no default)  |

**Output Concepts**

| Concept                    | Description                              | Type            |
| -------------------------- | ---------------------------------------- | --------------- |
| [`answer`](#slack-message) | Details of the message sent successfully | `slack message` |

**Examples**

Send a message to Slack

```generic
retrieve the channel from slack
    the channel name is "general"
use the above as the channel
send message to the channel
    the message is "Hello, world!"
    the attachments are "image.png"
```

## Concepts

### Slack channel

Represents a reference to a channel in Slack.

| Field Name     | Description              | Type   |
| -------------- | ------------------------ | ------ |
| `channel_id`   | The ID of the channel.   | `text` |
| `channel_name` | The name of the channel. | `text` |

### Slack user

Represents a reference to a channel in Slack.

| Field Name   | Description                                         | Type   |
| ------------ | --------------------------------------------------- | ------ |
| `user_id`    | The ID of the user.                                 | `text` |
| `user_name`  | The name of the user.                               | `text` |
| `channel_id` | The ID of the IM channel with the current user/bot. | `text` |

### Slack message

Represents a reference to a message in the Slack

| Field Name  | Description                   | Type     |
| ----------- | ----------------------------- | -------- |
| `text`      | The message.                  | `text`   |
| `timestamp` | The timestamp of the message. | `number` |
| `meta`      | Metadata of the message       | `json`   |

### Slack action block

Represents an action block in Slack.

| Field Name | Description                 | Type                                                                                                                                                                                                                           |
| ---------- | --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `block_id` | The ID of the block.        | `optional[text]`                                                                                                                                                                                                               |
| `elements` | The elements of the action. | `optional[list of list of slack button element` or `slack checkbox element` or `slack date picker element` or `slack image element` or `slack markdown element?` or `slack overflow element` or `slack static select element]` |

### Slack context block

Represents a context block in Slack.

| Field Name | Description                        | Type                                                                                                                                                                                                                           |
| ---------- | ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `block_id` | The ID of the block.               | `optional[text]`                                                                                                                                                                                                               |
| `elements` | The elements of the context block. | `optional[list of list of slack button element` or `slack checkbox element` or `slack date picker element` or `slack image element` or `slack markdown element?` or `slack overflow element` or `slack static select element]` |

### Slack divider block

Represents a divider block in Slack.

| Field Name | Description          | Type             |
| ---------- | -------------------- | ---------------- |
| `block_id` | The ID of the block. | `optional[text]` |

### Slack header block

Represents a header block in Slack.

| Field Name | Description             | Type             |
| ---------- | ----------------------- | ---------------- |
| `text`     | The text of the header. | `text`           |
| `block_id` | The ID of the block.    | `optional[text]` |

### Slack image block

Represents an image block in Slack.

| Field Name  | Description                 | Type             |
| ----------- | --------------------------- | ---------------- |
| `image_url` | The URL of the image.       | `text`           |
| `alt_text`  | The alt text for the image. | `text`           |
| `block_id`  | The ID of the block.        | `optional[text]` |

### Slack markdown block

Represents a markdown block in Slack.

| Field Name | Description                     | Type             |
| ---------- | ------------------------------- | ---------------- |
| `text`     | The text of the markdown block. | `text`           |
| `block_id` | The ID of the block.            | `optional[text]` |

### Slack section block

Represents a section block in Slack.

| Field Name  | Description                   | Type                                                                                                                                                                                                           |
| ----------- | ----------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `text`      | The text of the section.      | `optional[text]`                                                                                                                                                                                               |
| `fields`    | The fields of the section.    | `optional[slack markdown element?` or `text]`                                                                                                                                                                  |
| `accessory` | The accessory of the section. | `optional[slack button element` or `slack checkbox element` or `slack date picker element` or `slack image element` or `slack markdown element?` or `slack overflow element` or `slack static select element]` |
| `block_id`  | The ID of the block.          | `optional[text]`                                                                                                                                                                                               |

### Slack attachment

Represents a reference to an attachment in the Slack

| Field Name  | Description                 | Type   |
| ----------- | --------------------------- | ------ |
| `file_name` | The name of the attachment. | `text` |
| `data`      | The File object             | `file` |
