MicrosoftDocs / msteams-docs

Source for the Microsoft Teams developer platform documentation.
https://aka.ms/teamsdev
Creative Commons Attribution 4.0 International
285 stars 508 forks source link

Link Unfurling | Automatic Refresh invoke of MS teams bot doesn't work on the preview dialog #10067

Open Vignesh-s-s opened 11 months ago

Vignesh-s-s commented 11 months ago

Link unfurling works with bringing a base card at first and then automatic refresh happens and then the bot brings up the user specific card in MS teams. This behaviour works fine when tried on teams web client or desktop client. However, the automatic refresh invoke doesn't happen in the share preview dialog (https://teams.microsoft.com/share), the link unfurling brings up only the base card and stops there. Is the automatic refresh not supported in the share dialog?

SaiPratap-MSFT commented 11 months ago

@Vignesh-s-s - Thanks for reporting your issue. Could you please share any video reference for both cases for better understanding the issue

Vignesh-s-s commented 11 months ago

https://github.com/MicrosoftDocs/msteams-docs/assets/7553761/0928a21a-e512-4b4e-856d-fc93213265e5

https://github.com/MicrosoftDocs/msteams-docs/assets/7553761/d3e7645f-eb7c-47d5-86d0-e434b713dcf4

@SaiPratap-MSFT I have uploaded two video links for both cases.

ChetanSharma-msft commented 11 months ago

Hello @Vignesh-s-s - Thanks for sharing the videos. Could you please let us know how you have implemented the automatic refresh functionality in Link Unfurling card? Please share code, steps and any reference doc, so that we can try to repro it from our end quickly.

Naina-G commented 11 months ago

Hi @ChetanSharma-msft , Replying on behalf of @Vignesh-s-s

Please find below details, Document followed for adding automatic refresh functionality: https://learn.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/universal-actions-for-adaptive-cards/user-specific-views?tabs=mobile%2Cnodejs

https://learn.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/universal-actions-for-adaptive-cards/up-to-date-views

We have a conversational bot where user pastes any valid link, handleTeamsAppBasedLinkQuery is called and we return a base card (adaptive card) from this handler which is shown to the user. Schema of this base card that we return on unfurling is as shown below:

{
  "type": "AdaptiveCard",
  "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
  "version": "1.4",
  "msTeams": {
    "width": "full"
  },
  "metadata": {
    "webUrl": "${applicationURL}"
  },
  "refresh": {
    "action": {
      "fallback": "drop",
      "type": "Action.Execute",
      "verb": "refreshCard",
      "title": "See Latest",
      "data": {
        "cardUrl": "${cardUrl}",
        "loading": true
    }
    }
  },
  "body": [...],
}

In the schema of base card, we maintain a refresh clause as shown in the above code. This refresh clause is to trigger automatic refresh of base card and then return user specific card on refresh.

We are not maintaining the userIds property in refresh clause, as we want the automatic refresh to be triggered for all users. Please refer to this line "If the userIds field isn't specified in the Refresh property, Teams client can automatically trigger refresh for all users when there are less than or equal to 60 members in the conversation." in https://learn.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/universal-actions-for-adaptive-cards/user-specific-views?tabs=mobile%2Cnodejs

As shared in videos and comments earlier, when we maintain refresh clause in base card, refresh is automatically triggered for all users when tried on teams web client or desktop client. However, the automatic refresh invoke doesn't happen in the share preview dialog (https://teams.microsoft.com/share), the link unfurling brings up only the base card and stops there.

Please let us know in case of further details needed from our end

SaiPratap-MSFT commented 10 months ago

@Vignesh-s-s - Could you please share your sample repo code or deployed app package for better investigating the issue

Naina-G commented 10 months ago

Hi @SaiPratap-MSFT, We cat share the repo link ad its private once, But below is the code sample of how we have implemented the handlers: Inside handleTeamsAppBasedLinkQuery : // We check for the url received on unfurling, and if the url contains certain query params like Card_Title etc // We construct a result object and return from the handler as shown below

const result = {
                    attachmentLayout: "list",
                    type: "result",
                    attachments: [],
                };
                result.attachments.push({
                    // Cannot send an adaptive card without the dummy preview Herocard
                    preview: CardFactory.heroCard(CARD_TITLE, [LOGO]),
                    ...CardFactory.adaptiveCard(card)  // here card is AdaptiveCards.declare(cardSchema).render(cardData);
                });
                 return {
            composeExtension: result,
            responseType: "composeExtension"
        };

When refresh is triggered onAdaptiveCardInvoke is called and we return updated card a shown below:

 if (updatedCard) {
                return {
                    statusCode: 200,
                    type: "application/vnd.microsoft.card.adaptive",
                    value: updatedCard // updatedCard is AdaptiveCards.declare(userSpecificSchema).render(data);
                };
            }

PFA section from Manifest file where we declare information for bots and compose extensions, we have removed our org specific values

"bots": [
    {
        "botId": "${{CONFIG__MANIFEST__BOTID}}",
        "scopes": [
            "personal",
            "team",
            "groupchat"
        ]
   }
  ],
  "composeExtensions": [
    {
      "botId": "${{CONFIG__MANIFEST__BOTID}}",
      "commands": [
        {
          "id": "searchQuery",
          "context": ["compose", "commandBox"],
          "description": "SAP Community Search",
          "title": "Search",
          "type": "query",
          "parameters": [
            {
              "name": "searchQuery",
              "title": "Search Query",
              "description": "Ask SAP",
              "inputType": "text"
            }
          ]
        }
      ],
      "messageHandlers": [
        {
          "type": "link",
          "value": {
            "domains": [
              "token.botframework.com",
              "*.botframework.com"
// Other domains which we validate for unfurling the link
            ]
          }
        }
      ]
    }
  ],
ChetanSharma-msft commented 10 months ago

Hello @Naina-G - Sorry for delay in response. The "Share to Teams" feature is primarily used for sharing content from external apps or websites to Teams. It may not support all the interactive features of Adaptive Cards, including auto refresh functionality.

However, we will check with engineering team and let you know the updates.

Naina-G commented 10 months ago

Thanks @ChetanSharma-msft Did you hear back anything on this issue ?

ChetanSharma-msft commented 10 months ago

Hello @Naina-G - Sorry for delay in response. We are actively checking your issue with engineering team and let you know the updates, if any.

SaiPratap-MSFT commented 10 months ago

Hello @Naina-G - We have raised bug for this issue. We will inform you once we get any update.

Naina-G commented 10 months ago

@SaiPratap-MSFT Thanks, would you be able to share bug Id for tracking ?

SaiPratap-MSFT commented 10 months ago

@Naina-G - We have raised bug internally and you won't have access to it.