Add link unfurling
Important
The code samples in this section are based on 4.6 and later versions of the Bot Framework SDK. If you're looking for documentation for earlier versions, see the Message Extensions - v3 SDK section in the Resources folder of the documentation.
This document guides you on how to add link unfurling to your app manifest using Developer Portal or manually. With link unfurling, your app can register to receive an invoke activity when URLs with a particular domain are pasted into the compose message area. The invoke contains the full URL that was pasted into the compose message area. You can respond with a card that the user can unfurl for additional information or actions. This works as a search command with the URL as the search term.
Note
- Currently, link unfurling is not supported on Mobile clients.
- The link unfurling result is cached for 30 minutes.
The Azure DevOps message extension uses link unfurling to look for URLs pasted into the compose message area pointing to a work item. In the following image, a user pasted a URL for an item in Azure DevOps that the message extension has resolved into a card:
See the following video to learn more about link unfurling:
Add link unfurling to your app manifest
To add link unfurling to your app manifest, add a new messageHandlers array to the composeExtensions section of your app manifest JSON. You can add the array with the help of Developer Portal or manually. Domain listings can include wildcards, for example *.example.com. This matches exactly one segment of the domain; if you need to match a.b.example.com then use *.*.example.com.
Note
Don't add domains that are not in your control, either directly, or through wildcards. For example, yourapp.onmicrosoft.com is valid, but *.onmicrosoft.com is not valid. The top-level domains are prohibited, for example, *.com, *.org.
Add link unfurling using Developer Portal
Open Developer Portal from the Microsoft Teams client and then select the Apps tab.
Load your app manifest.
On the Messaging Extension page under App features, select existing bot or create a new bot.
Select Save.
Select Add a domain under Preview links section and then enter valid domain.
Select Add. The following image explains the process:
Add link unfurling manually
Note
If authentication is added through Azure AD, unfurl links in Teams using bot.
To enable your message extension to interact with links, first you must add the messageHandlers array to your app manifest. The following example explains how to add link unfurling manually:
...
"composeExtensions": [
{
"botId": "abc123456-ab12-ab12-ab12-abcdef123456",
"messageHandlers": [
{
"type": "link",
"value": {
"domains": [
"*.trackeddomain.com"
]
}
}
]
}
],
...
For a complete manifest example, see manifest reference.
Handle the composeExtension/queryLink invoke
After adding the domain to the app manifest, you must update your web service code to handle the invoke request. Use the received URL to search your service and create a card response. If you respond with more than one card, only the first card response is used.
The following card types are supported:
For more information, see Action type invoke.
Example
protected override async Task<MessagingExtensionResponse> OnTeamsAppBasedLinkQueryAsync(ITurnContext<IInvokeActivity> turnContext, AppBasedLinkQuery query, CancellationToken cancellationToken)
{
//You'll use the query.link value to search your service and create a card response
var card = new HeroCard
{
Title = "Hero Card",
Text = query.Url,
Images = new List<CardImage> { new CardImage("https://raw.githubusercontent.com/microsoft/botframework-sdk/master/icon.png") },
};
var attachments = new MessagingExtensionAttachment(HeroCard.ContentType, null, card);
var result = new MessagingExtensionResult(AttachmentLayoutTypes.List, "result", new[] { attachments }, null, "test unfurl");
return new MessagingExtensionResponse(result);
}
Step-by-step guide
Follow the step-by-step guide to unfurl links in Teams using bot.
See also
Feedback
Submit and view feedback for