# Slack Integration via LowCodeAPI

## Overview

Slack is a messaging platform for teams. The Slack API provides comprehensive functionality for:

- **Messaging** - Send and manage messages in channels and DMs
- **Channels** - Create, archive, and manage channels
- **Users** - Get user information and presence
- **Files** - Upload and manage files
- **Conversations** - Manage conversations and threads
- **Webhooks** - Configure incoming webhooks
- **Reactions** - Add and remove reactions
- **Search** - Search messages and files
- **Reminders** - Set and manage reminders

## Base Endpoint

```
https://api.lowcodeapi.com/slack/
```

## Authentication

LowCodeAPI handles authentication automatically using Bearer token authentication. You only need to:

1. **Create an app** at [Slack API](https://api.slack.com) to get your Bot Token
2. **Install the app** to your workspace
3. **Connect your account** in the LowCodeAPI dashboard
4. **Use your `api_token`** in all requests

The `api_token` is your LowCodeAPI authentication token. LowCodeAPI will automatically:
- Fetch your Slack Bot Token
- Apply it to each request as a Bearer token

**Auth Type**: Bearer Token (xoxb- prefix for bot tokens)

## API Categories

- **Team Collaboration** - Messaging and team communication

## Common Endpoints

### Category: Chat

#### Post Message

**Method**: `POST` | **LowCodeAPI Path**: `/chat.postMessage`

**Full URL**:
```
https://api.lowcodeapi.com/slack/chat.postMessage?api_token={api_token}
```

**Description**: Send a message to a channel, private group, or DM.

**Request Body**:
```json
{
  "channel": "C1234567890",
  "text": "Hello from the Slack API!",
  "blocks": [
    {
      "type": "section",
      "text": {
        "type": "mrkdwn",
        "text": "Hello, *world!*"
      }
    }
  ],
  "mrkdwn": true,
  "thread_ts": "1234567890.123456",
  "reply_broadcast": false
}
```

**Request Body Fields**:

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `channel` | string | Yes | Channel ID or name |
| `text` | string | Conditionally | Message text (required if no blocks) |
| `blocks` | array | No | Array of layout blocks |
| `mrkdwn` | boolean | No | Enable Markdown formatting |
| `thread_ts` | string | No | Parent timestamp to create thread |
| `reply_broadcast` | boolean | No | Reply to thread and broadcast to channel |

**Example Request**:
```bash
curl -X POST "https://api.lowcodeapi.com/slack/chat.postMessage?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "channel": "#general",
    "text": "Important announcement: The deployment is complete!",
    "blocks": [
      {
        "type": "section",
        "text": {
          "type": "mrkdwn",
          "text": "*Deployment Complete*\nAll services are now live."
        }
      }
    ]
  }'
```

**Official Documentation**: [Post Message](https://api.slack.com/methods/chat.postMessage)

---

#### Update Message

**Method**: `POST` | **LowCodeAPI Path**: `/chat.update`

**Full URL**:
```
https://api.lowcodeapi.com/slack/chat.update?api_token={api_token}
```

**Description**: Update a message in a channel.

**Request Body**:
```json
{
  "channel": "C1234567890",
  "ts": "1234567890.123456",
  "text": "Updated message text",
  "blocks": []
}
```

**Request Body Fields**:

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `channel` | string | Yes | Channel containing the message |
| `ts` | string | Yes | Timestamp of the message to update |
| `text` | string | Conditionally | New message text |
| `blocks` | array | No | New layout blocks |
| `reply_broadcast` | boolean | No | Broadcast reply to channel |

**Example Request**:
```bash
curl -X POST "https://api.lowcodeapi.com/slack/chat.update?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "channel": "#general",
    "ts": "1234567890.123456",
    "text": "Updated: The deployment is scheduled for 2 PM."
  }'
```

**Official Documentation**: [Update Message](https://api.slack.com/methods/chat.update)

---

#### Delete Message

**Method**: `POST` | **LowCodeAPI Path**: `/chat.delete`

**Full URL**:
```
https://api.lowcodeapi.com/slack/chat.delete?api_token={api_token}
```

**Description**: Delete a message from a channel.

**Request Body**:
```json
{
  "channel": "C1234567890",
  "ts": "1234567890.123456"
}
```

**Request Body Fields**:

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `channel` | string | Yes | Channel containing the message |
| `ts` | string | Yes | Timestamp of the message to delete |

**Example Request**:
```bash
curl -X POST "https://api.lowcodeapi.com/slack/chat.delete?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "channel": "#general",
    "ts": "1234567890.123456"
  }'
```

**Official Documentation**: [Delete Message](https://api.slack.com/methods/chat.delete)

---

### Category: Conversations

#### List Conversations

**Method**: `GET` | **LowCodeAPI Path**: `/conversations.list`

**Full URL**:
```
https://api.lowcodeapi.com/slack/conversations.list?api_token={api_token}
```

**Description**: List all channels in a workspace.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `types` | string | Yes | Conversation types: public_channel, private_channel, mpim, im |
| `cursor` | string | No | Pagination cursor |
| `limit` | integer | No | Maximum number of conversations (default: 100) |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/slack/conversations.list?api_token=YOUR_API_TOKEN&types=public_channel,private_channel&limit=100"
```

**Official Documentation**: [List Conversations](https://api.slack.com/methods/conversations.list)

---

#### Create Channel

**Method**: `POST` | **LowCodeAPI Path**: `/conversations.create`

**Full URL**:
```
https://api.lowcodeapi.com/slack/conversations.create?api_token={api_token}
```

**Description**: Create a new channel.

**Request Body**:
```json
{
  "name": "new-channel",
  "is_private": false,
  "description": "Channel for team updates"
}
```

**Request Body Fields**:

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `name` | string | Yes | Channel name (no spaces) |
| `is_private` | boolean | No | Create private channel |
| `description` | string | No | Channel description |

**Example Request**:
```bash
curl -X POST "https://api.lowcodeapi.com/slack/conversations.create?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "project-updates",
    "is_private": false,
    "description": "Updates about the project"
  }'
```

**Official Documentation**: [Create Channel](https://api.slack.com/methods/conversations.create)

---

#### Archive Channel

**Method**: `POST` | **LowCodeAPI Path**: `/conversations.archive`

**Full URL**:
```
https://api.lowcodeapi.com/slack/conversations.archive?api_token={api_token}
```

**Description**: Archive a channel.

**Request Body**:
```json
{
  "channel": "C1234567890"
}
```

**Request Body Fields**:

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `channel` | string | Yes | Channel ID to archive |

**Example Request**:
```bash
curl -X POST "https://api.lowcodeapi.com/slack/conversations.archive?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"channel": "C1234567890"}'
```

**Official Documentation**: [Archive Channel](https://api.slack.com/methods/conversations.archive)

---

### Category: Users

#### List Users

**Method**: `GET` | **LowCodeAPI Path**: `/users.list`

**Full URL**:
```
https://api.lowcodeapi.com/slack/users.list?api_token={api_token}
```

**Description**: List all users in a workspace.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `cursor` | string | No | Pagination cursor |
| `limit` | integer | No | Maximum number of users (default: 100) |
| `team_id` | string | No | ID of the workspace |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/slack/users.list?api_token=YOUR_API_TOKEN&limit=200"
```

**Official Documentation**: [List Users](https://api.slack.com/methods/users.list)

---

#### Get User Info

**Method**: `GET` | **LowCodeAPI Path**: `/users.info`

**Full URL**:
```
https://api.lowcodeapi.com/slack/users.info?user={user}&api_token={api_token}
```

**Description**: Get information about a user.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `user` | string | Yes | User ID to fetch info for |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/slack/users.info?user=U1234567890&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [Get User Info](https://api.slack.com/methods/users.info)

---

### Category: Files

#### Upload File

**Method**: `GET` | **LowCodeAPI Path**: `/files.upload`

**Full URL**:
```
https://api.lowcodeapi.com/slack/files.upload?api_token={api_token}
```

**Description**: Upload or create a file in Slack.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `channels` | string | No | Comma-separated channel IDs |
| `content` | string | No | File content |
| `file` | file | No | File to upload |
| `filename` | string | No | Filename |
| `title` | string | No | File title |
| `initial_comment` | string | No | Initial comment for file |
| `thread_ts` | string | No | Timestamp for thread upload |

**Example Request**:
```bash
curl -X POST "https://api.lowcodeapi.com/slack/files.upload?api_token=YOUR_API_TOKEN" \
  -F "channels=#general" \
  -F "[email protected]" \
  -F "title=Monthly Report" \
  -F "initial_comment=Here is the monthly report."
```

**Official Documentation**: [Upload File](https://api.slack.com/methods/files.upload)

---

#### List Files

**Method**: `GET` | **LowCodeAPI Path**: `/files.list`

**Full URL**:
```
https://api.lowcodeapi.com/slack/files.list?api_token={api_token}
```

**Description**: List files in a workspace.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `channel` | string | No | Filter by channel |
| `user` | string | No | Filter by user |
| `types` | string | No | File types to return |
| `count` | integer | No | Number of items to return |
| `page` | integer | No | Page number to fetch |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/slack/files.list?api_token=YOUR_API_TOKEN&count=50&page=1"
```

**Official Documentation**: [List Files](https://api.slack.com/methods/files.list)

---

### Category: Reactions

#### Add Reaction

**Method**: `POST` | **LowCodeAPI Path**: `/reactions.add`

**Full URL**:
```
https://api.lowcodeapi.com/slack/reactions.add?api_token={api_token}
```

**Description**: Add a reaction to a message.

**Request Body**:
```json
{
  "channel": "C1234567890",
  "name": "thumbsup",
  "timestamp": "1234567890.123456"
}
```

**Request Body Fields**:

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `name` | string | Yes | Reaction name (e.g., thumbsup) |
| `channel` | string | Conditionally | Channel ID (required if not DM) |
| `timestamp` | string | Conditionally | Message timestamp |
| `file` | string | Conditionally | File ID to react to |
| `file_comment` | string | Conditionally | File comment ID |

**Example Request**:
```bash
curl -X POST "https://api.lowcodeapi.com/slack/reactions.add?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "channel": "#general",
    "name": "white_check_mark",
    "timestamp": "1234567890.123456"
  }'
```

**Official Documentation**: [Add Reaction](https://api.slack.com/methods/reactions.add)

---

### Category: Search

#### Search Messages

**Method**: `GET` | **LowCodeAPI Path**: `/search.messages`

**Full URL**:
```
https://api.lowcodeapi.com/slack/search.messages?query={query}&api_token={api_token}
```

**Description**: Search for messages in a workspace.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `query` | string | Yes | Search query |
| `count` | integer | No | Number of results (default: 20) |
| `page` | integer | No | Page number (default: 1) |
| `cursor` | string | No | Pagination cursor |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/slack/search.messages?query=deployment&api_token=YOUR_API_TOKEN&count=50"
```

**Official Documentation**: [Search Messages](https://api.slack.com/methods/search.messages)

---

## Usage Examples

### Example 1: Send and Update Messages

Send a message and update it later:

```bash
# Step 1: Send a message
# No ID needed - posts to channel
curl -X POST "https://api.lowcodeapi.com/slack/chat.postMessage?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "channel": "#announcements",
    "text": "Deployment starting now...",
    "blocks": [
      {
        "type": "section",
        "text": {
          "type": "mrkdwn",
          "text": "*Deployment Status*: :construction_worker: In progress"
        }
      }
    ]
  }'

# Step 2: Update the message when complete
# Replace CHANNEL and TS with actual values from Step 1
curl -X POST "https://api.lowcodeapi.com/slack/chat.update?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "channel": "CHANNEL_ID",
    "ts": "MESSAGE_TIMESTAMP",
    "text": "Deployment complete!",
    "blocks": [
      {
        "type": "section",
        "text": {
          "type": "mrkdwn",
          "text": "*Deployment Status*: :white_check_mark: Complete"
        }
      }
    ]
  }'
```

### Example 2: Create Channel and Invite Users

Set up a new project channel:

```bash
# Step 1: Create a new channel
# No ID needed - creates new channel
curl -X POST "https://api.lowcodeapi.com/slack/conversations.create?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "project-alpha",
    "is_private": false,
    "description": "Discussion for Project Alpha"
  }'

# Step 2: List all channels to get the channel ID
# No ID needed - lists all channels
curl -X GET "https://api.lowcodeapi.com/slack/conversations.list?api_token=YOUR_API_TOKEN&types=public_channel"

# Step 3: Send welcome message to the new channel
# Replace CHANNEL_ID with actual ID from Step 2
curl -X POST "https://api.lowcodeapi.com/slack/chat.postMessage?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "channel": "CHANNEL_ID",
    "text": "Welcome to the Project Alpha channel!"
  }'
```

### Example 3: Upload and Share File

Share a document with a channel:

```bash
# Step 1: Upload a file with comment
# No ID needed - uploads new file
curl -X POST "https://api.lowcodeapi.com/slack/files.upload?api_token=YOUR_API_TOKEN" \
  -F "channels=#general" \
  -F "[email protected]" \
  -F "title=Project Specifications" \
  -F "initial_comment=Here are the latest specs for review."

# Step 2: Add a reaction to acknowledge
# Replace CHANNEL, TS with actual values
curl -X POST "https://api.lowcodeapi.com/slack/reactions.add?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "channel": "#general",
    "name": "eyes",
    "timestamp": "FILE_MESSAGE_TIMESTAMP"
  }'
```

## Complete Endpoint Reference

For a complete list of all 150+ endpoints and their parameters, refer to:

- **OpenAPI Definition**: https://backend.lowcodeapi.com/slack/definition
- **Official Slack Documentation**: https://api.slack.com/methods

## Rate Limits & Best Practices

- **Rate Limit**: Tier 1 (1+ requests/minute) to Tier 4 (100+ requests/minute) based on method
- **Best Practices**:
  - Use message timestamps to update/delete messages efficiently
  - Store channel and user IDs to avoid repeated API calls
  - Use blocks for rich, interactive messages
  - Implement rate limiting for high-volume operations
  - Use webhooks for real-time event handling
  - Cache conversation and user lists when possible
  - Use thread_ts for threaded conversations

## Error Handling

All responses are wrapped in a `data` key:
```json
{
  "data": {
    // Actual response from Slack
  }
}
```

Common error responses:
- **channel_not_found**: Invalid channel ID
- **message_not_found**: Message not found or already deleted
- **cant_delete_message**: No permission to delete message
- **rate_limited**: Rate limit exceeded
- **not_authed**: Invalid or missing token