sample added
This commit is contained in:
parent
36aba947f1
commit
82f52a6d29
|
@ -32,4 +32,6 @@ obj
|
||||||
# Styles Generated Code
|
# Styles Generated Code
|
||||||
*.scss.ts
|
*.scss.ts
|
||||||
|
|
||||||
packages/
|
packages/
|
||||||
|
samples/react-teams-send-notification/MyNotes.md
|
||||||
|
samples/react-teams-send-notification/teams/teams.zip
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
# EditorConfig helps developers define and maintain consistent
|
||||||
|
# coding styles between different editors and IDEs
|
||||||
|
# editorconfig.org
|
||||||
|
|
||||||
|
root = true
|
||||||
|
|
||||||
|
|
||||||
|
[*]
|
||||||
|
|
||||||
|
# change these settings to your own preference
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
||||||
|
|
||||||
|
# we recommend you to keep these unchanged
|
||||||
|
end_of_line = lf
|
||||||
|
charset = utf-8
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
insert_final_newline = true
|
||||||
|
|
||||||
|
[*.md]
|
||||||
|
trim_trailing_whitespace = false
|
||||||
|
|
||||||
|
[{package,bower}.json]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
|
@ -0,0 +1,32 @@
|
||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
|
||||||
|
# Dependency directories
|
||||||
|
node_modules
|
||||||
|
|
||||||
|
# Build generated files
|
||||||
|
dist
|
||||||
|
lib
|
||||||
|
solution
|
||||||
|
temp
|
||||||
|
*.sppkg
|
||||||
|
|
||||||
|
# Coverage directory used by tools like istanbul
|
||||||
|
coverage
|
||||||
|
|
||||||
|
# OSX
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
|
# Visual Studio files
|
||||||
|
.ntvs_analysis.dat
|
||||||
|
.vs
|
||||||
|
bin
|
||||||
|
obj
|
||||||
|
|
||||||
|
# Resx Generated Code
|
||||||
|
*.resx.ts
|
||||||
|
|
||||||
|
# Styles Generated Code
|
||||||
|
*.scss.ts
|
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
"@microsoft/generator-sharepoint": {
|
||||||
|
"isCreatingSolution": true,
|
||||||
|
"environment": "spo",
|
||||||
|
"version": "1.11.0",
|
||||||
|
"libraryName": "react-teams-send-notification",
|
||||||
|
"libraryId": "22dbb17f-8889-4859-a7a6-f32d951f640b",
|
||||||
|
"packageManager": "npm",
|
||||||
|
"isDomainIsolated": false,
|
||||||
|
"componentType": "webpart"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,79 @@
|
||||||
|
# react-teams-send-notification
|
||||||
|
|
||||||
|
## Summary
|
||||||
|
|
||||||
|
This webpart allows you to send MS Teams feed notifications to a selected user. It is using the new beta endpoint documented here: [https://docs.microsoft.com/en-us/graph/teams-send-activityfeednotifications](https://docs.microsoft.com/en-us/graph/teams-send-activityfeednotifications)
|
||||||
|
|
||||||
|
![react-teams-send-notification](./assets/teams-notification-sender.gif)
|
||||||
|
|
||||||
|
## Used SharePoint Framework Version
|
||||||
|
|
||||||
|
![version](https://img.shields.io/badge/version-1.11-green.svg)
|
||||||
|
|
||||||
|
## Applies to
|
||||||
|
|
||||||
|
- [SharePoint Framework](https://aka.ms/spfx)
|
||||||
|
- [Microsoft 365 tenant](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/set-up-your-developer-tenant)
|
||||||
|
|
||||||
|
> Get your own free development tenant by subscribing to [Microsoft 365 developer program](http://aka.ms/o365devprogram)
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
|
||||||
|
- You need to get the Azure AD ClientID for the "SharePoint Online Client Extensibility Web Application Principal" Application. You can do this from the Azure AD portal.
|
||||||
|
|
||||||
|
## Solution
|
||||||
|
|
||||||
|
Solution|Author(s)
|
||||||
|
--------|---------
|
||||||
|
react-teams-send-notification | Luis Mañez (MVP, [ClearPeople](http://www.clearpeople.com), @luismanez)
|
||||||
|
|
||||||
|
## Version history
|
||||||
|
|
||||||
|
Version|Date|Comments
|
||||||
|
-------|----|--------
|
||||||
|
1.0|December 4, 2020|Initial release
|
||||||
|
|
||||||
|
## Disclaimer
|
||||||
|
|
||||||
|
**THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.**
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Minimal Path to Awesome
|
||||||
|
|
||||||
|
- Clone this repository
|
||||||
|
- Ensure that you are at the solution folder
|
||||||
|
- In the command-line run:
|
||||||
|
- **npm install**
|
||||||
|
- **gulp bundle --ship**
|
||||||
|
- **gulp package-solution --ship**
|
||||||
|
- Deploy .sppkg to SharePoint
|
||||||
|
- Edit the file __/teams/manifest.json__ and update the _webApplicationInfo_ with your _SharePoint Online Client Extensibility Web Application Principal_ App ID
|
||||||
|
- Zip the files in the _/teams_ folder, and deploy it to Teams
|
||||||
|
- Add the new SPFx Tab to any Team
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
This webpart illustrates the following concepts:
|
||||||
|
|
||||||
|
- Using the new Feed notifications API in MS Graph from an SPFx Teams Tab (spfx webpart running as Teams tab)
|
||||||
|
- Using the Graph Toolkit react components (PeoplePicker)
|
||||||
|
- Using FluentUI components
|
||||||
|
|
||||||
|
## References
|
||||||
|
|
||||||
|
About this sample:
|
||||||
|
|
||||||
|
- [https://docs.microsoft.com/en-us/graph/api/team-sendactivitynotification?view=graph-rest-beta&tabs=http](https://docs.microsoft.com/en-us/graph/api/team-sendactivitynotification?view=graph-rest-beta&tabs=http)
|
||||||
|
- [https://docs.microsoft.com/en-us/graph/api/resources/teamworkactivitytopic?view=graph-rest-beta](https://docs.microsoft.com/en-us/graph/api/resources/teamworkactivitytopic?view=graph-rest-beta)
|
||||||
|
- [https://docs.microsoft.com/en-us/graph/api/resources/itembody?view=graph-rest-beta](https://docs.microsoft.com/en-us/graph/api/resources/itembody?view=graph-rest-beta)
|
||||||
|
- [https://docs.microsoft.com/en-us/graph/api/resources/aadusernotificationrecipient?view=graph-rest-beta](https://docs.microsoft.com/en-us/graph/api/resources/aadusernotificationrecipient?view=graph-rest-beta)
|
||||||
|
|
||||||
|
|
||||||
|
About SPFx:
|
||||||
|
|
||||||
|
- [Getting started with SharePoint Framework](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/set-up-your-developer-tenant)
|
||||||
|
- [Building for Microsoft teams](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/build-for-teams-overview)
|
||||||
|
- [Use Microsoft Graph in your solution](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/web-parts/get-started/using-microsoft-graph-apis)
|
||||||
|
- [Publish SharePoint Framework applications to the Marketplace](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/publish-to-marketplace-overview)
|
||||||
|
- [Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp) - Guidance, tooling, samples and open-source controls for your Microsoft 365 development
|
Binary file not shown.
After Width: | Height: | Size: 12 MiB |
|
@ -0,0 +1,19 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/config.2.0.schema.json",
|
||||||
|
"version": "2.0",
|
||||||
|
"bundles": {
|
||||||
|
"teams-notification-sender-web-part": {
|
||||||
|
"components": [
|
||||||
|
{
|
||||||
|
"entrypoint": "./lib/webparts/teamsNotificationSender/TeamsNotificationSenderWebPart.js",
|
||||||
|
"manifest": "./src/webparts/teamsNotificationSender/TeamsNotificationSenderWebPart.manifest.json"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"externals": {},
|
||||||
|
"localizedResources": {
|
||||||
|
"TeamsNotificationSenderWebPartStrings": "lib/webparts/teamsNotificationSender/loc/{locale}.js",
|
||||||
|
"ControlStrings": "node_modules/@pnp/spfx-controls-react/lib/loc/{locale}.js"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/copy-assets.schema.json",
|
||||||
|
"deployCdnPath": "temp/deploy"
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/deploy-azure-storage.schema.json",
|
||||||
|
"workingDir": "./temp/deploy/",
|
||||||
|
"account": "<!-- STORAGE ACCOUNT NAME -->",
|
||||||
|
"container": "react-teams-send-notification",
|
||||||
|
"accessKey": "<!-- ACCESS KEY -->"
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
|
||||||
|
"solution": {
|
||||||
|
"name": "react-teams-send-notification-client-side-solution",
|
||||||
|
"id": "22dbb17f-8889-4859-a7a6-f32d951f640b",
|
||||||
|
"version": "1.0.0.0",
|
||||||
|
"includeClientSideAssets": true,
|
||||||
|
"skipFeatureDeployment": true,
|
||||||
|
"isDomainIsolated": false,
|
||||||
|
"developer": {
|
||||||
|
"name": "",
|
||||||
|
"websiteUrl": "",
|
||||||
|
"privacyUrl": "",
|
||||||
|
"termsOfUseUrl": "",
|
||||||
|
"mpnId": ""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"paths": {
|
||||||
|
"zippedPackage": "solution/react-teams-send-notification.sppkg"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/core-build/serve.schema.json",
|
||||||
|
"port": 4321,
|
||||||
|
"https": true,
|
||||||
|
"initialPage": "https://localhost:5432/workbench",
|
||||||
|
"api": {
|
||||||
|
"port": 5432,
|
||||||
|
"entryPath": "node_modules/@microsoft/sp-webpart-workbench/lib/api/"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/write-manifests.schema.json",
|
||||||
|
"cdnBasePath": "<!-- PATH TO CDN -->"
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const build = require('@microsoft/sp-build-web');
|
||||||
|
|
||||||
|
build.addSuppression(`Warning - [sass] The local CSS class 'ms-Grid' is not camelCase and will not be type-safe.`);
|
||||||
|
|
||||||
|
build.initialize(require('gulp'));
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,43 @@
|
||||||
|
{
|
||||||
|
"name": "react-teams-send-notification",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"private": true,
|
||||||
|
"main": "lib/index.js",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.10.0"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"build": "gulp bundle",
|
||||||
|
"clean": "gulp clean",
|
||||||
|
"test": "gulp test"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@microsoft/mgt": "^1.3.6",
|
||||||
|
"@microsoft/mgt-react": "^2.0.0-preview.8",
|
||||||
|
"@microsoft/sp-core-library": "1.11.0",
|
||||||
|
"@microsoft/sp-lodash-subset": "1.11.0",
|
||||||
|
"@microsoft/sp-office-ui-fabric-core": "1.11.0",
|
||||||
|
"@microsoft/sp-property-pane": "1.11.0",
|
||||||
|
"@microsoft/sp-webpart-base": "1.11.0",
|
||||||
|
"@pnp/spfx-controls-react": "2.2.0",
|
||||||
|
"office-ui-fabric-react": "6.214.0",
|
||||||
|
"react": "16.8.5",
|
||||||
|
"react-dom": "16.8.5"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@microsoft/rush-stack-compiler-3.3": "0.3.5",
|
||||||
|
"@microsoft/rush-stack-compiler-3.7": "^0.6.35",
|
||||||
|
"@microsoft/sp-build-web": "1.11.0",
|
||||||
|
"@microsoft/sp-module-interfaces": "1.11.0",
|
||||||
|
"@microsoft/sp-tslint-rules": "1.11.0",
|
||||||
|
"@microsoft/sp-webpart-workbench": "1.11.0",
|
||||||
|
"@types/chai": "3.4.34",
|
||||||
|
"@types/es6-promise": "0.0.33",
|
||||||
|
"@types/mocha": "2.2.38",
|
||||||
|
"@types/react": "16.8.8",
|
||||||
|
"@types/react-dom": "16.8.3",
|
||||||
|
"@types/webpack-env": "1.13.1",
|
||||||
|
"ajv": "~5.2.2",
|
||||||
|
"gulp": "~3.9.1"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
// A file is required to be in the root of the /src directory by the TypeScript compiler
|
|
@ -0,0 +1,27 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/spfx/client-side-web-part-manifest.schema.json",
|
||||||
|
"id": "f86ed598-f65b-40f4-aab7-1a42e5496295",
|
||||||
|
"alias": "TeamsNotificationSenderWebPart",
|
||||||
|
"componentType": "WebPart",
|
||||||
|
|
||||||
|
// The "*" signifies that the version should be taken from the package.json
|
||||||
|
"version": "*",
|
||||||
|
"manifestVersion": 2,
|
||||||
|
|
||||||
|
// If true, the component can only be installed on sites where Custom Script is allowed.
|
||||||
|
// Components that allow authors to embed arbitrary script code should set this to true.
|
||||||
|
// https://support.office.com/en-us/article/Turn-scripting-capabilities-on-or-off-1f2c515f-5d7e-448a-9fd7-835da935584f
|
||||||
|
"requiresCustomScript": false,
|
||||||
|
"supportedHosts": ["SharePointWebPart", "TeamsTab"],
|
||||||
|
|
||||||
|
"preconfiguredEntries": [{
|
||||||
|
"groupId": "5c03119e-3074-46fd-976b-c60198311f70", // Other
|
||||||
|
"group": { "default": "Other" },
|
||||||
|
"title": { "default": "TeamsNotificationSender" },
|
||||||
|
"description": { "default": "Allows you to send a MS Teams feed notification to a user" },
|
||||||
|
"officeFabricIconFontName": "Page",
|
||||||
|
"properties": {
|
||||||
|
"description": "TeamsNotificationSender"
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
|
@ -0,0 +1,69 @@
|
||||||
|
import * as React from 'react';
|
||||||
|
import * as ReactDom from 'react-dom';
|
||||||
|
import { Version } from '@microsoft/sp-core-library';
|
||||||
|
import {
|
||||||
|
IPropertyPaneConfiguration,
|
||||||
|
PropertyPaneTextField
|
||||||
|
} from '@microsoft/sp-property-pane';
|
||||||
|
import { BaseClientSideWebPart } from '@microsoft/sp-webpart-base';
|
||||||
|
|
||||||
|
import * as strings from 'TeamsNotificationSenderWebPartStrings';
|
||||||
|
import TeamsNotificationSender from './components/TeamsNotificationSender';
|
||||||
|
import { ITeamsNotificationSenderProps } from './components/ITeamsNotificationSenderProps';
|
||||||
|
|
||||||
|
import { Providers, SharePointProvider } from '@microsoft/mgt';
|
||||||
|
|
||||||
|
export interface ITeamsNotificationSenderWebPartProps {
|
||||||
|
description: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class TeamsNotificationSenderWebPart extends BaseClientSideWebPart<ITeamsNotificationSenderWebPartProps> {
|
||||||
|
|
||||||
|
protected async onInit(): Promise<void> {
|
||||||
|
Providers.globalProvider = new SharePointProvider(this.context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public render(): void {
|
||||||
|
//console.log(this.context.pageContext.site.group);
|
||||||
|
const element: React.ReactElement<ITeamsNotificationSenderProps> = React.createElement(
|
||||||
|
TeamsNotificationSender,
|
||||||
|
{
|
||||||
|
teamsContext: this.context.sdks.microsoftTeams,
|
||||||
|
groupId: this.context.pageContext.site.group.id,
|
||||||
|
webpartContext: this.context
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
ReactDom.render(element, this.domElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected onDispose(): void {
|
||||||
|
ReactDom.unmountComponentAtNode(this.domElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected get dataVersion(): Version {
|
||||||
|
return Version.parse('1.0');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
|
||||||
|
return {
|
||||||
|
pages: [
|
||||||
|
{
|
||||||
|
header: {
|
||||||
|
description: strings.PropertyPaneDescription
|
||||||
|
},
|
||||||
|
groups: [
|
||||||
|
{
|
||||||
|
groupName: strings.BasicGroupName,
|
||||||
|
groupFields: [
|
||||||
|
PropertyPaneTextField('description', {
|
||||||
|
label: strings.DescriptionFieldLabel
|
||||||
|
})
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
import { IMicrosoftTeams, WebPartContext } from "@microsoft/sp-webpart-base";
|
||||||
|
|
||||||
|
export interface ITeamsNotificationSenderProps {
|
||||||
|
teamsContext?: IMicrosoftTeams;
|
||||||
|
groupId: string;
|
||||||
|
webpartContext: WebPartContext;
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
export interface ITeamsNotificationSenderState {
|
||||||
|
groupName: string;
|
||||||
|
selectedPeople: string;
|
||||||
|
notificationText: string;
|
||||||
|
success?: boolean;
|
||||||
|
}
|
|
@ -0,0 +1,74 @@
|
||||||
|
@import '~office-ui-fabric-react/dist/sass/References.scss';
|
||||||
|
|
||||||
|
.teamsNotificationSender {
|
||||||
|
.container {
|
||||||
|
max-width: 700px;
|
||||||
|
margin: 0px auto;
|
||||||
|
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2), 0 25px 50px 0 rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.row {
|
||||||
|
@include ms-Grid-row;
|
||||||
|
@include ms-fontColor-white;
|
||||||
|
background-color: $ms-color-themeDark;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.column {
|
||||||
|
@include ms-Grid-col;
|
||||||
|
@include ms-lg10;
|
||||||
|
@include ms-xl8;
|
||||||
|
@include ms-xlPush2;
|
||||||
|
@include ms-lgPush1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.title {
|
||||||
|
@include ms-font-xl;
|
||||||
|
@include ms-fontColor-white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.subTitle {
|
||||||
|
@include ms-font-l;
|
||||||
|
@include ms-fontColor-white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.description {
|
||||||
|
@include ms-font-l;
|
||||||
|
@include ms-fontColor-white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button {
|
||||||
|
// Our button
|
||||||
|
text-decoration: none;
|
||||||
|
height: 32px;
|
||||||
|
|
||||||
|
// Primary Button
|
||||||
|
min-width: 80px;
|
||||||
|
background-color: $ms-color-themePrimary;
|
||||||
|
border-color: $ms-color-themePrimary;
|
||||||
|
color: $ms-color-white;
|
||||||
|
|
||||||
|
// Basic Button
|
||||||
|
outline: transparent;
|
||||||
|
position: relative;
|
||||||
|
font-family: "Segoe UI WestEuropean","Segoe UI",-apple-system,BlinkMacSystemFont,Roboto,"Helvetica Neue",sans-serif;
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
font-size: $ms-font-size-m;
|
||||||
|
font-weight: $ms-font-weight-regular;
|
||||||
|
border-width: 0;
|
||||||
|
text-align: center;
|
||||||
|
cursor: pointer;
|
||||||
|
display: inline-block;
|
||||||
|
padding: 0 16px;
|
||||||
|
|
||||||
|
.label {
|
||||||
|
font-weight: $ms-font-weight-semibold;
|
||||||
|
font-size: $ms-font-size-m;
|
||||||
|
height: 32px;
|
||||||
|
line-height: 32px;
|
||||||
|
margin: 0 4px;
|
||||||
|
vertical-align: top;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,121 @@
|
||||||
|
import * as React from "react";
|
||||||
|
import styles from "./TeamsNotificationSender.module.scss";
|
||||||
|
import { ITeamsNotificationSenderProps } from "./ITeamsNotificationSenderProps";
|
||||||
|
import { ITeamsNotificationSenderState } from "./ITeamsNotificationSenderState";
|
||||||
|
import { PeoplePicker } from "@microsoft/mgt-react";
|
||||||
|
import { TextField } from "office-ui-fabric-react/lib/components/TextField/TextField";
|
||||||
|
import { PrimaryButton } from "office-ui-fabric-react/lib/components/Button/PrimaryButton/PrimaryButton";
|
||||||
|
|
||||||
|
export default class TeamsNotificationSender extends React.Component<
|
||||||
|
ITeamsNotificationSenderProps,
|
||||||
|
ITeamsNotificationSenderState
|
||||||
|
> {
|
||||||
|
constructor(props: ITeamsNotificationSenderProps) {
|
||||||
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
groupName: "",
|
||||||
|
selectedPeople: "",
|
||||||
|
notificationText: "",
|
||||||
|
};
|
||||||
|
this._sendNotification = this._sendNotification.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private _getGroupName(id: string): void {
|
||||||
|
this.props.webpartContext.msGraphClientFactory
|
||||||
|
.getClient()
|
||||||
|
.then((graphClient) => {
|
||||||
|
graphClient
|
||||||
|
.api(`/groups/${id}/displayName`)
|
||||||
|
.get((error, response: any, rawResponse?: any) => {
|
||||||
|
if (error) {
|
||||||
|
console.error(error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
groupName: response.value,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private _sendNotification(): void {
|
||||||
|
const endpoint: string = `https://graph.microsoft.com/beta/teams/${this.props.groupId}`;
|
||||||
|
|
||||||
|
const notificationBody: any = {
|
||||||
|
topic: {
|
||||||
|
source: "entityUrl",
|
||||||
|
value: endpoint,
|
||||||
|
},
|
||||||
|
activityType: "readThisRequired",
|
||||||
|
previewText: {
|
||||||
|
content: this.state.notificationText,
|
||||||
|
},
|
||||||
|
recipient: {
|
||||||
|
"@odata.type": "microsoft.graph.aadUserNotificationRecipient",
|
||||||
|
userId: this.state.selectedPeople,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log(notificationBody);
|
||||||
|
|
||||||
|
this.props.webpartContext.msGraphClientFactory
|
||||||
|
.getClient()
|
||||||
|
.then((graphClient) => {
|
||||||
|
graphClient
|
||||||
|
.api(`${endpoint}/sendActivityNotification`)
|
||||||
|
.post(notificationBody);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public componentDidMount(): void {
|
||||||
|
this._getGroupName(this.props.groupId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public render(): React.ReactElement<ITeamsNotificationSenderProps> {
|
||||||
|
if (!this.props.groupId) {
|
||||||
|
return (
|
||||||
|
<p>
|
||||||
|
GroupId not available. Ensure the webpart is running in Teams or
|
||||||
|
SharePoint Team Site
|
||||||
|
</p>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.state.groupName) {
|
||||||
|
return <p>Loading data...</p>;
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSelectionChanged = (e) => {
|
||||||
|
console.log(e.target.selectedPeople);
|
||||||
|
this.setState({ selectedPeople: e.target.selectedPeople[0].id });
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={styles.teamsNotificationSender}>
|
||||||
|
<div className={styles.container}>
|
||||||
|
<div className={styles.row}>
|
||||||
|
<div className={styles.column}>
|
||||||
|
<h1>{this.state.groupName}</h1>
|
||||||
|
<TextField
|
||||||
|
label="Please enter notification text"
|
||||||
|
onChange={(event) => {
|
||||||
|
this.setState({
|
||||||
|
notificationText: (event.target as HTMLInputElement).value,
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<p>Select the user to Notify:</p>
|
||||||
|
<PeoplePicker
|
||||||
|
selectionChanged={handleSelectionChanged}
|
||||||
|
selectionMode="single"
|
||||||
|
groupId={this.props.groupId}
|
||||||
|
/>
|
||||||
|
<PrimaryButton text="Primary" onClick={this._sendNotification} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
7
samples/react-teams-send-notification/src/webparts/teamsNotificationSender/loc/en-us.js
vendored
Normal file
7
samples/react-teams-send-notification/src/webparts/teamsNotificationSender/loc/en-us.js
vendored
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
define([], function() {
|
||||||
|
return {
|
||||||
|
"PropertyPaneDescription": "Description",
|
||||||
|
"BasicGroupName": "Group Name",
|
||||||
|
"DescriptionFieldLabel": "Description Field"
|
||||||
|
}
|
||||||
|
});
|
10
samples/react-teams-send-notification/src/webparts/teamsNotificationSender/loc/mystrings.d.ts
vendored
Normal file
10
samples/react-teams-send-notification/src/webparts/teamsNotificationSender/loc/mystrings.d.ts
vendored
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
declare interface ITeamsNotificationSenderWebPartStrings {
|
||||||
|
PropertyPaneDescription: string;
|
||||||
|
BasicGroupName: string;
|
||||||
|
DescriptionFieldLabel: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
declare module 'TeamsNotificationSenderWebPartStrings' {
|
||||||
|
const strings: ITeamsNotificationSenderWebPartStrings;
|
||||||
|
export = strings;
|
||||||
|
}
|
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
Binary file not shown.
After Width: | Height: | Size: 416 B |
|
@ -0,0 +1,61 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/en-us/json-schemas/teams/v1.8/MicrosoftTeams.schema.json",
|
||||||
|
"manifestVersion": "1.8",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"id": "6dd40ce9-f485-47f7-a40a-921649e818d9",
|
||||||
|
"packageName": "com.sambori.teamsfeed",
|
||||||
|
"developer": {
|
||||||
|
"name": "Luis Mañez",
|
||||||
|
"websiteUrl": "https://www.github.com/luismanez",
|
||||||
|
"privacyUrl": "https://www.github.com/luismanez",
|
||||||
|
"termsOfUseUrl": "https://www.github.com/luismanez"
|
||||||
|
},
|
||||||
|
"icons": {
|
||||||
|
"color": "f86ed598-f65b-40f4-aab7-1a42e5496295_color.png",
|
||||||
|
"outline": "f86ed598-f65b-40f4-aab7-1a42e5496295_outline.png"
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"short": "SPFxTeamsAlert",
|
||||||
|
"full": "Testing feed notifications API"
|
||||||
|
},
|
||||||
|
"description": {
|
||||||
|
"short": "Just testing Feed notifications API",
|
||||||
|
"full": "The Microsoft Teams activity feed enables users to triage items that require attention by notifying them of changes."
|
||||||
|
},
|
||||||
|
"accentColor": "#FFFFFF",
|
||||||
|
"configurableTabs": [
|
||||||
|
{
|
||||||
|
"configurationUrl": "https://{teamSiteDomain}{teamSitePath}/_layouts/15/TeamsLogon.aspx?SPFX=true&dest={teamSitePath}/_layouts/15/teamshostedapp.aspx%3FopenPropertyPane=true%26teams%26componentId=f86ed598-f65b-40f4-aab7-1a42e5496295",
|
||||||
|
"canUpdateConfiguration": true,
|
||||||
|
"scopes": ["team"],
|
||||||
|
"context": ["channelTab"]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"staticTabs": [],
|
||||||
|
"bots": [],
|
||||||
|
"composeExtensions": [],
|
||||||
|
"permissions": ["identity", "messageTeamMembers"],
|
||||||
|
"validDomains": [
|
||||||
|
"*.login.microsoftonline.com",
|
||||||
|
"*.sharepoint.com",
|
||||||
|
"*.sharepoint-df.com",
|
||||||
|
"spoppe-a.akamaihd.net",
|
||||||
|
"spoprod-a.akamaihd.net",
|
||||||
|
"resourceseng.blob.core.windows.net",
|
||||||
|
"msft.spoppe.com",
|
||||||
|
"github.com"
|
||||||
|
],
|
||||||
|
"webApplicationInfo": {
|
||||||
|
"id": "e2c3a0e0-9bb1-46b4-907d-f9197614b8a1",
|
||||||
|
"resource": "https://{teamSiteDomain}"
|
||||||
|
},
|
||||||
|
"activities": {
|
||||||
|
"activityTypes": [
|
||||||
|
{
|
||||||
|
"type": "readThisRequired",
|
||||||
|
"description": "Just another activity",
|
||||||
|
"templateText": "{actor} created a new notification"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
{
|
||||||
|
"extends": "./node_modules/@microsoft/rush-stack-compiler-3.7/includes/tsconfig-web.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "es5",
|
||||||
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
"module": "esnext",
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"jsx": "react",
|
||||||
|
"declaration": true,
|
||||||
|
"sourceMap": true,
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"outDir": "lib",
|
||||||
|
"inlineSources": false,
|
||||||
|
"strictNullChecks": false,
|
||||||
|
"noUnusedLocals": false,
|
||||||
|
"typeRoots": [
|
||||||
|
"./node_modules/@types",
|
||||||
|
"./node_modules/@microsoft"
|
||||||
|
],
|
||||||
|
"types": [
|
||||||
|
"es6-promise",
|
||||||
|
"webpack-env"
|
||||||
|
],
|
||||||
|
"lib": [
|
||||||
|
"es5",
|
||||||
|
"dom",
|
||||||
|
"es2015.collection"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"src/**/*.ts",
|
||||||
|
"src/**/*.tsx"
|
||||||
|
],
|
||||||
|
"exclude": [
|
||||||
|
"node_modules",
|
||||||
|
"lib"
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
{
|
||||||
|
"extends": "@microsoft/sp-tslint-rules/base-tslint.json",
|
||||||
|
"rules": {
|
||||||
|
"class-name": false,
|
||||||
|
"export-name": false,
|
||||||
|
"forin": false,
|
||||||
|
"label-position": false,
|
||||||
|
"member-access": true,
|
||||||
|
"no-arg": false,
|
||||||
|
"no-console": false,
|
||||||
|
"no-construct": false,
|
||||||
|
"no-duplicate-variable": true,
|
||||||
|
"no-eval": false,
|
||||||
|
"no-function-expression": true,
|
||||||
|
"no-internal-module": true,
|
||||||
|
"no-shadowed-variable": true,
|
||||||
|
"no-switch-case-fall-through": true,
|
||||||
|
"no-unnecessary-semicolons": true,
|
||||||
|
"no-unused-expression": true,
|
||||||
|
"no-with-statement": true,
|
||||||
|
"semicolon": true,
|
||||||
|
"trailing-comma": false,
|
||||||
|
"typedef": false,
|
||||||
|
"typedef-whitespace": false,
|
||||||
|
"use-named-parameter": true,
|
||||||
|
"variable-name": false,
|
||||||
|
"whitespace": false
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue