Edits history of script submission #23270 for ' List Files (slack)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    import { WebClient } from "@slack/web-api"
    
    /**
     * List Files
     * List files visible to the token, newest first, optionally filtered by `channel`, uploader `user`, `types` (comma-separated: all, spaces, snippets, images, gdocs, zips, pdfs) and a Unix-seconds `ts_from`/`ts_to` window. Pages with `count` (default 100) + `page`, bounded by `paging.pages`. Needs files:read (user-token default; tick it for a bot token).
     */
    export async function main(
      auth: RT.Slack,
      channel?: string,
      user?: string,
      types?: string,
      ts_from?: number,
      ts_to?: number,
      count?: number,
      page?: number
    ) {
      const client = new WebClient(auth.token)
      return await client.files.list(
        dropEmpty({ channel, user, types, ts_from, ts_to, count, page }) as any
      )
    }
    
    function dropEmpty<T extends { [key: string]: any }>(params: T) {
      return Object.fromEntries(
        Object.entries(params).filter(
          ([, v]) => v !== undefined && v !== null && v !== ""
        )
      ) as T
    }
    

    Submitted by hugo989 2 hours ago