如何通过Teams JS SDK或MS Graph API为自定义Microsoft Teams标签页触发显示"New"徽章
Awesome question! I’ve worked with custom Teams tabs before, so let’s walk through exactly how you can trigger that "New" badge when your tab content gets updated—using either the Teams JS SDK or Microsoft Graph API.
Using the Teams JavaScript SDK
If you want to trigger the badge directly from your tab’s frontend (right after a user updates content), you can use the Teams JS SDK to update the tab’s settings. Teams detects changes to the tab’s configuration and will show the "New" badge automatically for all channel members.
Here’s how to do it:
- Make sure you’ve loaded the latest stable version of the Teams JS SDK in your tab.
- After your content finishes updating, call
microsoftTeams.settings.setSettings()to modify a unique identifier for the tab (like adding a timestamp to theentityIdorcontentUrl). This tells Teams the tab has fresh content:
microsoftTeams.settings.setSettings({ entityId: `your-custom-tab-${Date.now()}`, // Unique ID with timestamp to trigger update contentUrl: "https://your-tab-domain.com?contentVersion=" + Date.now(), // Optional: versioned URL suggestedDisplayName: "Your Tab Name" }).then(() => { console.log("Tab settings updated—'New' badge should now appear for all users"); }).catch(error => { console.error("Failed to update tab settings:", error); });
- Note: The user triggering this update needs permissions to modify the tab (usually channel member or higher access works).
Using Microsoft Graph API
If you need to trigger the badge from a backend service (for example, when content is updated automatically without user interaction), the Graph API is your best bet. You can update the tab’s configuration directly, which will trigger the "New" badge across all users in the channel.
Steps to implement:
- Call the
PATCHendpoint for Teams tabs:PATCH https://graph.microsoft.com/v1.0/teams/{team-id}/channels/{channel-id}/tabs/{tab-id} - In the request body, update a unique property like
entityIdto signal a content change:
{ "configuration": { "entityId": "your-tab-entity-" + new Date().toISOString() } }
- Ensure your app has the right permissions: Use
TeamsTab.ReadWriteSelfForTeam(if updating tabs your app installed) orTeamsTab.ReadWrite.All(for broader access).
Once this request succeeds, Teams will immediately show the "New" badge next to your tab name for every member in the channel.
Quick Notes
- The SDK method is great for user-initiated content updates, while the Graph API is perfect for automated backend triggers.
- Test with multiple user accounts to confirm the badge appears consistently—sometimes you might need to refresh Teams to see the update right away.
内容的提问来源于stack exchange,提问作者vt.

