slack-ruby / slack-ruby/slack-ruby-client
Passing chat_postMessage attachments=null will cause "Copy Link" in Slack not to unfurl.
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 1.3k
- Forks
- 222
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 3
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the Ruby client's chat_postMessage request-building path and inspect the Faraday request body when attachments is nil. Reproduce the call described in the issue, then verify that the selected handling of nil arguments prevents the Slack Copy Link unfurling regression.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100