Skip to main content

Microsoft Teams: Developer Blog

Microsoft Teams Adaptive cards

Add rich previews to messages using Link unfurling

One of the most common ways to share content in Microsoft Teams is through links, be it for an update for that task you’re working on or for sharing the latest Game of Thrones trailer. For any publicly accessible link Teams already shows a preview of the link including information like an image, title and a description.

But starting today, we’re allowing apps to customize these previews for domains that it’s interested in. Apps can register a message handler for domains that they want to serve, and in doing so will get a queryLink event every time a link of that domain is entered in the compose box.

By default the content is shown in the standard URL preview format supported in Teams, but users have the option to expand to the full card if they wish to do so.

How to add it to your app?

To enable your app to interact with links, you need to add a messageHandlers array to your app manifest, as in the example below: Note that this article assumes that you already have an app with a messaging extension capability, if not please do have a look at our documentation on messaging extensions.

Once you’ve added the domain to listen on to the app manifest, you’ll need to change your bot code to respond to the below invoke request.

In your app you can use the onAppBasedLinkQuery handler to listen to this event and build a response. Here’s the sample code to building the response to the event in Javascript:

This will result in the following response being sent to the client, and will be used to build the Link preview.

Note that if your app responds with more than one preview for a link only the first one will be considered.

What if the user needs to sign in or setup the app?

Just like in the standard messaging extension response, responses for auth and setup are both supported. On receiving these, the Teams client will show an inline message to the user asking them to complete the sign in or setup.

Try it out yourself!

App based link previews are in Developer preview today do try it out and reach out to us for any questions or issues you run into.