Skip to content

Built for people who want to own their automations. Join the waitlist for an invite.

Package listing

@kentcdodds/slack

src/list-users.ts

23 lines · 692 B · TypeScript
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),
  }
}