With SPFx 1.7 preview release, I know we can access Teams Context information in SharePoint Framework web part but not from SharePoint Framework extensions. I looked at ApplicationCustomizerContext class but didn't find any reference. Wondering if Teams context information is available in SharePoint Framework extensions?
1 Answer
Interestingly I found the way to get Teams Context information in SPFx extension. Follow the below steps to do it:
Do "npm install @microsoft/teams-js --save" in your SPFx extension project.
In your .ts file or if you using React, then inside your target component, import microsoftTeams names as 'Import * as microsoftTeams from '@microsoft/teams-js'.
In your code, use below code:
try { microsoftTeams.initialize(); microsoftTeams.getContext(tContext => { console.log('Inside Teams:'+tContext.teamName); this.setState({ ShowBanner: false }); }); } catch (error) { console.error("Exception while getting Teams context:" + error); }