by Lazy Sloth
Slack Thread Summarizer App
import os
from slack_bolt import App
from slack_bolt.adapter.socket_mode import SocketModeHandler
from abilities import llm_prompt
import re
# Initialize the Bolt app with the token and signing secret
app = App(token=os.getenv('SLACK_BOT_TOKEN'))
def summarize_text(text):
# Clean the text by removing emojis and images
clean_text = re.sub(r':[^:]+:', '', text) # Removes Slack emojis
clean_text = re.sub(r'<[^>]+>', '', clean_text) # Removes image URLs or any Slack-specific markup
# Use the llm_prompt ability to generate the summary
prompt = (
"Please summarize the following text into key takeaways in English. "
"The response should be in bullet points, each one concise and to the point. "
"Minimize the number of bullet points and avoid repeated content. "
"Ignore any emojis and images. If there is text in any other language, "
"provide a summary of that text in English. Here is the text:\n\n" + clean_text
)
summary = llm_prompt(prompt)
return summary
Created: | Last Updated:
Introduction to the Slack Thread Summarizer App Template
Welcome to the Slack Thread Summarizer App template! This template is designed to help you create an application that listens for mentions in a Slack thread and provides a concise summary of the conversation. It's perfect for keeping up with important discussions without having to read through every message. Let's walk through the steps to get your app up and running on the Lazy platform.
Clicking Start with this Template
To begin using this template, simply click on the "Start with this Template" button in the Lazy Builder interface. This will pre-populate the code in the Lazy Builder, so you won't need to copy, paste, or delete any code manually.
Initial Setup: Adding Environment Secrets
Before testing your app, you'll need to set up some environment secrets. These are not the same as environment variables in your operating system; they are specific to the Lazy platform and can be set in the Environment Secrets tab within the Lazy Builder.
You will need to provide the following environment secrets:
- SLACK_BOT_TOKEN: The token for your Slack bot. You can obtain this from your Slack app's settings under the OAuth \& Permissions section.
- SLACK_APP_TOKEN: The token for your Slack app to use socket mode. This can be generated in your Slack app's settings under the Socket Mode section.
Make sure to keep these tokens secure and do not share them publicly.
Test: Pressing the Test Button
Once you have set up the necessary environment secrets, you can test your app by pressing the "Test" button in the Lazy Builder. This will deploy your app and launch the Lazy CLI. There is no need for user input at this stage, as the app will operate based on events within Slack.
Using the App
After deploying your app, it will listen for mentions in Slack threads. When your bot is mentioned, it will fetch the thread's messages, filter out those from bots or containing mentions of the bot, and then summarize the conversation. The summary will be posted back into the same thread.
Integrating the App
To integrate this app with your Slack workspace, you need to have a Slack bot set up with the appropriate permissions. Ensure your bot has permissions to read messages and post in threads where it is mentioned. You may need to invite the bot to the channels where you want it to operate.
If you need to reference the Slack API documentation for further details on permissions and bot setup, you can find it at Slack API Documentation.
That's it! You now have a Slack Thread Summarizer App ready to help you stay on top of important conversations in your Slack workspace. Enjoy the convenience of automated summaries and never miss out on key takeaways from your team's discussions.