Join slack channels with slack-id (#23495)
* Join slack channels with slack-id Fixes https://github.com/metabase/metabase/issues/23229 We upload images to a channel and then send messages to the desired channel referencing those images from the channel we uploaded. But the slack bot must be in the channel to upload images. We handle this in `slack/upload-image!` where we watch the error message and join the channel if we recognize that is our issue. This special upload channel is set in the admin section when setting up, typed in by a human. Slack now requires us to use the internal id of the channel when joining. IE we used to use "metabase_files" but now we need to use something like "C87LQNL0Y23". But we do not have this information and we don't want humans to have to look this up. SOLUTION: change our cache. We currently just get a list of channels and users ``` ["#general" "@dan" ...] ``` Change this to ``` {:version 2, :channels [{:display-name "#random", :name "random", :id "CT2FNGZSRPL", :type "channel"} {:display-name "#general", :name "general", :id "C87LQNL0Y23", :type "channel"} {:display-name "@dan", :type "user", :name "dan", :id "UR65C4ZJVIW"} ...]} ``` Now we have slack internal ids present. When we attempt to join the slack channel, look for this id and attempt to use that. This has some knock-on effects. The UI still lists the channels in a channel picker when sending pulses. The list sent over the wire still mimics the previous shape (a flat list) and the choice is still the human readable name. In the future we should switch over to using the stable ids rather than solely channel names. Channel names can be renamed. I didn't go down this route because of the files channel. It is set at setup before we have a channel list. We could do some kind of run time migration but it is difficult because it would change the type of `slack-files-channel` from string to :json to handle the more complex type. Or perhaps we could make another setting to hold the json form and set that when we can positively identify things. In either case, these changes were not required yet to fix our slack issue. We just upgrade the information we have about slack channels, downgrade it when it hits the wire so the UI needs no changes, and use the extra information in the one spot where we need it. The cache is populated at startup and every four hours after that. So we do not need to worry about the old cache shape. If the new code is running, its the new cache. * Send #channel and @user forms over wire We store `{"channel": "#slack-pulses"}` in the pulse_channel.details column so we should keep those types of values around. We use the bare portion ("slack-pulses") rather than with the hash on it so we seem to be mixing usernames and channels. But these sets are distinct and you cannot create a channel with the same name as a user. Also, channel names are lowercase while channel-ids are uppercase so those are also non-overlapping sets. * Put slack token so slack reports as configured * Errant tap> * Alignment and docstring fixes * Remove slack-cache version information remove the `:version 2` from the cache. We are always in charge of the cache, and we compute it on startup so there's little risk of other data shapes being present.
Showing
- src/metabase/api/pulse.clj 3 additions, 1 deletionsrc/metabase/api/pulse.clj
- src/metabase/integrations/slack.clj 39 additions, 15 deletionssrc/metabase/integrations/slack.clj
- src/metabase/task/refresh_slack_channel_user_cache.clj 1 addition, 1 deletionsrc/metabase/task/refresh_slack_channel_user_cache.clj
- test/metabase/api/pulse_test.clj 22 additions, 11 deletionstest/metabase/api/pulse_test.clj
- test/metabase/api/slack_test.clj 10 additions, 8 deletionstest/metabase/api/slack_test.clj
- test/metabase/integrations/slack_test.clj 70 additions, 13 deletionstest/metabase/integrations/slack_test.clj
Please register or sign in to comment