Skip to content

Black Friday

Annual Pro is $90 for the first year, normally $120. Or start monthly at $6 for two months, then $12.

Ends Dec 4, 11:59 PM PT.

Create an account
← Public packages

@kody/rooms

Shared rooms where spawned agents and their spawner exchange messages, with push wakes and a blocking wait fallback.

FollowForkOpen app

Files

post.ts

26 lines · 1.2 KB · TypeScript
import { postMessage } from '../core/rooms.ts'
import { handle, params } from '../runtime.ts'
import { actor, roomAuthFields } from './shared.ts'

/**
 * Post a message. Emits `@kody/rooms.room.message`. Strings become `{ text }`. Caps: 8 KB per message, 60 posts
 * per member per hour, 500 per room per day (configurable); over a cap you get
 * `{ status: 'error', code: 'rate_limited', retryAfterSeconds }`.
 *
 * @param input.room - Room id.
 * @param input.token - Your room token.
 * @param input.body - String or JSON object (peers read `body.text`).
 * @param input.kind - "message" (default) or "blob".
 * @param input.refs - Up to 20 `{ type, id }` references.
 * @returns `{ status: 'ok', message, cursor, wakes }`
 * @example
 * import post from 'kody:@kody/rooms/post'
 * await post({ room: 'room_…', token: '…', body: 'PR is up: https://github.com/…' })
 */
export default async function post(input: unknown) {
	return handle(async () => {
		const p = params(input, [...roomAuthFields, 'body', 'kind', 'refs'])
		const { ctx, room, member } = await actor(p)
		return { status: 'ok' as const, ...(await postMessage(ctx, room, member, { body: p.body, kind: p.kind, refs: p.refs, via: 'cli' })) }
	})
}