Simple package to connect LangGraph applications to Slack
Project description
lg2slack
Simple, minimal package to connect LangGraph applications to Slack with just a few lines of code.
Installation
pip install lg2slack
Quick Start
1. Create a Slack App
- Go to https://api.slack.com/apps
- Click "Create New App" → "From a manifest"
- Copy the contents of
slack_manifest.yamlfrom this repo - Replace placeholder values:
your-app-name→ Your app nameyour-deployment-url→ Your ngrok URL (local) or LangGraph Platform URL (production)
- Install the app to your workspace
- Copy the Bot Token and Signing Secret
2. Configure Environment Variables
Create a .env file:
# Slack credentials (from https://api.slack.com/apps -> Your App)
SLACK_BOT_TOKEN=xoxb-your-bot-token
SLACK_SIGNING_SECRET=your-signing-secret
# LangGraph configuration
ASSISTANT_ID=your-assistant-id
# Optional: specify LangGraph URL (omit for loopback on platform)
# LANGGRAPH_URL=http://localhost:8123
3. Create Your Bot
# server.py
from lg2slack import SlackBot
bot = SlackBot()
# Export the app for langgraph.json
app = bot.app
That's it! Just 4 lines of code.
4. Configure LangGraph Deployment
Add to your langgraph.json:
{
"dependencies": ["lg2slack", "."],
"graphs": {
"agent": "./your_agent.py:graph"
},
"env": ".env",
"http": {
"/events/slack": "server:app"
}
}
5. Deploy
# Deploy to LangGraph Platform
langgraph deploy
# Your bot is now live! Chat with it in Slack by:
# - Sending a DM to the bot
# - @mentioning the bot in a channel
Advanced Usage
With Transformers
Customize message processing with input/output transformers:
from lg2slack import SlackBot
bot = SlackBot()
# Add user context to messages
@bot.transform_input
async def add_context(message, context):
return f"User {context.user_id} in {context.channel_id}: {message}"
# Add footer to responses
@bot.transform_output
async def add_footer(response, context):
return f"{response}\n\n_Powered by LangGraph_"
app = bot.app
Disable Streaming
If you prefer non-streaming responses:
bot = SlackBot(streaming=False)
Multiple Transformers
Transformers are applied in order:
@bot.transform_input
async def first_transform(message, context):
return f"[1] {message}"
@bot.transform_input
async def second_transform(message, context):
return f"[2] {message}"
# Input "hello" becomes: "[2] [1] hello"
Local Development
1. Start LangGraph with your bot
langgraph dev
# This automatically runs on http://localhost:8123 and serves your custom routes
Note: You don't need to run a separate server! LangGraph dev automatically imports and mounts your FastAPI app from langgraph.json.
2. Expose with ngrok
Install ngrok if you haven't already:
# macOS
brew install ngrok
# Or download from https://ngrok.com/download
Start ngrok to expose your local server:
ngrok http 8123
This will output something like:
Forwarding https://abc123.ngrok.io -> http://localhost:8123
Tip: You can view all requests in ngrok's web interface at http://localhost:4040
3. Update Slack App
Go to your Slack app settings → Event Subscriptions:
- Request URL:
https://abc123.ngrok.io/events/slack(use YOUR ngrok URL) - Slack will verify the URL - you should see a green checkmark
4. Test
Send a DM to your bot or @mention it in a channel! You'll see requests in both:
- LangGraph dev console
- ngrok web interface (http://localhost:4040)
Configuration Options
SlackBot Parameters
SlackBot(
assistant_id: str = None, # LangGraph assistant ID (or from env)
langgraph_url: str = None, # LangGraph URL, None for loopback
streaming: bool = True, # Enable streaming (default: True)
slack_bot_token: str = None, # Override Slack token (or from env)
slack_signing_secret: str = None, # Override Slack secret (or from env)
)
Environment Variables
SLACK_BOT_TOKEN- Required: Bot token from SlackSLACK_SIGNING_SECRET- Required: Signing secret from SlackASSISTANT_ID- Required: LangGraph assistant IDLANGGRAPH_URL- Optional: LangGraph deployment URL (None = loopback)
How It Works
Architecture
Slack → lg2slack → [INPUT] → LangGraph [Human Message]
↓
Slack ← lg2slack ← [OUTPUT] ← LangGraph [AI Message]
Message Flow
- User sends message in Slack (DM or @mention)
- Slack sends event to
/events/slackendpoint - lg2slack applies input transformers
- Message sent to LangGraph as Human Message
- LangGraph processes and generates AI Message
- LangGraph streams response chunks
- Each chunk immediately forwarded to Slack (low latency!)
- lg2slack applies output transformers
- Final message displayed in Slack
Thread Management
lg2slack automatically manages conversation threads:
- Slack threads map to LangGraph threads using format:
slack_{channel}_{timestamp} - Same Slack thread always connects to same LangGraph conversation
- LangGraph maintains conversation history
Features
Streaming
By default, lg2slack uses true low-latency streaming:
- Each token from LangGraph is immediately sent to Slack
- No waiting for complete response
- Better user experience with instant feedback
Feedback (Coming Soon)
Integration with LangSmith for collecting user feedback on bot responses.
Examples
See the examples/ directory:
basic.py- Minimal setupwith_transformers.py- Using input/output transformers
Troubleshooting
Bot doesn't respond
- Check Slack app Event Subscriptions URL is correct
- Verify bot is invited to the channel (for @mentions)
- Check logs:
langgraph devshows request logs - Ensure environment variables are set correctly
- Check ngrok is running and forwarding correctly
"Missing required configuration"
Make sure .env file exists with all required variables:
SLACK_BOT_TOKENSLACK_SIGNING_SECRETASSISTANT_ID
Streaming not working
- Verify LangGraph is returning messages in streaming mode
- Check that
streaming=True(default) - Ensure your LangGraph app has a
messagesstate key
Local dev: "Connection refused"
Make sure langgraph dev is running before starting ngrok.
ngrok URL keeps changing
Free ngrok URLs change each time you restart. Options:
- Use the new URL each time in Slack app settings
- Get a ngrok account for a persistent subdomain
- For production, deploy to LangGraph Platform (stable URL)
Requirements
- Python 3.10+
- LangGraph deployment with
messagesstate key - Slack workspace with bot permissions
License
MIT
Contributing
Contributions welcome! Please open an issue or PR.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lg2slack-0.1.2.tar.gz.
File metadata
- Download URL: lg2slack-0.1.2.tar.gz
- Upload date:
- Size: 26.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4775752d09c2c35edf75746b0b496ddab7652ccf8edec9a294602a48cb185095
|
|
| MD5 |
6a21fbd362af37a809145cdfb83bbb41
|
|
| BLAKE2b-256 |
9602d731a2f19544383aa65c0a1f38b347fd46efd38a4f1a31333126746a68fc
|
File details
Details for the file lg2slack-0.1.2-py3-none-any.whl.
File metadata
- Download URL: lg2slack-0.1.2-py3-none-any.whl
- Upload date:
- Size: 28.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
143917ffe4b03982c0a8519aa9b24fc6350f51babe270f6754f7fbbea071e1dd
|
|
| MD5 |
2d32c63044a37a13804f1bcc41ef980f
|
|
| BLAKE2b-256 |
f32c3a5a696e721dddc85b2b4e6e9ac247aaa87c232196386f6cd2bf23cdc2ac
|