Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions slack-pdf-summarizer/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Slack Bot credentials (from https://api.slack.com/apps)
SLACK_BOT_TOKEN=xoxb-your-bot-token
SLACK_SIGNING_SECRET=your-signing-secret
SLACK_APP_TOKEN=xapp-your-app-level-token

# OpenAI API key (from https://platform.openai.com/api-keys)
OPENAI_API_KEY=sk-your-openai-api-key

# Optional: OpenAI model to use (defaults to gpt-4o)
OPENAI_MODEL=gpt-4o

# Optional: port for the Slack app (defaults to 3000)
PORT=3000
2 changes: 2 additions & 0 deletions slack-pdf-summarizer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
.env
89 changes: 89 additions & 0 deletions slack-pdf-summarizer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Slack PDF Summarizer

A Slack bot that automatically detects when a PDF is shared in a channel and replies in a thread with a concise bullet-point summary of the document's key insights.

## How it works

1. A user drops a PDF into any channel the bot is a member of.
2. The bot detects the PDF attachment, downloads it, and extracts the text.
3. The extracted text is sent to OpenAI (GPT-4o by default) with a prompt that produces 3–7 bullet points of key insights.
4. The summary is posted as a threaded reply on the original message.

## Prerequisites

- **Node.js** 18+ (uses native `fetch`)
- A **Slack App** with Socket Mode enabled
- An **OpenAI API key**

## Slack App Setup

1. Go to [api.slack.com/apps](https://api.slack.com/apps) and click **Create New App → From scratch**.
2. Under **Socket Mode**, enable it and generate an **App-Level Token** with the `connections:write` scope. Save this as `SLACK_APP_TOKEN`.
3. Under **OAuth & Permissions**, add these **Bot Token Scopes**:
- `channels:history` — read messages in public channels
- `groups:history` — read messages in private channels
- `im:history` — read direct messages
- `chat:write` — post summary replies
- `files:read` — download shared PDF files
4. Under **Event Subscriptions**, enable events and subscribe to these **bot events**:
- `message.channels`
- `message.groups`
- `message.im`
5. Install the app to your workspace. Copy the **Bot User OAuth Token** (`xoxb-…`) as `SLACK_BOT_TOKEN`.
6. Copy the **Signing Secret** from **Basic Information** as `SLACK_SIGNING_SECRET`.
7. Invite the bot to any channels where you want automatic PDF summarization (`/invite @YourBotName`).

## Installation

```bash
cd slack-pdf-summarizer
npm install
```

## Configuration

Copy the example env file and fill in your credentials:

```bash
cp .env.example .env
```

| Variable | Required | Description |
|---|---|---|
| `SLACK_BOT_TOKEN` | Yes | Bot User OAuth Token (`xoxb-…`) |
| `SLACK_SIGNING_SECRET` | Yes | Signing secret from app Basic Information |
| `SLACK_APP_TOKEN` | Yes | App-Level Token (`xapp-…`) for Socket Mode |
| `OPENAI_API_KEY` | Yes | OpenAI API key |
| `OPENAI_MODEL` | No | Model to use (default: `gpt-4o`) |
| `PORT` | No | Server port (default: `3000`) |

## Running

```bash
# Load env vars and start the bot
node -r dotenv/config src/app.js

# Or if you set env vars another way:
npm start
```

For development with auto-reload:

```bash
npm run dev
```

## Architecture

```
src/
├── app.js # Slack Bolt app — listens for messages with PDFs
├── pdf-extractor.js # Extracts text from PDF buffers via pdf-parse
└── summarizer.js # Sends extracted text to OpenAI for summarization
```

## Notes

- **Image-based PDFs** (scanned documents without OCR) will not produce usable text. The bot will report that it could not extract meaningful content.
- Very large PDFs are truncated to ~100 000 characters before summarization to stay within model context limits.
- The bot processes multiple PDFs in a single message concurrently.
Loading