Skip to content

slack: add file upload functionality #9472

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Powma
Copy link

@Powma Powma commented Dec 30, 2024

SUMMARY

Add file upload functionality to upload the files with the new API SLACK.

Continuation of #9431.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME
  • Slack
ADDITIONAL INFORMATION

This enhancement allows you to upload files with the new version of the Slack API
https://api.slack.com/methods/files.completeUploadExternal
https://api.slack.com/methods/files.getUploadURLExternal

Example usage:

    - name: Upload a file to Slack
      community.general.slack:
        token: thetoken/generatedby/slack
        channel: 'kuma'
        upload_file:
          path: "/tmp/test.py"
          title: "main.py"
         snippet_type: "python"

@felixfontein felixfontein added check-before-release PR will be looked at again shortly before release and merged if possible. backport-10 Automatically create a backport for the stable-10 branch labels Dec 30, 2024
@ansibullbot

This comment was marked as outdated.

@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added feature This issue/PR relates to a feature request module module needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR new_contributor Help guide this first time contributor plugins plugin (any type) labels Dec 30, 2024
@ansibullbot

This comment was marked as outdated.

@ansibullbot

This comment was marked as outdated.

@ansibullbot ansibullbot removed the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR label Dec 30, 2024
Copy link
Collaborator

@russoz russoz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @Powma thanks for your contribution!

Other than fixing the sanity checks, and adding the version in the docs, it LGTM

Copy link
Collaborator

@felixfontein felixfontein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution!

type: str
description:
- Optional title for the uploaded file.
thread_ts:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this option relate to the global thread_id?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- name: Send initial message to start a thread
  community.general.slack:
    token: "{{ slack_token }}"
    channel: "#channel"
    msg: "first"
  register: slack_response

- name: Upload a file in the same thread
  community.general.slack:
    token: "{{ slack_token }}"
    channel: "#channel"
    upload_file:
      path: "/path/to/README.md"
      initial_comment: "blablabla"
      alt_text: "My README"
      thread_ts: "{{ slack_response.ts }}"  # specific to file uploads

In this case, using thread_id globally has no effect on the file upload. It must be passed as thread_ts within the upload_file dictionary. That’s why this option is duplicated.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But - why? Can't you use the global parameter thread_id for the value of thread_ts?


if upload_file:
try:
upload_response = upload_file_to_slack(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this seems to be very separate from the rest of the module. Maybe this should be a new module that only does file uploading, instead of squeezing this into the current module which is about posting messages?

Copy link
Author

@Powma Powma Mar 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but should I create a new file in plugins/module_utils ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we upload a file together with sending a message, as in the same request? If yes, then I would suggest to keep the feature in this module, else create a new module.

As of new file in module_utils, if you end up with two modules, it is likely there will be some common code between them and it would make total sense to put that common code in module_utils. If not, then probably no need to.

@russoz russoz changed the title feat(slack) : Add file upload functionality slack: add file upload functionality Jan 2, 2025
@ansibullbot ansibullbot added the stale_ci CI is older than 7 days, rerun before merging label Jan 10, 2025
@russoz
Copy link
Collaborator

russoz commented Feb 23, 2025

ping @Powma

Are you still working on this?

@felixfontein
Copy link
Collaborator

needs_info

@ansibullbot ansibullbot added the needs_info This issue requires further information. Please answer any outstanding questions label Mar 23, 2025
@Powma
Copy link
Author

Powma commented Mar 23, 2025

Sorry, I’ll take a look at it next week. I know there’s an IRC channel if I need help.

@ansibullbot ansibullbot removed the needs_info This issue requires further information. Please answer any outstanding questions label Mar 23, 2025
Powma and others added 2 commits March 27, 2025 10:57
docs(slack): unify file upload API links

Co-authored-by: Felix Fontein <[email protected]>
docs(slack): unify file upload API links

Co-authored-by: Alexei Znamensky <[email protected]>
@ansibullbot ansibullbot removed the stale_ci CI is older than 7 days, rerun before merging label Mar 27, 2025
@ansibullbot ansibullbot added the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR label Mar 27, 2025
docs(changelog): improve wording for Slack upload feature

Co-authored-by: Felix Fontein <[email protected]>
@ansibullbot ansibullbot removed the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR label Mar 27, 2025
@ansibullbot

This comment was marked as outdated.

@ansibullbot ansibullbot added the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR label Mar 27, 2025
@ansibullbot ansibullbot removed the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR label Mar 27, 2025
@ansibullbot

This comment was marked as outdated.

@ansibullbot ansibullbot added ci_verified Push fixes to PR branch to re-run CI needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR labels Mar 27, 2025
@ansibullbot ansibullbot removed ci_verified Push fixes to PR branch to re-run CI needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR labels Mar 27, 2025
U(https://api.slack.com/methods/files.completeUploadExternal).
suboptions:
path:
type: str
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
type: str
type: path

type: str
description:
- Optional timestamp of parent message to thread this message, see U(https://api.slack.com/docs/message-threading).
version_added: 10.2.0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
version_added: 10.2.0
version_added: 10.6.0

@ansibullbot ansibullbot added the stale_ci CI is older than 7 days, rerun before merging label Apr 5, 2025
@russoz
Copy link
Collaborator

russoz commented Apr 18, 2025

Hi @Powma

You are probably busy, but the PR is very close to being good to go, and we're having a release of the collection next week. Do you think you will have time to give it some TLC before that? No pressure, just trying to work on the logistics, there will be other releases in the future. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-10 Automatically create a backport for the stable-10 branch check-before-release PR will be looked at again shortly before release and merged if possible. feature This issue/PR relates to a feature request module module new_contributor Help guide this first time contributor plugins plugin (any type) stale_ci CI is older than 7 days, rerun before merging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants