Notify your team via Slack on publish
On document publish, send a Slack notification so your team is informed
functions/slack-notify/index.ts
import {env} from 'node:process'
import {documentEventHandler} from '@sanity/functions'
import {WebClient} from '@slack/web-api'
const {
SLACK_OAUTH_TOKEN = '',
SLACK_CHANNEL = '',
BASE_URL = 'http://localhost:3000',
STUDIO_URL = 'http://localhost:3333',
} = env
export const handler = documentEventHandler(async ({event}) => {
// Initialize Slack client
const slack = new WebClient(SLACK_OAUTH_TOKEN)
try {
// Prepare message content
const message = `*New Document Created!*\nTitle: ${event.data.title || 'Untitled'}\nWebpage: <${BASE_URL}/posts/${event.data.slug?.current || 'no-slug'}|Click Here>\nStudio: <${STUDIO_URL}/structure/post;${event.data._id}|Click Here>\nDateTime Created: ${new Date(event.data._createdAt).toLocaleString()}`
// Send message to Slack
await slack.chat.postMessage({
channel: SLACK_CHANNEL,
text: message,
})
console.log(
'Slack notification sent successfully to channel:',
SLACK_CHANNEL,
'Message sent:',
message,
)
} catch (error) {
console.error('Error sending Slack notification:', error)
throw error
}
})sanity.blueprint.ts
import {defineBlueprint, defineDocumentFunction} from '@sanity/blueprints'
export default defineBlueprint({
resources: [
defineDocumentFunction({
name: 'slack-notify',
src: './functions/slack-notify',
memory: 1,
timeout: 10,
event: {
on: ['create'],
filter: "_type == 'post'",
projection: '{_id, title, slug, _createdAt}',
},
}),
],
})Automatically notify your team when content gets published - no more missed posts or delayed promotions.
Quick Start
View full instructions and source code.
Initialize blueprints if you haven't already: npx sanity blueprints init
Then: npx sanity blueprints add function --example slack-notify
Then deploy: npx sanity blueprints deploy
Slack Setup
More robust instructions in the GitHub README
- Create Slack App: Go to api.slack.com/apps → "Create New App" → "From scratch"
- Add Permissions: Go to "OAuth & Permissions" → Add
chat:writescope under "Bot Token Scopes" - Install & Get Token: Click "Install to Workspace" → Copy the Bot User OAuth Token (starts with
xoxb-) - Add to Channel: Invite your app to the desired channel using
/invite @your-app-name
How It Works
When a content editor publishes a new blog post (or any configure document type), the function automatically:
- Triggers on the publish event for post documents
- Extracts key document information (title, slug, publication time)
- Formats a rich Slack notification with direct links
- Sends the message to your designated Slack channel
- Provides quick access to both the published webpage and Studio editor
Key Benefits
- Instant team notifications eliminate communication delays
- Direct links enable immediate content review and promotion
- Reduces manual overhead of notifying stakeholders
- Keeps entire team aware of publishing activity
- Enables faster response times for content marketing workflows
Technical Implementation
The function uses Slack's Web API to send formatted notifications with rich content previews. It's built with:
- Event-driven architecture (triggers on document publish)
- Slack Web API integration for reliable message delivery
- Smart link generation for both public and editorial access
- Configurable channel targeting and message formatting
- Error handling and logging for robust operation
Perfect For
- Content teams requiring immediate publish notifications
- Marketing workflows needing rapid content promotion
- Editorial teams coordinating across multiple stakeholders
- Projects requiring real-time publishing awareness
- Teams using Slack as their primary communication platform
The function works with any Sanity project and can be easily customized to target different channels, document types, or include additional metadata in notifications.
Contributor

Ken Jones Pizza
Designer who spends most of his time coding