Slack Digest

Fetch messages from all Slack channels, send them to Claude for summarization, and post the digest back to Slack.

What it does

  1. Lists all Slack channels you have access to
  2. Fetches recent message history from each channel
  3. Sends all messages to Claude for intelligent summarization
  4. Posts the formatted digest to a specified channel

Prerequisites

  • cli4ai add slack - Install the Slack package
  • cli4ai secrets set SLACK_BOT_TOKEN - Configure your Slack bot token
  • claude CLI installed and authenticated

Usage

# Run with defaults
cli4ai routines run slack-digest

# Customize channel and time window
cli4ai routines run slack-digest --var channel=team --var hours=48

# Preview without executing
cli4ai routines run slack-digest --dry-run

Variables

Variable Default Description
channel general Channel to post the digest to
hours 24 Time window to fetch messages from

JSON Version

Save as ~/.cli4ai/routines/slack-digest.routine.json

{
  "version": 1,
  "name": "slack-digest",
  "description": "Summarize Slack activity and post a digest",
  "vars": {
    "channel": { "default": "general" },
    "hours": { "default": "24" }
  },
  "steps": [
    {
      "id": "get-channels",
      "type": "cli4ai",
      "package": "slack",
      "command": "channels",
      "capture": "json"
    },
    {
      "id": "fetch-history",
      "type": "exec",
      "cmd": "bash",
      "args": ["-c", "echo \"$CHANNELS\" | jq -r '.[].name' | while read ch; do cli4ai run slack history \"$ch\" 50 2>/dev/null; done | jq -s 'flatten'"],
      "env": { "CHANNELS": "{{steps.get-channels.stdout}}" },
      "capture": "json",
      "timeout": 120000
    },
    {
      "id": "summarize",
      "type": "exec",
      "cmd": "bash",
      "args": ["-c", "echo \"Summarize these Slack messages. Group by topic, highlight decisions and action items:\n\n$MESSAGES\" | claude --print"],
      "env": { "MESSAGES": "{{steps.fetch-history.stdout}}" },
      "capture": "text",
      "timeout": 60000
    },
    {
      "id": "post",
      "type": "cli4ai",
      "package": "slack",
      "command": "post",
      "args": ["{{vars.channel}}", "📊 *Daily Digest*\n\n{{steps.summarize.stdout}}"],
      "capture": "json"
    }
  ],
  "result": "{{steps.post.json}}"
}

Bash Version

Save as ~/.cli4ai/routines/slack-digest.routine.sh

#!/usr/bin/env bash
set -euo pipefail

# slack-digest.routine.sh
# Usage: cli4ai routines run slack-digest --var channel=general

CHANNEL="${CLI4AI_VAR_CHANNEL:-general}"
HOURS="${CLI4AI_VAR_HOURS:-24}"

echo "📬 Gathering Slack messages..." >&2

# Get all channels and fetch history
CHANNELS=$(cli4ai run slack channels | jq -r '.[].name')
ALL_MESSAGES=""

for ch in $CHANNELS; do
  echo "  Checking #$ch..." >&2
  HISTORY=$(cli4ai run slack history "$ch" 100 2>/dev/null || echo "[]")
  if [ "$HISTORY" != "[]" ]; then
    ALL_MESSAGES="$ALL_MESSAGES\n## #$ch\n$HISTORY"
  fi
done

if [ -z "$ALL_MESSAGES" ]; then
  echo "📭 No messages found" >&2
  exit 0
fi

# Send to Claude for summary
echo "📝 Summarizing with Claude..." >&2
SUMMARY=$(echo -e "Summarize these Slack messages from the last $HOURS hours. Group by topic, highlight decisions and action items:\n$ALL_MESSAGES" | claude --print)

# Post to Slack
cli4ai run slack post "$CHANNEL" "📊 *Daily Digest*\n\n$SUMMARY"
echo "✅ Posted to #$CHANNEL" >&2

Tips

  • Schedule this routine to run daily using cron or a task scheduler
  • Customize the Claude prompt to focus on specific topics or team needs
  • Add filtering to exclude certain channels (e.g., bots, announcements)

← Back to Examples