0

我正在使用 Microsoft Teams Toolkit 创建可配置选项卡。当我在可配置选项卡中时,我想将此选项卡的深层链接保存到我的一个数据库中。但是我看到的是我拥有的应用程序包的应用程序 ID 正在更改。我使用 Teams 工具包生成了应用程序包,然后在不同租户的两个 Teams 频道中上传。我看到两个链接中的应用程序 ID 都已更改。如何确保应用程序 ID 保持不变。还有什么方法可以让我在 Tab 本身中动态获取 app id 和 Tab id?

[![在此处输入图像描述][1]][1]

这是我的代码:

microsoftTeams.getContext((context) => {
      teamId = context.groupId;
      tenantid = context.tid;
      channelId = context.channelId;

      const entityId =
     "_djb2_msteams_prefix_" +
     Util.djb2_hash("<<AppId>>" + ":" + context.entityId.replace(/\+/g, " "));
     
      var ctx ;

     if (context.subEntityId ||  context.channelId) {
       ctx = encodeURIComponent(JSON.stringify({
         subEntityId: context.subEntityId,
         channelId: context.channelId
       }));
     };```

      //How to get the app id and the tab id
     linkUrl="https://teams.microsoft.com/l/entity/**<<AppId>>**/"+entityId+"/" + "&context=" + ctx+ "&groupId="+context.groupId+"&tenantId="+context.tid;
});
 };


 [1]: https://i.stack.imgur.com/T5jGc.png
4

3 回答 3

0

我已经设法解决了这个问题。以下是您可以在可配置选项卡中动态获取应用程序 ID 的方法:

microsoftTeams.getTabInstances(function (tabInstances) {
        // alert(JSON.stringify(tabInstances));     
        var tab = JSON.parse(JSON.stringify(tabInstances.teamTabs.find(x => x.channelId ==channelId)));
        console.log(JSON.stringify(tab));
        appid = tab["appId"];        
            
     });

注意: TabInstance 没有 appId 作为属性,但是当您对 object 进行字符串化时,您会看到该值。

于 2021-11-25T15:28:17.837 回答
0

如果您使用相同的应用程序包,则应用程序 ID 在两种情况下都是相同的(它是在包内的清单文件中定义的那个),并且两个租户中的实体 ID 也相同原因。

于 2021-11-24T11:12:26.843 回答
0

获取应用 ID

当租户中的客户安装您的应用程序时,这实际上会在其租户中创建该应用程序的实例。

如果您作为开发人员 - 在不同范围内安装或加载同一应用程序的多个副本,这也会创建新的应用程序实例 Same 用于将单个清单上传到团队

此团队应用程序实例分配有一个“内部应用程序 ID”,您可以在 Teams AppCatalog 中看到这一点:externalidid在应用程序中指定的manifest.json

根据我的个人经验,您应该能够使用 Teams_App_Manifest_id ,但是当它解析为具有相同外部 ID 的多个应用程序实例时,您可能/将会遇到麻烦。请注意,团队客户端生成的链接倾向于使用internal id. 我想避免这个问题

获取标签 ID

就像在上下文中你有Team.idChannel.id和你的选项卡的 Entity.id 一样,你可以使用 Graph 遍历该通道中的选项卡 https://graph.microsoft.com/beta/teams/{groupId}/channels/{channelId}/tabs?$expand=teamsApp&$filter=configuration/entityId eq '{entityId}'

租户应用目录: 图形浏览器

{
    "@odata.context": "https://graph.microsoft.com/beta/$metadata#appCatalogs/teamsApps",
    "value": [
        {
            "id": "fcb9685a-8bc4-4b82-947b-12f8d2146ec3",
            "externalId": "73fb4e73-97e2-44f6-a880-160933ea881e",
            "displayName": "App SSO in csharp",
            "distributionMethod": "organization"
        },            

用户从租户目录(组织) 图形资源管理器安装应用程序

{
    "@odata.context": "https://graph.microsoft.com/beta/$metadata#users('cb4d216f-1e86-4b8b-94f0-c213b258d376')/teamwork/installedApps(teamsApp())",
    "@odata.count": 86,
    "value": [
        {
            "id": "Y2I0ZDIxNmYtMWU4Ni00YjhiLTk0ZjAtYzIxM2IyNThkMzc2IyNmY2I5Njg1YS04YmM0LTRiODItOTQ3Yi0xMmY4ZDIxNDZlYzM=",
            "teamsApp": {
                "id": "fcb9685a-8bc4-4b82-947b-12f8d2146ec3",
                "externalId": "73fb4e73-97e2-44f6-a880-160933ea881e",
                "displayName": "App SSO in csharp",
                "distributionMethod": "organization"
            }
        },

添加二进制相同的团队应用程序“for me” 会导致应用程序在左侧导航中显示两次(如预期的那样,因此这也添加了一个具有自己的(内部)应用程序 ID 的应用程序实例

在此处输入图像描述

    "@odata.count": 87,
    "value": [
        {
            "id": "Y2I0ZDIxNmYtMWU4Ni00YjhiLTk0ZjAtYzIxM2IyNThkMzc2IyNmY2I5Njg1YS04YmM0LTRiODItOTQ3Yi0xMmY4ZDIxNDZlYzM=",
            "teamsApp": {
                "id": "fcb9685a-8bc4-4b82-947b-12f8d2146ec3",
                "externalId": "73fb4e73-97e2-44f6-a880-160933ea881e",
                "displayName": "App SSO in csharp",
                "distributionMethod": "organization"
            }
        },
    // ....
        {
            "id": "Y2I0ZDIxNmYtMWU4Ni00YjhiLTk0ZjAtYzIxM2IyNThkMzc2IyMyNWYzMDBjMS05ZGE2LTRjYTMtYWUwZS1iN2EwZDJkMDQzZGY=",
            "teamsApp": {
                "id": "25f300c1-9da6-4ca3-ae0e-b7a0d2d043df",
                "externalId": "73fb4e73-97e2-44f6-a880-160933ea881e",
                "displayName": "App SSO in csharp",
                "distributionMethod": "sideloaded"
            }
        },
于 2021-11-25T16:56:26.460 回答