Skip to content
← Public packages

@kody/slack

Read Slack conversations and safely send messages as the authorizing user through the saved slack OAuth integration.

src/list-users.ts

27 lines · 755 B · TypeScript
import { nextCursor, resolveIntegrationName, slackRequest } from './request.ts'
import { boundedLimit, inputRecord, optionalString } from './validation.ts'

type UsersResponse = {
	ok: boolean
	members?: unknown[]
	response_metadata?: { next_cursor?: string }
	[key: string]: unknown
}

/** List workspace users so message author IDs can be resolved. */
export default async function listUsers(params: Record<string, unknown> = {}) {
	const input = inputRecord(params)
	const result = await slackRequest<UsersResponse>(
		'users.list',
		{
			limit: boundedLimit(input.limit),
			cursor: optionalString(input, 'cursor'),
		},
		resolveIntegrationName(input.integration),
	)

	return {
		users: result.members ?? [],
		nextCursor: nextCursor(result),
	}
}