https://github.com/themashcodee/slack-blocks-ai-schema
A TypeScript library providing Zod schemas for Slack Block Kit, designed to be used with AI integrations.
https://github.com/themashcodee/slack-blocks-ai-schema
Last synced: over 1 year ago
JSON representation
A TypeScript library providing Zod schemas for Slack Block Kit, designed to be used with AI integrations.
- Host: GitHub
- URL: https://github.com/themashcodee/slack-blocks-ai-schema
- Owner: themashcodee
- Created: 2025-03-16T16:34:05.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-16T17:52:55.000Z (over 1 year ago)
- Last Synced: 2025-03-16T18:40:20.312Z (over 1 year ago)
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/slack-blocks-ai-schema
- Size: 23.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# slack-blocks-ai-schema
> π«ΆπΌ If you use this in your project, please consider giving a shoutout on LinkedIn (@themashcodee) or crediting the original author. Your support is much appreciated!
A JSON schema for validating Slack Block Kit content, specifically designed for AI integrations. This library helps ensure that AI-generated Slack messages conform to the Block Kit format.
## Installation
`npm i slack-blocks-ai-schema`
## Features
- Complete JSON schema for Slack Block Kit validation
- Optimized for AI integrations (OpenAI, Anthropic, etc.)
- Simple and lightweight
- Zero dependencies
## Example Usage
```typescript
import dotenv from "dotenv"
dotenv.config()
import OpenAI from "openai"
import { json_schema } from "slack-blocks-ai-schema"
const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY })
async function main() {
const completion = await client.chat.completions.create({
model: "gpt-4o-mini",
messages: [
{
role: "system",
content:
"You are a helpful assistant that creates Slack Block Kit content. Only use blocks and formats as defined in the response format schema. For text content, use plain_text or mrkdwn text objects where appropriate.",
},
{
role: "user",
content:
"Create a brief product announcement using Slack blocks for a new eco-friendly water bottle. Include a product image. Describe the product features and benefits, highlighting key points with markdown formatting.",
},
],
response_format: {
type: "json_schema",
json_schema: {
name: "blocks",
schema: json_schema,
},
},
})
const completion_text = completion.choices[0].message.content
if (!completion_text) return console.log("No completion text")
const parsed = JSON.parse(completion_text) // { blocks: [...] }
console.log(
`https://app.slack.com/block-kit-builder#${encodeURIComponent(
JSON.stringify(parsed)
)}`
)
}
await main()
```
## Support
Love my open source work or anything else I do? Treat me to a coffee! π
[](https://www.buymeacoffee.com/themashcodee)