Deep Link SharePoint News post in Teams using Adaptive card and Power Automate

Microsoft Teams helps us bring together content from different Microsoft 365 services for easier collaboration. In Microsoft Teams connected SharePoint site, SharePoint News connector would help receive news updates from the site. In this post let us see how to create Notifications about new News post with deep link to the post from a communication site in an Adaptive card on a Teams channel using

  1. Adaptive card
  2. Stage View
  3. Power Automate cloud flow

The users from a Teams channel would be able to read & engage on the News post by click of a button as shown below

Adaptive card:

Adaptive Cards are a platform-agnostic method of sharing and displaying blocks of information using JSON across various host applications like Teams, Outlook, Bots etc. The above adaptive card has following information from the News Post

  1. Title
  2. Description
  3. Banner Image Url
  4. Author Profile picture
  5. Author Name
  6. Published Date
  7. Deep Link to the post

The card can be designed based on your requirements from the Adaptive Card Designer portal. The JSON content of the above adaptive card can be downloaded from here.

Stage View:

Stage View helps provide a seamless experience of viewing content in Teams. Users can view the content without leaving the context thus leading to have a higher engagement. For this post, I have used stage view through deep link for a SharePoint News post. Find the syntax below to deep link SharePoint News post

https://teams.microsoft.com/l/stage/teamsAppId/0?context={"contentUrl":" newsPostPageUrl","websiteUrl":"newsPostPageUrl","name":"Internal News"}

In the above syntax replace teamsAppId, newsPostPageUrl & title which I have named as Internal News.

teamsAppId: 2a527703-1f6f-4559-a332-d8a7d288cd88

newsPostPageUrl: The url of the News post in SharePoint.

In the adaptive card action set OpenUrl the following from the stage view syntax should be encoded

{
  "contentUrl":" newsPostPageUrl",
  "websiteUrl":"newsPostPageUrl",
  "name":"Internal News"
}

I have also tested stage view for Microsoft forms & Power BI. You can find the app id for other Microsoft 365 service here on this link

https://docs.microsoft.com/en-us/graph/teams-configuring-builtin-tabs

Power Automate cloud flow:

The Cloud flow is used to send an adaptive card to a Teams channel with the SharePoint News post deep link whenever there is a new News post published in a Communication site.

Step 1: Let us start with creating the Automated cloud flow with SharePoint trigger When an item is created or modified. In the trigger, the Site Address should be url of the communication site and the List Name as the Site Pages Library GUID as shown below

Step 2: In the trigger settings enter the following trigger condition to fire only on the first major version of the News Post

@and(equals(triggerOutputs()?['body/PromotedState'],2),contains(triggerOutputs()?['body/{VersionNumber}'],'1.0'))

For more information on trigger conditions for SharePoint online, go through this blog post.

Step 3: The compose action Compose-StageViewURL with the following code

{
  "contentUrl": "@{triggerOutputs()?['body/{Link}']}",
  "websiteUrl": "@{triggerOutputs()?['body/{Link}']}",
  "name": "Internal News"
}

The trigger output Link should have the url of the News post.

Encode the content in the compose action Compose-StageViewURL using the expression encodeUriComponent() and form the remaining part of the URL.

https://teams.microsoft.com/l/stage/2a527703-1f6f-4559-a332-d8a7d288cd88/0?context= @{encodeUriComponent(outputs('Compose-StageViewURL'))}

on another compose action Compose-StageViewURL-Encoded.

Step 4: Add the action Get user photo to display the picture of the author in the adaptive card. The User (UPN) property of the action can be provided from the trigger output Created By Email. The next step is to convert the output of the Get user photo action to Base64 encoded string using the following expression

concat('data:',body('Get_user_photo_(V2)')?['$content-type'],';base64,',body('Get_user_photo_(V2)')?['$content'])

Step 5: Add the action Post Adaptive card in a chat or channel as shown below

In the adaptive card JSON, find below the mapping information of each property from the output of trigger or action

  1. Title: {triggerOutputs()?[‘body/Title’]
  2. Description: triggerOutputs()?[‘body/Description’]
  3. Banner Image Url: triggerOutputs()?[‘body/BannerImageUrl’]
  4. Author Profile picture: outputs(‘Compose-Base64ProfilePic’)
  5. Author Name: triggerOutputs()?[‘body/Author/DisplayName’]
  6. Published Date: formatDateTime(triggerOutputs()?[‘body/Created’], ‘g’)
  7. Deep Link to the post: outputs(‘Compose-StageViewURL-Encoded’)

The export version of the flow can be downloaded from this GitHub link.

Summary:

The adaptive card with stage view to a SharePoint News post allows the users to open and view the content without leaving the context. The user can also Like or Comment on the News post. Hope you have found this informational & thanks for reading. If you are visiting my blog for the first time, please do look at my other blogposts.

Do you like this article?

Subscribe to my blog with your email address using the widget on the right side or on the bottom of this page to have new articles sent directly to your inbox the moment I publish them.

16 thoughts on “Deep Link SharePoint News post in Teams using Adaptive card and Power Automate

  1. This is great, much better than the built in connector. I am having a slight issue with the flow though. When I click ‘View News Post’ I get a popup that says “channel info is unable to show this view” (and to Contact IT admin if it persists, which is me). Have I missed something?

    Like

    1. There was an issue in the Flow ZIP package which I have uploaded in the GitHub which is now corrected. In the compose action named Compose-StageViewURL change the SharePoint property from Full Path to Link to item

      Like

    2. Are you able to solve the issue (“channel info is unable to show this view”) ,I am still getting the same issue after changing the Compose-StageViewURL SharePoint property from Full Path to Link to item and please let me know what you are providing in the section of teamsAppId .

      Liked by 1 person

  2. Great insturction!

    But I am receiving below error:
    {“error”:”The payload is too large. Please make sure the size is less than 28KB.”}

    Like

    1. I echo your statement, great instructions! But I’m also getting the same error message. I read somewhere (but accidentally closed the browser and now can’t find the link) that a possible workaround is to create a new action, “Send an HTTP request to SharePoint”. I’m new to Power Automate so not really sure how to go about implementing this action to make everything work. Hopefully Mohamed (or anyone else) can help with this!

      Liked by 1 person

      1. This is because of the Adaptive card JSON payload exceeding its limit 28 KB as highlighted by Mika, this is as per design. Are you using any base64 content in the Adaptive card JSON payload? If so convert it to a URL instead which will reduce the payload size.

        Liked by 1 person

  3. Solution is working properly in all the platform IOS /Android/ Desktop .
    Use below context in “compose action Compose-StageViewURL”
    {“contentUrl”:””,”websiteUrl”:””,”name”:”News”,”threadId”:”ChannelID”}

    and for below step there should be no space between (Context= and encodeUriComponent)
    https://teams.microsoft.com/l/stage/2a527703-1f6f-4559-a332-d8a7d288cd88/0?context= @{encodeUriComponent(outputs(‘Compose-StageViewURL’))}

    Liked by 1 person

  4. Thank you for your solution to this. It’s very thorough and detailed. I have tried this except the fact that instead of new post im trying to open an ‘item” of list in stage view. the View opens up but it is giving me an error “unable to reach app”. I am unable to understand why is it so. can you please help?

    Compose URL:
    {
    “contentUrl”: “@{triggerOutputs()?[‘body/{Link}’]}”,
    “name”: “@{triggerOutputs()?[‘body/Title’]}”
    }

    Compose URL Stage View Encoded:

    https://teams.microsoft.com/l/stage/26bc2873-6023-480c-a11b-76b66605ce8c/_djb2_msteams_prefix_1604105787?context=@encodeUriComponent(outputs('Compose-StageView‘))

    What am i doing wrong in this?

    Like

  5. It works for almost anything and not just SharePoint pages! What a bonus!

    (We can even preview PDFs in this “popup” – which is really a floating tab)

    Like

  6. Many thanks for your great article. As others have already reported here, unfortunately the display does not work in iOS. Most of the time, an empty post appears. Every now and then the app crashes completely. Is there already a solution to this (from someone)?

    Like

Leave a comment