DEV Community

koooosuke
koooosuke

Posted on

Automatically Generating TODO Lists from Slack Messages: Using llama_index and SlackLoader

In this tutorial, we'll demonstrate how to use llama_index and SlackLoader together to retrieve messages from Slack and automatically generate a TODO list.

Prerequisites:

  1. Python is installed
  2. Slack workspace is available
  3. Required Python packages are installed (dotenv, llama_index, etc.)

Step-by-step Instructions:

Step 1: Create a Slack App

The first step is to create an app in your Slack workspace. This app will be used to fetch messages from a specific channel.

  1. Visit the Slack API site.
  2. Click on the Create New App button.
  3. Choose From scratch, give your app a name, select a workspace, and click the Create App button.

Step 2: Configure the Necessary Permissions

You'll need to add the necessary permissions to your app.

  1. Navigate to your app's settings page.
  2. From the left-side menu, select OAuth & Permissions.
  3. Under the Scopes section, click on Add an OAuth Scope button.
  4. Search for channels:history and add it.

Step 3: Install the App to Your Workspace

Once you've set up the necessary permissions, you can install the app to your workspace.

  1. Click the Install App to Workspace button at the top of the OAuth & Permissions page.
  2. Review the required permissions and click Allow.

Step 4: Post Test Data to Slack

Post the following test data to any channel in your workspace. This message will be used to generate the TODO list.

Today, I have several tasks on my plate: ... [continued]
Enter fullscreen mode Exit fullscreen mode

Step 5: Set Up Environment Variables

Create a .env file and set up the following two environment variables:

  • SLACK_APP_TOKEN: The Bot User OAuth Token for the app you installed in Step 3. You can get this from the OAuth & Permissions page.
  • SLACK_CHANNEL_ID: The ID of the channel where you posted the test data in Step 4. This can be retrieved from the URL.

Step 6: Run Python Code

Finally, run the following Python code.

import os
from dotenv import load_dotenv
from llama_index import GPTVectorStoreIndex, download_loader

load_dotenv()

SlackReader = download_loader("SlackReader")

loader = SlackReader(os.environ.get("SLACK_APP_TOKEN"))
documents = loader.load_data(channel_ids=[os.environ.get("SLACK_CHANNEL_ID")])

index = GPTVectorStoreIndex.from_documents(documents)
query_engine = index.as_query_engine()

query_prompt = """
Based on what was posted in Slack today, could you please summarize your TODO list? Please structure your response in the following format:

- No: Task number
- Task: Brief description
- Status: (Not Started / In Progress / Completed)
- Due date: (if applicable)
- Any other relevant information or notes
"""

print(query_engine.query(query_prompt.strip()))
Enter fullscreen mode Exit fullscreen mode

After running the above code, you should see an output similar to the following:

1. Task: Conduct market research on competitors
   Status: Not Started
   Due Date: Friday

2. Task: Compile list of target media outlets
   Status: Not Started
   Due Date: Friday

3. Task: Prepare press release for new product
   Status: Not Started
   Due Date: Friday

4. Task: Meeting with design team to discuss packaging design
   Status: Not Started
   Due Date: Tomorrow (2 PM)

5. Task: Prepare for next sprint
   Status: Not Started
   Due Date: N/A

6. Task: Analyze customer feedback
   Status: Not Started
   Due Date: N/A

7. Task: Attend training for CRM system
   Status: Not Started
   Due Date: Monday

8. Task: Submit Q2 performance report
   Status: Not Started
   Due Date: End of Week

9. Task: Gather feedback on website design proposal
   Status: Not Started
   Due Date: Next Week

10. Task: Propose new project
    Status: Not Started
    Due Date: N/A

11. Task: Update budget report
    Status: Not Started
    Due Date: End of Month
Enter fullscreen mode Exit fullscreen mode

And that's it! You should now be able to automatically generate a TODO list from messages posted in a specific Slack channel.

Please note that llama_index and SlackReader are still under development and their functionality or usage might change in the future. So, it's always a good idea to keep an eye on the latest documentation or release notes.

Top comments (0)