slack-ruby-client icon indicating copy to clipboard operation
slack-ruby-client copied to clipboard

Passing chat_postMessage attachments=null will cause "Copy Link" in Slack not to unfurl.

Open sonjz opened this issue 6 years ago • 3 comments

I was so confused on this one I contacted someone at slack support.

At some point in the last several weeks, we noticed that our Copy Link for messages from from this ruby client would no longer unfurl (create a preview of the original message). This was problematic as we value our previews, and click on a *.slack.com/archive/.... link to see the message (and taking you out of context) isn't a good user experience.

After debugging the output in faraday, I noticed that our attachments was nil but still being added to the request body.

self.SlackClient.chat_postMessage(
  channel: channel,
  text: msg,
  as_user: true,
  link_names: true,
  thread_ts: thread_ts,
  attachments: attachments #passed in as nil
)

I believe in the past this wasn't an issue, but in the last several weeks the behaviour has changed. To fix this I just stopped sending the attachments argument if it was nil.

# see keyword_args: https://www.justinweiss.com/articles/fun-with-keyword-arguments/
keyword_args = {
  channel: channel,
  text: msg,
  as_user: true,
  link_names: true,
}
keyword_args[thread_ts] = thread_ts unless thread_ts.nil?
keyword_args[attachments] = attachments unless attachments.nil?
self.SlackClient.chat_postMessage(**keyword_args)

I was thinking someone might want to filter out any nil arguments from the request body before sending it out (or throw error)

Cheers, Jason.

sonjz avatar Feb 07 '19 19:02 sonjz

From slack support:

There were some stricter schema rules added in preparation for this feature: https://api.slack.com/changelog/2018-12-a-bric-a-brac-of-broadcasts-built-with-blocks' What you described exactly falls in line with those rules.

sonjz avatar Feb 07 '19 20:02 sonjz

Should we add something to this effect to README?

dblock avatar Feb 07 '19 22:02 dblock

I attempted to address a similar issue I was having in #239, but Slack ultimately fixed it for me. Take a look at my comments about chat.update and the code I wrote to handle that situation, since passing null for attachments is not the same thing as omitting attachments with chat.update.

jmanian avatar Feb 11 '19 18:02 jmanian