Skip to content

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

Open

Description

@sonjz

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.

Activity

  1. changed the title [-]Passing chat_postMessage attachments=null will cause "Copy Links" not to unfurl.[/-] [+]Passing chat_postMessage attachments=null will cause "Copy Link" in Slack not to unfurl.[/+] on Feb 7, 2019
  2. sonjz commented on Feb 7, 2019

    @sonjz
    Author

    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.

  3. dblock commented on Feb 7, 2019

    @dblock
    Collaborator

    Should we add something to this effect to README?

  4. jmanian commented on Feb 11, 2019

    @jmanian
    Collaborator

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions