core
core copied to clipboard
Method deprecated for file-based message: SlackApi
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
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 closeCloses the issue.@home-assistant rename Awesome new titleRenames the issue.@home-assistant reopenReopen the issue.@home-assistant unassign slackRemoves the current integration label and assignees on the issue, add the integration domain after the command.@home-assistant add-label needs-more-informationAdd a label (needs-more-information, problem in dependency, problem in custom component) to the issue.@home-assistant remove-label needs-more-informationRemove 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)
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.
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?
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.
Bump
bump please
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'}")
While this 100% needs to get fixed migrating to the new method in a HA friendly way is likely beyond my skillset.
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
👋 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 🤞
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!
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 🤞
Reviewed two more PRs.
@tkdrob, @FletcherAU let me know if you have any concerns or feedback. Thanks!
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 :)
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 🙇
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.
Quick update: I reduced the scope of the PR so hopefully make it easier for review.
@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
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!
🎉 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!
Many thanks for this @jsuar !
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
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
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 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?
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
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?
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.
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
#testchannel naming and0xHEXchannel-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.