About this template
A Slack app with search functionality for messages based on query, username, and channel name. Requires SLACK_USER_TOKEN with search:read users scope enabled.
Introduction to the Slack Message Search API Template
This template provides a ready-to-use API for searching messages in Slack based on a query, username, and channel name. It's designed to help you integrate Slack's search functionality into your own applications or workflows without the need to write the code from scratch. The API is built using FastAPI and requires a Slack user token with the appropriate permissions.
Clicking Start with this Template
To begin using this template, simply click on the "Start with this Template" button. This will pre-populate the code in the Lazy Builder interface, so you won't need to copy, paste, or delete any code.
Initial setup: Adding Environment Secrets
Before you can use this template, you'll need to set up an environment secret for the `SLACK_USER_TOKEN`. Here's how to obtain and set up your Slack user token:
1. Visit the Slack API website and create a new app if you haven't already.
2. Navigate to the 'OAuth & Permissions' page of your app settings.
3. Add the `search:read` and `users:read` scopes under the 'User Token Scopes' section.
4. Install the app to your workspace and authorize the requested permissions.
5. Copy the 'User OAuth Token' that is generated for you.
6. In the Lazy Builder interface, go to the Environment Secrets tab.
7. Create a new secret with the key `SLACK_USER_TOKEN` and paste the token you copied as the value.
Test: Pressing the Test Button
Once you have set up your environment secret, press the "Test" button. This will begin the deployment of the app and launch the Lazy CLI.
Using the App
After deployment, Lazy will provide you with a dedicated server link to use the API. Additionally, since this template uses FastAPI, you will also be provided with a link to the API documentation. This documentation will guide you on how to make requests to the API and understand the expected responses.
Here's a sample request you might make to the API:
POST /search_messages
Content-Type: application/json
{
"query": "hello world",
"username": "example_user",
"channel_name": "general"
}
And a sample response you might receive:
{
"messages": [
{
"type": "message",
"user": "U12345678",
"text": "Hello world!",
"ts": "1234567890.123456",
"channel": {
"id": "C12345678",
"name": "general"
},
"username": "example_user"
}
// ... more messages
]
}
Integrating the App
If you wish to integrate this API into an external service or frontend, you will need to use the server link provided by Lazy after deployment. For example, you could make HTTP POST requests to the `/search_messages` endpoint from your frontend application to retrieve search results from Slack.
Remember to handle user authentication and authorization appropriately when integrating this API into your applications, ensuring that only authorized users can access the search functionality.
By following these steps, you can easily integrate Slack message search functionality into your applications using the Lazy platform.