slack-ruby-client
slack-ruby-client copied to clipboard
Passing chat_postMessage attachments=null will cause "Copy Link" in Slack not to unfurl.
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.
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.
Should we add something to this effect to README?
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
.