core icon indicating copy to clipboard operation
core copied to clipboard

Method deprecated for file-based message: SlackApi

Open vikashsonu900 opened this issue 1 year ago • 4 comments

The problem

I have below config and when I am sending the image it results in below error.

service: notify.slack
metadata: {}
data:
  target: "#channel"
  message: Snapshot
  data:
    file: 
      path: "/config/www/image.jpg"
Logger: homeassistant.components.slack.notify
Source: components/slack/notify.py:173
integration: Slack ([documentation](https://www.home-assistant.io/integrations/slack), [issues](https://github.com/home-assistant/core/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+slack%22))
First occurred: 12:18:10 PM (1 occurrences)
Last logged: 12:18:10 PM

Error while uploading file-based message: SlackApiError("The request to the Slack API failed.\nThe server responded with: {'ok': False, 'error': 'method_deprecated'}")

What version of Home Assistant Core has the issue?

core-2024.7.1

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

slack

Link to integration documentation on our website

https://www.home-assistant.io/integrations/slack

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

vikashsonu900 avatar Jul 10 '24 10:07 vikashsonu900

Hey there @tkdrob, @fletcherau, mind taking a look at this issue as it has been labeled with an integration (slack) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of slack can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign slack Removes the current integration label and assignees on the issue, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


slack documentation slack source (message by IssueLinks)

home-assistant[bot] avatar Jul 10 '24 10:07 home-assistant[bot]

The deprecated method appears to be files.upload. While that api will continue to function until March 2025, newly created apps (those of us adding the Slack integration now) can't use this method.

From the linked Slack page:

Existing apps & integrations should migrate away from files.upload and instead leverage a combination of two APIs: files.getUploadURLExternal and files.completeUploadExternal. The use of these two methods is more reliable, especially when uploading large files.

bmcdonnell-zz avatar Jul 11 '24 18:07 bmcdonnell-zz

I currently have the same issue. First I had to add the "files:write" scope, then later I got the same error that this function is deprecated. Is there any workaround or fix I can use?

RemyyB avatar Jul 15 '24 19:07 RemyyB

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

Fine that this issue gets closed if no one is working on it. But in 5 months, when the api is discontinued in March, there will be a lot more folks interested in the issue.

bmcdonnell-zz avatar Oct 17 '24 02:10 bmcdonnell-zz

Bump

reidcooper avatar Oct 21 '24 22:10 reidcooper

bump please

andreaskefalas avatar Nov 01 '24 02:11 andreaskefalas

Yup just found my way here, unable to upload files because i just set this up and no longer can use it

Hopefully its OK to retag @tkdrob @FletcherAU for help!

Log details (ERROR) Logger: homeassistant.components.slack.notify Source: components/slack/notify.py:173 integration: Slack (documentation, issues) First occurred: 6:07:28 PM (3 occurrences)

Last logged: 7:15:04 PM

Error while uploading file-based message: SlackApiError("The request to the Slack API failed.\nThe server responded with: {'ok': False, 'error': 'method_deprecated'}")

k1n6b0b avatar Nov 11 '24 00:11 k1n6b0b

While this 100% needs to get fixed migrating to the new method in a HA friendly way is likely beyond my skillset.

FletcherAU avatar Nov 11 '24 16:11 FletcherAU

Heh well my skill set stops at tagging others and hoping :) I did find a workaround, saving the file to local media and using a slack message data block with the external URL of my home assistant instance I was able to get the image to show on slack... not as universal or secure as posting the file to slack but it worked for me for now

k1n6b0b avatar Nov 12 '24 01:11 k1n6b0b

👋 Hi all, I stumbled on this because I happened to be testing out HA this weekend. I really want tight Slack integration so this is a bummer. Luckily, I think I should have a PR for the fix soon 🤞

jsuar avatar Dec 02 '24 16:12 jsuar

I got the draft PR out. I just need to review some other PRs and then I'll formally open it. Feedback welcomed in the meantime. Thanks!

jsuar avatar Dec 06 '24 04:12 jsuar

I've never contributed to this project so reviewing PRs was tough. I reviewed two smaller ones and will try to review a few others. Either way, I formally opened the PR 🤞

jsuar avatar Dec 06 '24 20:12 jsuar

Reviewed two more PRs.

@tkdrob, @FletcherAU let me know if you have any concerns or feedback. Thanks!

jsuar avatar Dec 09 '24 17:12 jsuar

Thank you for your contributions <3 I should have time to spin up the branch for testing later this week but it looks good at first glance :)

FletcherAU avatar Dec 09 '24 17:12 FletcherAU

Quick update for interested folks. I have a PR to address the breaking API change including a PR to add a small note in the docs

Local image uploads were straightforward. Remote images, not so much. Either way, hopefully we can get this out sometime soon. Let me know if you have any feedback or concerns 🙇

jsuar avatar Jan 04 '25 02:01 jsuar

Thank you @jsuar for helping the few of us using slack. Must say, recently the file upload fails more than it works. So really excited to see this change go in.

tinuva avatar Jan 10 '25 06:01 tinuva

Quick update: I reduced the scope of the PR so hopefully make it easier for review.

jsuar avatar Jan 12 '25 14:01 jsuar

@FletcherAU Apologies for the multiple pings today. I’ve created a new PR with the bare minimum changes required to fix the file upload issue. Unfortunately, the Slack client needed updating due to outdated dependencies, but I’ve kept the changes strictly focused on resolving this issue. Let me know if you have any questions!

  • Old PR https://github.com/home-assistant/core/pull/132451 (PR closed)
  • New PR https://github.com/home-assistant/core/pull/135818

Far less code added Old PR changes

New PR changes

jsuar avatar Jan 17 '25 03:01 jsuar

Another update:

  • @zweckj has provided excellent feedback on the new PR, which helped refine it further.
  • I’ve made a few changes to address the feedback, but the overall PR remains narrow in scope.

I’m excited to see this get merged and start using it on my server.

Thanks to everyone for their patience and collaboration!

jsuar avatar Jan 19 '25 02:01 jsuar

🎉 The fix for this issue has been merged with PR #135818, addressing Slack's API deprecation of files.upload. Thanks to everyone who provided feedback and helped push this forward!

jsuar avatar Jan 20 '25 15:01 jsuar

Many thanks for this @jsuar !

tinuva avatar Jan 20 '25 16:01 tinuva

It looks like the fix has been pulled into https://github.com/home-assistant/core/releases/tag/2025.2.0b1 as my Slack integration is now working. Not sure why the fix isn't listed in the description

jsuar avatar Jan 30 '25 18:01 jsuar

The PR is officially listed in the 2025.2.0 changelog. @vikashsonu900 I think this issue can be closed once you confirm it's working on your end

jsuar avatar Feb 06 '25 01:02 jsuar

Well initially I still had issues but noticed I have a log error

2025-02-12 06:10:17.927 ERROR (MainThread) [homeassistant.components.slack.notify] Error getting channel ID: SlackApiError("The request to the Slack API failed. (url: https://slack.com/api/conversations.list, status: 200)\nThe server responded with: {'ok': False, 'error': 'missing_scope', 'needed': 'channels:read,groups:read,mpim:read,im:read', 'provided': 'channels:join,chat:write,files:write,chat:write.public,chat:write.customize'}")

After adding those 4 missing, I can now send files as images. I also tried a url, and that seemed to end up as a binary on slack, so possibly doing something wrong there. No matter though, files at least work now.

tinuva avatar Feb 12 '25 04:02 tinuva

@tinuva Yes, unfortunately the deprecation caused some issues on how we handled channel names vs IDs. I provided some details here. I'm working on a new PR to make this easier and more backwards compatible, however, this will require more permissions scope.

Can you share an example of your config so I can see how you are sending the images?

jsuar avatar Feb 12 '25 15:02 jsuar

aha ok. that makes sense, not sure why I missed it. But happy to add the permissions for the fact that it does make life simpler.

As for how I am using it, work in progress to get my camera notifications working nicely.

Cameras using it direct: https://github.com/tinuva/home-assistant-config/blob/6a176b3dbef3995cd28b27b01d0af838bd411e6e/packages/security/bi.yaml#L36

Or a more generic script I used to use but need to reconsider: https://github.com/tinuva/home-assistant-config/blob/6a176b3dbef3995cd28b27b01d0af838bd411e6e/packages/notifications/notification_scripts.yaml#L70

tinuva avatar Feb 12 '25 18:02 tinuva

Now that I think about it. Is there a way one could specify the channel id instead of channel name, to reduce the api calls, so as to make the notifications quicker?

tinuva avatar Feb 12 '25 18:02 tinuva

It works now, but the docs need updating badly.

If one is to upload files, extra slack "scopes" are required, no word about this in the docs.

im:read, mpim:read, channels:read, groups:read, dnd:read

p.s. Also, funny: In case of a text message, both #test channel naming and 0xHEX channel-id is accepted. In the case of the file, neither works, unless relevant scopes are added in the slack app.

bogorad avatar Feb 19 '25 20:02 bogorad

It works now, but the docs need updating badly.

If one is to upload files, extra slack "scopes" are required, no word about this in the docs.

im:read, mpim:read, channels:read, groups:read, dnd:read

p.s. Also, funny: In case of a text message, both #test channel naming and 0xHEX channel-id is accepted. In the case of the file, neither works, unless relevant scopes are added in the slack app.

I fixed by trial and error and adding the missing permissions. I also needed to add files:write permission.

Indeed the documentation should be updated because it is not clear at all.

groenmarsmannetje avatar Apr 05 '25 13:04 groenmarsmannetje