botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

No link preview for bot message - improve Slack support

Open KonstantinKharitonov opened this issue 10 years ago • 17 comments

Hello,

We create Slack bot using MS bot network for simple notifications from HR Tech project. https://cerebro.slack.com/apps/A243V8QEQ-staya-bot

If bot send text messages w/ external link, slack don't create preview (sniped for link by Open Graph protocol) But if user send the same message preview created see img. attachment - bug_bot

And we have answer from Slack support team:

When a bot sends a message via the "chat.postMessagemethod" you will need to set the "unfurl_links" and "unfurl_media" arguments to true for Slack to unful and display a preview.

More information can be found here in the API docs which explains in further detail about unfurling and how it works (https://api.slack.com/docs/message-attachments#unfurling).

Note: Once an a link or media has already been unfurled in a channel, reposting the same URL will not trigger to occur again.

We don't have access for changing behavior for chat.postMessagemethod in Slack by MS bot connector.
May be some one from MSbotframework team can help us?

KonstantinKharitonov avatar Aug 25 '16 10:08 KonstantinKharitonov

Slack defaults unfurl_media to true and unfurl_links to false. If you want to change the defaults you can pass them in ChannelData as follows:

reply.Text = "<http://www.youtube.com/watch?v=wq1R93UMqlk>";
reply.ChannelData = JObject.FromObject(new { unfurl_links = true, unfurl_media = true });

I've closed this issue. Please reopen if you have additional questions

craigjensen avatar Aug 26 '16 01:08 craigjensen

We use you JavaScipt API for bots. Can't you provide ex. using JavaScipt? P.S: BTW - you JS documentation don't have good amount of examples :(

KonstantinKharitonov avatar Aug 26 '16 12:08 KonstantinKharitonov

@muzahmed @Stevenic can you provide an example in node?

Andrea-Orimoto avatar Aug 26 '16 17:08 Andrea-Orimoto

You can use something like this:

function oneOffTests(session) {

    replyMessage = new builder.Message(session)
        .text("<http://www.youtube.com/watch?v=wq1R93UMqlk>");

    replyMessage.channelData = ({
        unfurl_links: "true",
        unfurl_media: "true"
    });

    session.send(replyMessage);
}

jameslew avatar Aug 26 '16 23:08 jameslew

I am POSTing to this endpoint, but my bot still isn't unfurling the message text.

https://slack.com/api/chat.postMessage?token=MY_TOKEN&channel=MY_CHANNEL&text=https://www.my-app.com&unfurl_links=true&unfurl_media=true

@craigjensen @jameslew Am I missing something here?

splutz avatar May 17 '17 18:05 splutz

You can remove the http:// and it doesn't show the preview.

eg. example.com instead of http://example.com.

Booligoosh avatar Nov 04 '17 05:11 Booligoosh

I'm having the same problem with chat.postMessage (via the Python client):

msg = sc.api_call('chat.postMessage', channel=channel, text='https://www.dropbox.com/s/ogtvwayg00qx9hq/Long%20Otter.jpg?raw=1', as_user=True, unfurl_links=True, unfurl_media=True)

This doesn't preview the image, but if I paste the same link into a message myself, it is previewed.

Any idea what's going on?

isokrates avatar Jan 21 '18 09:01 isokrates

Same here:

curl -X POST -H 'Content-type: application/json' --data '{"text":"<www.oreilly.com/ideas/artificial-intelligence-in-the-software-engineering-workflow>", "unfurl_links": true, "unfurl_media": true }' https://hooks.slack.com/services/BLAHBLAH/BLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHB

DiegoGLagash avatar Feb 27 '18 23:02 DiegoGLagash

I see the same behavior with Node.js using the @slack/client module. My Slack bot posts a message containing a link to an image and only the link is displayed. If I copy and paste that same URL into the same channel it is "converted" into an image.

jbodwell avatar Mar 12 '18 11:03 jbodwell

Anyone get this working? Having same issue as @jbodwell with the Node @slack/client module nearly a year later. This is the only thread I've found discussing the issue.

If bot uses postMessage with URL with both unfurl_links and unfurl_media as true, nothing unfurled. If I copy paste the same URL, it's unfurled.

Edit: Should make it clear that I'm attempting to unfurl a Slack File URL. Interestingly, this Slack example states "The message should by posted using the bot_access_token and as_user set to true so that the image unfurls correctly," but when I do that, it still is not unfurled.

simpleshadow avatar Feb 18 '19 15:02 simpleshadow

@simpleshadow I wish I could help you but I left my job (and all the code) where I had this problem.

Good luck!

jbodwell avatar Feb 18 '19 16:02 jbodwell

Still can't unfurl URL now. Tried to use Incoming WebHooks to send message contains a link to Google docs, only url shows without preview. BTW, adding "unfurl_links" : true did not work. While copying the same URL manually and send via slack, the preview shows up correctly.

Wei-Lin-D avatar Nov 18 '19 10:11 Wei-Lin-D

I got the official response from the Slack Help Center: the unfurl link feature is not supported in block kit payload as for now.
So if you use chat.postMessage to post a message in block kit payload, the link will not be unfurled.

libindavis avatar Jun 15 '20 15:06 libindavis

For anyone else finding this in future, unfurl_links: false worked for me.

    replyMessage = new builder.Message(session)
        .text("my message");

    replyMessage.channelData = ({
        unfurl_links: false,
        unfurl_media: false
    });
}

slatlasdev avatar Nov 23 '22 07:11 slatlasdev

Still can't unfurl URL now. Tried to use Incoming WebHooks to send message contains a link to Google docs, only url shows without preview. BTW, adding "unfurl_links" : true did not work. While copying the same URL manually and send via slack, the preview shows up correctly.

After my verification, it was found that Bot tokens and incoming webhooks are not supported unfuring links.

0xleizhang avatar May 01 '24 10:05 0xleizhang

Any update on this? @craigjensen Our integration simply maps a command to an api endpoint through the slack api dashboard. Is it impossible for us to enable link unfurling for our bot?

Thank you!

chase-robbins avatar Sep 18 '24 15:09 chase-robbins

Why can't bot tokens unfurl?!

NathanSweet avatar May 29 '25 19:05 NathanSweet