Slack not unfurling image links to display preview image

5.4k Views Asked by At

I set up a Slackbot to post Craigslist listings and the URL is no longer unfurling to display the preview image when the message is posted.

A few things to note:

  • I have selected the following scopes under OAuth & Permissions, as stated in https://api.slack.com/reference/messaging/link-unfurling#setup

    1. links:read
    2. links:write
  • 'https://' is included in my image URLs

  • each link is a valid URL that links to an image

  • Any random Craigslist link I include doesn't unfurl in Slack (it used to)

  • I've ran this Slackbot before (not the final code) where the preview image was showing. I understand that Slack doesn't render images if the unique link has already been shared in the channel, but right now this isn't the case. I also noticed that when the preview images were rendering before, the message was "edited". See screenshot

Link unfurling when I ran the program on 8/31. My code has been updated since then but nothing drastic. Note that the message states '(edited)' however I didn't any of the messages.

What the message in Slack looks like now, on 9/15

My post_to_slack function:

client = WebClient(SLACK_TOKEN)
        attachments = [{"image_url": image_url_link}]
        desc = f" {result_price.text} | {title_text} | {datetime} | {url} | {neighborhood_text} | {final_final_strip} | {image_url_link} | "
        response = client.chat_postMessage(channel=SLACK_CHANNEL, text=desc, attachments=attachments, unfurl_links=True, unfurl_media=True)

Am I missing something? Did Slack update something with unfurling or is it Craigslist? Any insight would be appreciated. Thank you!

2

There are 2 best solutions below

0
On

The images were able to show up after including the .jpg URL in the Slack message. I forgot I had this previously

2
On

To do unfurling, you need to receive events from Slack (one such event is link_shared which lets you know a link was shared, so you can post the unfurl).

To set up a Slack bot to handle Events, you need to run your bot somewhere that Slack can send http requests to. For example, if you have your own server, you might host your app at https://slack.example.com/mybot . Then when you are configuring your app in Slack, you specify your request URL to be that.

Take a look at their documentation to get all the specific details. If you are doing this in python, you should be able to use the Python Events SDK to handle a lot of the details and simplify things.