Search code examples
httpslack-apislack

Slack Slash Command Get Request for a Gif


I'm trying to use the slack slash command tool to build a custom command for my team. I want to call a GET request when someone uses the slash command, and the URL I've given it to look up contains just a gif. The HTML of the page gets pasted into Slack instead of the gif itself. How do I get the slash command to post the gif instead? Is there some sort of http query I need to use on the URL to grab the single gif in the response?


Solution

  • Showing the image instead of the URL is called unfurling in Slack. Slack has some special rules on when to unfurl links and when not. And you are able to modify that behavior when using the API method (but not in the response to a slash command).

    From the documentation Attaching content and links to messages

    By default we unfurl all links in any messages posted by users. For messages posted via incoming webhooks or the chat.postMessage API method, we will unfurl links to media, but not other links. (...)

    There is one notable exception to these rules: we never unfurl links where the label is a complete substring of your URL minus the protocol. This is so a paragraph of text can contain domain names or abbreviated URLs that are treated as a simple reference, and not a link to be unfurled.

    Personally I find posting images work best with attachments using the image_url tag, which you can also use as reply to a slash command. See here for more info about how to use them.