Skip to content

Ability to build file_upload content dynamically #412

@khitrenovich

Description

@khitrenovich

Hello,

I'm trying to upload multiple files to a thread. This works like a charm with files.uploadV2 method and file_uploads in payload when I have a static list of files. However, I need to upload all files in a given directory without known what's there ahead of time.

I tried to build the array of files as follows (same technique works, for example, for defining matrix jobs) -

    - id: prepare-files
      if: ${{ inputs.attachment_dir }}
      shell: bash
      run: |
        count=$(find "${{ github.workspace }}/${{ inputs.attachment_dir }}" -type f | wc -l)
        uploads=$(find "${{ github.workspace }}/${{ inputs.attachment_dir }}" -type f | jq -Rsc 'split("\n") | map(select(length > 0)) | map({file: ., filename: (. | split("/") | last)})')
        echo "count=${count}" >> $GITHUB_OUTPUT
        echo "uploads=${uploads}" >> $GITHUB_OUTPUT
    - id: upload-files
      uses: slackapi/slack-github-action@v2.0.0
      if: ${{ inputs.attachment_dir && steps.prepare-files.outputs.count > 0 }}
      with:
        method: files.uploadV2
        token: ${{ inputs.bot_token }}
        errors: true
        payload: |
          channel_id: ${{ steps.send-message.outputs.channel_id }}
          thread_ts: "${{ steps.send-message.outputs.ts }}"
          file_uploads: ${{ fromJSON(steps.prepare-files.outputs.uploads) }}

This results in

Run slackapi/slack-github-action@v2.0.0
  with:
    method: files.uploadV2
    token: ***
    errors: true
    payload: channel_id: ***
  thread_ts: "***"
  file_uploads: Array
  
    payload-templated: false
    retries: 5
Error: SlackError: options.file_uploads.map is not a function

file:///home/runner/work/_actions/slackapi/slack-github-action/v2.0.0/node_modules/@slack/web-api/dist/file-upload.js:4
    return new (P || (P = Promise))(function (resolve, reject) {
^
TypeError: options.file_uploads.map is not a function
    at file:///home/runner/work/_actions/slackapi/slack-github-action/v2.0.0/node_modules/@slack/web-api/dist/file-upload.js:83:1
    at Generator.next (<anonymous>)
    at file:///home/runner/work/_actions/slackapi/slack-github-action/v2.0.0/node_modules/@slack/web-api/dist/file-upload.js:8:1
    at new Promise (<anonymous>)
    at __webpack_modules__.2577.__awaiter (file:///home/runner/work/_actions/slackapi/slack-github-action/v2.0.0/node_modules/@slack/web-api/dist/file-upload.js:4:1)
    at getMultipleFileUploadJobs (file:///home/runner/work/_actions/slackapi/slack-github-action/v2.0.0/node_modules/@slack/web-api/dist/file-upload.js:80:1)
    at WebClient.<anonymous> (file:///home/runner/work/_actions/slackapi/slack-github-action/v2.0.0/node_modules/@slack/web-api/dist/WebClient.js:401:1)
    at Generator.next (<anonymous>)
    at file:///home/runner/work/_actions/slackapi/slack-github-action/v2.0.0/node_modules/@slack/web-api/dist/WebClient.js:31:1
    at new Promise (<anonymous>)

I tried to convert the whole payload to JSON format, but I'm running into the same error.
Do you have any ideas?

Thanks in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsImprovements or additions to documentationquestionFurther information is requested

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions