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
- links:read
- 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
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!
To do unfurling, you need to receive events from Slack (one such event is
link_sharedwhich 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.