Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: be able to post a file to slack #92

Closed
1 of 7 tasks
mccare opened this issue May 2, 2022 · 22 comments · Fixed by #333
Closed
1 of 7 tasks

Feature Request: be able to post a file to slack #92

mccare opened this issue May 2, 2022 · 22 comments · Fixed by #333
Labels
enhancement New feature or request
Milestone

Comments

@mccare
Copy link

mccare commented May 2, 2022

Description

We are using https://github.com/adrey/slack-file-upload-action to upload a file. Would be great if slackapi would also support this method.

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • example code related
  • testing related
  • discussion
@seratch seratch added the enhancement New feature or request label May 2, 2022
@seratch seratch added this to the 1.x milestone May 2, 2022
@StefanOltmann
Copy link

This would be great!

@shalva97
Copy link

This is the only feature that is missing for my workflow to be perfect

@govindgupta1103
Copy link

Is any verified GitHub actions tool available to send the file to Slack? We are not allowed to use unverified tools.

@shalva97
Copy link

You can use Slack API directly for example:

      - name: Upload file to Slack
        run: >
          curl -F file=@app/build/outputs/apk/production/release/app-production-release.apk
          -F "initial_comment=Android production variant APK"
          -F channels=mobile-builds-android
          -H "Authorization: Bearer ${{ secrets.SLACK_BOT_TOKEN }}"
          https://slack.com/api/files.upload

Of course it is not perfect, but it works

@govindgupta1103
Copy link

Hi Shalva, where is the file location? Actually I want to attach an artifact which is generated using GitHub actions.

@shalva97
Copy link

shalva97 commented Jun 14, 2023

It is specified after @ symbol

curl -F file=@your-file-here.txt

directory will be your repository root. Check https://api.slack.com/methods/files.upload for more info

@govindgupta1103
Copy link

govindgupta1103 commented Jun 15, 2023

Hi Shalva, so does this method support only the json files or any other file type?
Because I want to upload an excel file to Slack

@govindgupta1103
Copy link

curl -F file=@app/build/outputs/apk/production/release/app-production-release.apk

Shouldn't file be in double quotes?

@govindgupta1103
Copy link

Did it work for you Shelva ?

@shalva97
Copy link

yes, thats what I use in my project. It does not need double queotes. I think its better to ask it somewhere else, because this issue is for a feature request...

@govindgupta1103
Copy link

Shalva , I know, but the requested feature is posting a file to Slack. I spent 5 hours today trying to send an excel file using above command but in vain

@govindgupta1103
Copy link

@srajiang Can you please confirm if we can send excel file to Slack using the commands provided by @shalva97 .

@gauravcanon
Copy link

@govindgupta1103 Yes for me it is working fine sending an Excel sheet.

@govindgupta1103
Copy link

govindgupta1103 commented Jul 24, 2023 via email

@iamunni
Copy link

iamunni commented Sep 22, 2023

@seratch , I would like to contribute to this feature. can I take this up?

@derekmurawsky
Copy link

I'd love to see this feature added as well. From an implementation perspective, I see it needing to be a two step process to support the nice formatting/block style messages which don't seem to be supported by the upload API (I haven't thoroughly checked this yet, though).

  1. Upload the file generically using the upload API and note the TS
  2. Update the message TS with the standard message API, thus supporting blocks.

@mjrulesamrat
Copy link

It's 2024 and this feature would be a great addition!!

@amrgetment
Copy link

any updates

@MatthewCane
Copy link

It looks like this feature is part of the proposed additions to a v2 of the Action, see #312

arealmaas added a commit to Altinn/dialogporten that referenced this issue Oct 11, 2024
<!--- Provide a general summary of your changes in the Title above -->

## Description

<!--- Describe your changes in detail -->

- Seems to be a classic case of "smør på flesk" to have both the
pipeline failing slack message and the k6-tests slack message. Won't
give any additional value until we can upload the test result file in
the message and make it sweeter:
slackapi/slack-github-action#92 Removing for
now.
- Tweaked the template a bit for the pipeline slack message
- This is a good start, and we can expand by adding more info on the
slack-message, for now posting a status for each workflow.

<img width="673" alt="image"
src="https://github.com/user-attachments/assets/d2dccb8c-2e1f-44da-add1-dd8a0a9af2f7">

## Related Issue(s)

- #230

## Verification

- [ ] **Your** code builds clean without any errors or warnings
- [ ] Manual testing done (required)
- [ ] Relevant automated test added (if you find this hard, leave it and
we'll help out)

## Documentation

- [ ] Documentation is updated (either in `docs`-directory, Altinnpedia
or a separate linked PR in
[altinn-studio-docs.](https://github.com/Altinn/altinn-studio-docs), if
applicable)


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Enhanced Slack notifications for pipeline statuses with improved
structure and clarity.
- Introduced a new GitHub Actions workflow for sending CI/CD status
updates to Slack, capturing results from multiple jobs.
- Updated existing Slack message jobs to report on both success and
failure conditions across various environments.

- **Bug Fixes**
- Removed unnecessary Slack message sending on K6 test failures,
streamlining the workflow.

- **Documentation**
- Updated environment variables and job conditions for better clarity
and functionality in CI/CD processes.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
@zimeg zimeg modified the milestones: 1.x, 2.0 Nov 15, 2024
@zimeg zimeg linked a pull request Nov 15, 2024 that will close this issue
8 tasks
@zimeg
Copy link
Member

zimeg commented Nov 15, 2024

👋 Hello! We're so excited to share that as part of the @v2.0.0 release that @MatthewCane hinted at, this is now possible!

More detailed notes on updating to the latest version are noted in that release and are also in the README, but a snippet to upload files might resemble this:

- name: Share a file to that channel
  uses: slackapi/slack-github-action@v2.0.0
  with:
    method: files.uploadV2
    token: ${{ secrets.SLACK_BOT_TOKEN }}
    payload: |
      channel: ${{ secrets.SLACK_CHANNEL_ID }}
      initial_comment: "the results are in!"
      file: "./path/to/results.out"
      filename: "results-${{ github.sha }}.out"

With the files:write scope attached to the token, files should be uploading to the channel your bot has been added to!

For now, we can close this issue, but if anyone is finding issues with file uploads, please feel free to open a new issue 🙏 ✨

@zimeg zimeg closed this as completed Nov 15, 2024
@amrgetment
Copy link

@zimeg I use payload with markdown like the following payload, I wonder how to migrate my json payload to the new version

  - name: 'Post release notes to Slack'
    uses: 'slackapi/slack-github-action@v1.26.0'
    with:
      channel-id: ${{ secrets.SLACK_FILES_CHANNEL_ID }}
      payload: |
        {
        "blocks": [
           {
            "type": "section",
            "text": {
              "type": "mrkdwn",
              "text": "*Release notes*"
            }
          },
           {
            "type": "section",
            "text": {
              "type": "mrkdwn",
              "text": "${{ steps.extract_release_note.outputs.release_note }}"
            }
          }
        ]
        }

@zimeg
Copy link
Member

zimeg commented Nov 16, 2024

@amrgetment At a glance that snippet seems to be sending the release notes as a message with perhaps a bot token?

Please let me know if I've misunderstood this setup, but I'd recommend checking out this example in the README for a change something like:

- name: "Post release notes to Slack"
  uses: slackapi/slack-github-action@v2.0.0
  with:
    method: chat.postMessage
    token: ${{ secrets.SLACK_BOT_TOKEN }}
    payload: |
      channel: ${{ secrets.SLACK_FILES_CHANNEL_ID }}
      text: "Release notes have been shared"
      blocks:
        - type: section
          text:
            type: mrkdwn
            text: "*Release notes*"
        - type: section
          text:
            type: mrkdwn
            text: "${{ steps.extract_release_note.outputs.release_note }}"

Also note that this includes the bot token and the payload also should include a top-level text value! I'm hoping this helps, but if let me know if I'm misunderstanding or if something else seems off in a new issue 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.