Hazel

Bot SDK

Build powerful bots for Hazel with type-safe APIs and real-time events

The Hazel Bot SDK lets you build bots that respond to messages, handle slash commands, and interact with channels in real-time. Built on Effect-TS, it provides full type safety and composable error handling.

Features

  • Real-time events - React to messages, channels, and members instantly via Electric SQL
  • Type-safe commands - Define slash commands with Schema-validated arguments
  • Message operations - Send, reply, update, delete, and react to messages
  • Built-in rate limiting - Automatic throttling to prevent API limits
  • Error recovery - Retries with exponential backoff for transient failures

Quick Start

import { Effect, Schema } from "effect"
import { Command, CommandGroup, runHazelBot } from "@hazel/bot-sdk"

// Define a slash command with typed arguments
const GreetCommand = Command.make("greet", {
	description: "Greet someone",
	args: { name: Schema.String },
})

runHazelBot({
	commands: CommandGroup.make(GreetCommand),
	setup: (bot) =>
		Effect.gen(function* () {
			// Handle the /greet command
			yield* bot.onCommand(GreetCommand, (ctx) =>
				bot.message.send(ctx.channelId, `Hello, ${ctx.args.name}!`),
			)

			// React to messages containing "hello"
			yield* bot.onMessage((message) =>
				Effect.gen(function* () {
					if (message.content.toLowerCase().includes("hello")) {
						yield* bot.message.react(message, "👋")
					}
				}),
			)
		}),
})

Next Steps

On this page