小编gat*_*sby的帖子

有没有办法判断您的应用程序是否在 Microsoft Teams 中运行

我有一个 Web 应用程序,如果它在 Microsoft Teams 中运行,则需要执行特定代码,但是我还没有弄清楚是否有任何方法可以判断您的应用程序是否在团队中运行。有什么想法或见解吗?

编辑:

对于任何想知道我们最终使用下面两个答案的组合的人,在应用程序启动时,它会检查应用程序的 url 以查看它是否包含“/teams”。团队应用程序被明确告知指向 {app_name}/teams,如果这种情况属实,它将运行以下代码块:

import * as microsoftTeams from '@microsoft/teams-js';


if (window.location.pathname.includes('teams')) {
    microsoftTeams.initialize(() => {
      microsoftTeams.getContext(context => {
        store.dispatch(teamsDetected(context.hostClientType!));
        try {
          microsoftTeams.settings.registerOnSaveHandler(saveEvent => {
            microsoftTeams.settings.setSettings({
              websiteUrl: window.location.href,
              contentUrl: `${window.location.href}&teams`,
              entityId: context.entityId,
              suggestedDisplayName: document.title
            });
            saveEvent.notifySuccess();
          });
          microsoftTeams.settings.setValidityState(true);
        } catch (err) {
          console.error('failed to set teams settings')
        }
      });
    });
  }
Run Code Online (Sandbox Code Playgroud)

microsoft-teams

5
推荐指数
1
解决办法
2672
查看次数

标签 统计

microsoft-teams ×1