Slack integration doesn't work with custom username/icon/file at the same time

Hi,

I have a slack notification integration that I have been using for a while and it has been working fine. However from some months ago (I don’t recall exactly when because for the longest time I thought it was my NVR not working and not HASS), it seems like if I call the slack notifier service in an automation, it doesn’t work if I specify username/icon at the same time as the file directive.

So this works:

service: notify.slack_notifier
data:
  message: test notification
  title: Some Title
  target: my_notification
  data:
    username: Home Assistant
    icon: house

This also works:

service: notify.slack_notifier
data:
  message: test notification
  title: Some Title
  target: my_notification
  data:
    file:
      path: /config/test.jpg

But this doesn’t:

service: notify.slack_notifier
data:
  message: test notification
  title: Some Title
  target: my_notification
  data:
    username: Home Assistant
    icon: house
    file:
      path: /config/test.jpg

The above would result in an error in the log like this:

Invalid message data: extra keys not allowed @ data[0]['username']

Any ideas what’s the problem when I specify both username/icon and file?

Thanks!

Hi,

I found out why this is and thought I’ll post it in case someone else is running into the same problem.

It is not supported to have the username, icon, and file at the same time because the underlying Slack api (files.upload) does not support a custom username and icon, and therefore the Python client library doesn’t, and in turn mean this integration cannot do that either.

Maybe a good thing to add to the documentation of this integration for anyone else stumbling upon this issue.

Thanks!

Thanks for sharing! I’m trying to track down why a Slack file upload automation of mine started failing sometime on Feb 12th, and this seems somewhat related. However, I think something slightly different is going on in my case as I don’t have a username/icon set on the notify calls that are failing.

Do you mind sharing what type of token you’re using to authenticate with Slack?

Hi,

I am still using an old legacy “bot” custom integration in Slack and not the newer “Slack apps”. For me, under the Bot configuration->Integration Settings section in Slack, there is an “API Token” and that’s the value I use to configure this Slack integration with.

Thanks!