Skip to content

SlackBridge API is a Flask-based REST API designed for user management, email-based user search, and Slack message integration.

License

Notifications You must be signed in to change notification settings

password123456/slackbridge-api

Repository files navigation

SlackBridge API

made-with-python Python Versions Hits

Slack Bridge API is a Flask-based REST API designed for user management, email-based user search, and Slack message integration.

Currently, this API supports querying users and sending messages to users through a Slack bot.

Features such as file attachments (e.g., images), sending messages to multiple users via the bot, sending messages to a specific channel (similar to a webhook), and responding to bot commands are not yet implemented. You can continue to modify and update the API as needed to include these features.

If you find this helpful, please the "star"🌟 to support further improvements.

Features

  • User Search: Fetch user details by email or retrieve all users.
  • Health Check: Validate server status with a lightweight endpoint.
  • Slack Message Integration: Send Slack messages to users via the Slack API.

Project Structure

slack_bridge
β”œβ”€β”€ settings.py
β”œβ”€β”€ wsgi.py
β”œβ”€β”€ token_generator.py
β”œβ”€β”€ service_config.py
β”œβ”€β”€ service_control.sh
β”œβ”€β”€ collect_slackusers.py
β”œβ”€β”€ collect_slackusers.sh
β”œβ”€β”€ requirements.txt
└── app
    β”œβ”€β”€ authentication.py
    β”œβ”€β”€ exceptions.py
    β”œβ”€β”€ generics.py
    β”œβ”€β”€ logger.py
    β”œβ”€β”€ route.py
    β”œβ”€β”€ search.py
    β”œβ”€β”€ sendmessage.py
    β”œβ”€β”€ validators.py
    └── db
        β”œβ”€β”€ keys.db
        └── users.db
    └── logs
        └── slack_bridge.app.validators.exceptions.log

Getting Started

To start using SlackBridge API:

Clone the repository:

git clone https://github.com/password123456/slackbridge-api.git

Install dependencies:

pip install -r requirements.txt

API Endpoints

1.Send Message

Endpoint: /api/v1/message/send

Method: POST

Description

  • Sends a message to a specific Slack user.
  • Sends the message via a Slack Bot.
  • The name of the sending Bot is the one configured in Slack.
  • The size of a single message must not exceed the limit defined by the verify_params_length decorator.
  • The request body format is JSON.

Headers:

  • Authorization: <API_TOKEN>
  • Content-Type: application/json

Body Parameters:

Name Type Description Required
email String Recipient's email address. The email format is validated by the verify_email_param_suffix decorator. Yes
message String The text message to send. Must not exceed 4000 bytes. Yes

1.1.Request:

{
  "email": "[email protected]",
  "message": "Hello Tony, Get Out!"
}

1.2.Response:

  • Success (200):
{
  "status": true,
  "result": {
    "email": "[email protected]",
    "message": "Message sent successfully, 2024-08-27T12:00:00Z"
}
  • Error (400):
{
  "status": false,
  "error": "Required fields are missing in the request body. Please check and try again."
}

2.Retrieve User Data

Endpoint: /api/v1/users/search

Method: POST

Description

  • Retrieves information about a specific Slack user.
  • Returns the user's email, username, display name, and Slack member_id.
  • Time-related data in the response body follows the ISO 8601 format (YYYY-MM-DDTHH:MM:SSZ).
  • Both the request and response body formats are in JSON.

Headers:

  • Authorization: <API_TOKEN>
  • Content-Type: application/json

Body Parameters:

Name Type Description Required
email String Recipient's email address. The email format is validated by the verify_email_param_suffix decorator. Yes

2.1.Request

{
  "email": "[email protected]",
}

2.2.Response

  • Success (200):
{
  "status": true,
  "result": {
    "datetime": "2024-11-22T10:09:14+09:00",
    "real_name": "tony.stark",
    "display_name": "stark",
    "member_id": "U072E6GR1LM",
    "user_email": "[email protected]"
  }
}
  • Error (404):
{
  "status": false,
  "message": "The specified user could not be found. Please check the input and try again."
}

3.List All Users

Endpoint: /api/v1/users/all

Method: GET

Description

  • Retrieves information about all Slack users.
  • Returns the user's email, username, display name, and Slack member_id.
  • Time-related data in the response body follows the ISO 8601 format (YYYY-MM-DDTHH:MM:SSZ).
  • Both the request and response body formats are in JSON.

Headers:

  • Authorization: <API_TOKEN>

Body Parameters:

  • None

3.1.Request

GET /api/v1/users/all

3.2.Response

  • Success (200):
{
  "status": true,
  "message": [
    {
      "datetime": "2024-11-22T10:09:14+09:00",
      "real_name": "tony.stark",
      "display_name": "stark",
      "member_id": "U072E6GR1LM",
      "user_email": "[email protected]"
    },
    {
      "datetime": "2024-11-22T10:09:14+09:00",
      "real_name": "Happy.Hogan",
      "display_name": "happy",
      "member_id": "U092P6GRALM",
      "user_email": "[email protected]"
    },
    {
      "datetime": "2024-11-22T10:09:14+09:00",
      "real_name": "Steve.Rogers",
      "display_name": "steve",
      "member_id": "U132E6BR1LM",
      "user_email": "[email protected]"
    }
  ]
}

4.Error Handling

The SlackBridge API uses standard HTTP response codes to indicate success or failure. Additional details are provided in the response body.

HTTP Code Meaning Example
200 Success The request was successful.
400 Bad Request Invalid parameters were provided.
401 Unauthorized Invalid or missing token.
404 Not Found The resource could not be found.
500 Internal Server Error An error occurred on the server.

5.Token Generator

token_generator.py simplifies the creation, encryption, decryption, and validation of API tokens using AES-GCM encryption, ensuring high security and integrity. It is particularly useful for managing access keys with expiration and IP-based restrictions.

Features:

  • Secure Token Management: Generates encrypted tokens, stores them in a database, and retrieves them securely.

  • Expiration & IP Validation: Tokens include metadata such as issuer, expiration time, and allowed IP addresses for access control.

  • AES-GCM Encryption: Ensures confidentiality and integrity using a 32-byte passphrase key and a 12-byte nonce.

About

SlackBridge API is a Flask-based REST API designed for user management, email-based user search, and Slack message integration.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published