Botframework-sdk: No link preview for bot message - improve Slack support

Created on 25 Aug 2016  路  13Comments  路  Source: microsoft/botframework-sdk

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?

Most helpful comment

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.

All 13 comments

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

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 :(

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

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);
}

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?

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

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

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?

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

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.

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 I wish I could help you but I left my job (and all the code) where I had this problem.

Good luck!

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.

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.

Was this page helpful?
0 / 5 - 0 ratings