|
1 | 1 | ---
|
2 | 2 | title: Expose SharePoint Framework web parts in Microsoft Teams
|
3 | 3 | description: You can expose web parts built using SharePoint Framework in Microsoft Teams.
|
4 |
| -ms.date: 06/15/2020 |
| 4 | +ms.date: 07/02/2020 |
5 | 5 | ms.prod: sharepoint
|
6 | 6 | localization_priority: Normal
|
7 | 7 | ---
|
8 | 8 |
|
9 | 9 | # Expose SharePoint Framework web parts in Microsoft Teams
|
10 | 10 |
|
11 |
| -Using SharePoint Framework, you can build [web parts](web-parts/overview-client-side-web-parts.md) and [extensions](extensions/overview-extensions.md). When building web parts, you can enable them to be exposed as a Microsoft Teams tab or a personal app. |
| 11 | +Using SharePoint Framework, you can build [web parts](web-parts/overview-client-side-web-parts.md) and [extensions](extensions/overview-extensions.md). When building web parts, you can enable them to be exposed as a [Microsoft Teams tab](https://docs.microsoft.com/microsoftteams/platform/tabs/what-are-tabs), a [personal app](https://docs.microsoft.com/microsoftteams/platform/concepts/design/personal-apps) or a [messaging extension](https://docs.microsoft.com/microsoftteams/platform/messaging-extensions/what-are-messaging-extensions). |
12 | 12 |
|
13 | 13 | > [!TIP]
|
14 | 14 | > To see how to use the different concepts described in this article, see the sample [Leads application](https://github.com/pnp/sp-dev-solutions/tree/master/solutions/LeadsLOBSolution) on GitHub.
|
15 | 15 |
|
| 16 | +## Expose web part as Microsoft Teams tab |
| 17 | + |
16 | 18 | To expose a SharePoint Framework client-side web part as a Microsoft Teams tab, in the web part’s manifest, in the `supportedHosts` property, add `TeamsTab`.
|
17 | 19 |
|
18 | 20 | 
|
19 | 21 |
|
| 22 | +## Expose web part as Microsoft Teams personal app |
| 23 | + |
20 | 24 | To expose the web part as a Microsoft Teams personal app, in the web part’s manifest, in the `supportedHosts` property, add `TeamsPersonalApp`.
|
21 | 25 |
|
22 | 26 | 
|
23 | 27 |
|
24 | 28 | > [!TIP]
|
25 | 29 | > The same SharePoint Framework web part can be exposed as a web part in SharePoint, Microsoft Teams tab and a personal Teams app. The values specified in the `supportedHosts` property decide how users will be able to work with your web part.
|
26 | 30 |
|
| 31 | +## Expose web part as Microsoft Teams messaging extension |
| 32 | + |
| 33 | +To expose your SharePoint Framework web part as a messaging extension, you don't need to use a specific host in the `supportedHosts` property. Instead, all you need to do, is to extend the teams manifest in your SharePoint Framework solution with a `composeExtension`, for example: |
| 34 | + |
| 35 | +```json |
| 36 | +{ |
| 37 | + "$schema": "https://developer.microsoft.com/json-schemas/teams/v1.5/MicrosoftTeams.schema.json", |
| 38 | + "manifestVersion": "1.5", |
| 39 | + // trimmed for brevity |
| 40 | + "composeExtensions": [ |
| 41 | + { |
| 42 | + "botId": "a349bab7-f895-4d6e-977a-764779833699", |
| 43 | + "canUpdateConfiguration": true, |
| 44 | + "commands": [ |
| 45 | + { |
| 46 | + "id": "shareLead", |
| 47 | + "type": "action", |
| 48 | + "title": "Share a lead", |
| 49 | + "description": "Find and share a lead", |
| 50 | + "initialRun": false, |
| 51 | + "fetchTask": false, |
| 52 | + "context": [ |
| 53 | + "commandBox", |
| 54 | + "compose" |
| 55 | + ], |
| 56 | + "taskInfo": { |
| 57 | + "title": "Share a lead", |
| 58 | + "width": "1100", |
| 59 | + "height": "665", |
| 60 | + "url": "https://{teamSiteDomain}/_layouts/15/TeamsLogon.aspx?SPFX=true&dest=/_layouts/15/teamstaskhostedapp.aspx%3Fteams%26personal%26componentId=e81a1b68-686e-412f-90ac-cb80f2544398%26forceLocale={locale}" |
| 61 | + } |
| 62 | + } |
| 63 | + ] |
| 64 | + } |
| 65 | + ] |
| 66 | + // trimmed for brevity |
| 67 | +} |
| 68 | +``` |
| 69 | + |
| 70 | +The key piece of information is the URL in the `taskInfo` property, which must match the URL specified in the example and which should have the `componentId` query string parameter set to the ID of the SharePoint Framework web part that should be exposed in the messaging extension. |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | +### Responding to user interaction |
| 75 | + |
| 76 | +When your web part is exposed in Microsoft Teams as a messaging extension, you might want to respond to user interaction, for example by posting an adaptive card to the conversation. This requires using a [task module](https://docs.microsoft.com/microsoftteams/platform/task-modules-and-cards/what-are-task-modules) and a [bot](https://docs.microsoft.com/microsoftteams/platform/bots/what-are-bots). The task module notifies the bot of the event that the user triggered, and the bot will post data back to the conversation. First however, you need to check if the web part is used as a messaging extension. |
| 77 | + |
| 78 | +To check if your web part is being used as a messaging extension, check if the `context._host._teamsManager._appContext.applicationName` property is set to `TeamsTaskModuleApplication`: |
| 79 | + |
| 80 | +```typescript |
| 81 | +private leadClicked = (ev?: React.SyntheticEvent<HTMLElement>): void => { |
| 82 | + const host: string = this.props.host._teamsManager._appContext.applicationName; |
| 83 | + if (host !== 'TeamsTaskModuleApplication') { |
| 84 | + return; |
| 85 | + } |
| 86 | + |
| 87 | + // web part used as a messaging extension |
| 88 | +} |
| 89 | +``` |
| 90 | + |
| 91 | +[see full code](https://github.com/pnp/sp-dev-solutions/blob/cd3757ac071e2fb9f90a3f64b43ede8b1de39a0c/solutions/LeadsLOBSolution/webpart/src/webparts/leads/components/Leads/Leads.tsx#L111-L114) |
| 92 | + |
| 93 | +Once you verified that the web part is used as a messaging extension, you use a task module, to pass the data from the web part to the bot: |
| 94 | + |
| 95 | +```typescript |
| 96 | +private leadClicked = (ev?: React.SyntheticEvent<HTMLElement>): void => { |
| 97 | + const host: string = this.props.host._teamsManager._appContext.applicationName; |
| 98 | + if (host !== 'TeamsTaskModuleApplication') { |
| 99 | + return; |
| 100 | + } |
| 101 | + |
| 102 | + // web part used as a messaging extension |
| 103 | + this.props.teamsContext.tasks.submitTask(selectedLead[0]); |
| 104 | +} |
| 105 | +``` |
| 106 | + |
| 107 | +[see full code](https://github.com/pnp/sp-dev-solutions/blob/cd3757ac071e2fb9f90a3f64b43ede8b1de39a0c/solutions/LeadsLOBSolution/webpart/src/webparts/leads/components/Leads/Leads.tsx#L128) |
| 108 | + |
| 109 | +After receiving the notification, the bot can process the retrieved data and post some information to the conversation. |
| 110 | + |
| 111 | +```typescript |
| 112 | +protected async handleTeamsMessagingExtensionSubmitAction(context: TurnContext, action: MessagingExtensionAction): Promise<MessagingExtensionActionResponse> { |
| 113 | + const lead: Lead = action.data; |
| 114 | + let leadChangeIcon: string = ""; |
| 115 | + if (lead.change > 0) { |
| 116 | + leadChangeIcon = "🔼 "; |
| 117 | + } else if (lead.change < 0) { |
| 118 | + leadChangeIcon = "🔽 "; |
| 119 | + } |
| 120 | + |
| 121 | + const leadCard = CardFactory.adaptiveCard({ |
| 122 | + "$schema": "http://adaptivecards.io/schemas/adaptive-card.json", |
| 123 | + "type": "AdaptiveCard", |
| 124 | + "version": "1.0", |
| 125 | + // trimmed for brevity |
| 126 | + }); |
| 127 | + |
| 128 | + await context.sendActivity({ attachments: [leadCard] }); |
| 129 | + |
| 130 | + return Promise.resolve({}); |
| 131 | +} |
| 132 | +``` |
| 133 | + |
| 134 | +[see full code](https://github.com/pnp/sp-dev-solutions/blob/cd3757ac071e2fb9f90a3f64b43ede8b1de39a0c/solutions/LeadsLOBSolution/bot/src/app/leadsBot/LeadsBot.ts#L24) |
| 135 | + |
| 136 | +> [!TIP] |
| 137 | +> For more information about building Microsoft Teams messaging extensions see the [Microsoft Teams documentation](https://docs.microsoft.com/microsoftteams/platform/messaging-extensions/what-are-messaging-extensions). To see an example of how a SharePoint Framework web part is exposed as a messaging extension see the sample [Leads application](https://github.com/pnp/sp-dev-solutions/tree/master/solutions/LeadsLOBSolution) on GitHub. |
| 138 | +
|
27 | 139 | When you choose to expose your SharePoint Framework web parts in Microsoft Teams, you have a number of options for how to deploy them to Microsoft Teams.
|
28 | 140 |
|
29 | 141 | ## Use the autogenerated Microsoft Teams manifest
|
|
0 commit comments