An open API service indexing awesome lists of open source software.

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.

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! 😊

[![Buy Me a Coffee](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/themashcodee)