import { nextCursor, 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'),
})
return {
users: result.members ?? [],
nextCursor: nextCursor(result),
}
}