Skip to content

Commit

Permalink
Added generic connector sample code (OfficeDev#4)
Browse files Browse the repository at this point in the history
* Added generic connector sample code
  • Loading branch information
Wajeed-msft authored Jan 3, 2021
1 parent 1b2923f commit a7053b9
Show file tree
Hide file tree
Showing 16 changed files with 1,021 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
| | Sample Name | Description | C# | TypeScript |
|:--:|:-------------------|:-------------------------------------------------------------------------------------------------|:--------|:-------------|
|1|Connectors | Sample Office 365 Connector generating notifications to teams channel. |[View][connector#cs] |[View][connector#ts]
|2|Outgoing Webhooks | Samples to create "Custom Bots" to be used in Microsoft Teams. |[View][outgoing-webhook#cs]|[View][outgoing-webhook#ts]
|2|Generic connectors sample | Sample code for a generic connector that's easy to customize for any system which supports webhooks. | |[View][connector-generic#ts]
|3|Outgoing Webhooks | Samples to create "Custom Bots" to be used in Microsoft Teams. |[View][outgoing-webhook#cs]|[View][outgoing-webhook#ts]


## Samples with multiple entry points
Expand All @@ -94,6 +95,7 @@

[connector#cs]:csharp/connector-todo-notification
[connector#ts]:nodejs/connector-github-notification
[connector-generic#ts]:nodejs/connector-generic

[app-auth#ts]:nodejs/app-auth

Expand Down
61 changes: 61 additions & 0 deletions nodejs/connector-generic/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# next.js build output
.next
21 changes: 21 additions & 0 deletions nodejs/connector-generic/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Microsoft Corporation. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE
52 changes: 52 additions & 0 deletions nodejs/connector-generic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Sample Connector
This contains the source for a generic connector that's easy to customize for any system which supports webhooks.

## Prerequisites
To complete this tutorial, you need the following tools. If you don't already have them you can install them from these links.

* [Git](https://git-scm.com/downloads)
* [Node.js and NPM](https://nodejs.org/)
* Get any text editor or IDE. You can install and use [Visual Studio Code](https://code.visualstudio.com/download) for free.
* An Office 365 account with access to Microsoft Teams, with [sideloading enabled](https://docs.microsoft.com/microsoftteams/platform/concepts/build-and-test/prepare-your-o365-tenant#enable-custom-teams-apps-and-turn-on-custom-app-uploading).
* If you want to run this code locally, use a tunnelling service. These instructions assume you are using [ngrok](https://ngrok.com/).

### Configure your own connector

1. Start the tunnelling service to get an https endpoint.
1. Open a new command prompt window.
1. Change to the directory that contains the ngrok.exe application.
1. In the command prompt, run the command `ngrok http 3978 --host-header=localhost`.
1. Ngrok will fill the entire prompt window. Make note of the https:// Forwarding URL. This URL will be your [BASE_URI] referenced below.
1. Minimize the ngrok Command Prompt window. It is no longer referenced in these instructions, but it must remain running.
1. [Register a new connector](https://docs.microsoft.com/microsoftteams/platform/webhooks-and-connectors/how-to/connectors-creating#adding-a-connector-to-your-teams-app)
1. Open [Connector Developer Portal](https://outlook.office.com/connectors/home/login/#/new) and select New Connector.
1. Fill in all the basic details such as name, logo, descriptions etc. for the new connector.
1. For the configuration page, you'll use our sample code's setup endpoint: `https://[BASE_URI]/connector/setup`
1. For Valid domains, make enter your domain's http or https URL, e.g. XXXXXXXX.ngrok.io.
1. Click on Save. After the save completes, you will see your connector ID in address bar.
1. In the `~/views/connectorconfig.jade` file line 27 and replace `ngrokURL` to the ngrok https forwarding url from the above.
1. Install all the dependencies by running `npm install` in root directory.
1. Run the sample: `node server.js`
1. Manifest updates:
1. Replace `ConnectorId` field in `~/app manifest/manifest.json` file with your newly registered connector ID.
1. Select all three files (manifest.json, outline_icon.png, color_icon.png) and create a zip file. This is your Teams App Manifest package.
1. Now you can [upload your app manifest](https://docs.microsoft.com/microsoftteams/platform/concepts/deploy-and-publish/apps-upload#upload-your-package-into-a-team-using-the-apps-tab) package in a team and test your new connector by following instructions in config UI.

## More Information
For more information about getting started with Teams, please review the following resources:
- Review [Office 365 Connectors](https://docs.microsoft.com/microsoftteams/platform/webhooks-and-connectors/how-to/connectors-creating)
- Review [Understanding Teams app capabilities](https://docs.microsoft.com/microsoftteams/platform/concepts/capabilities-overview)

## Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide
a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [[email protected]](mailto:[email protected]) with any additional questions or comments.
Binary file added nodejs/connector-generic/app manifest/color_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions nodejs/connector-generic/app manifest/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"$schema": "https://developer.microsoft.com/en-us/json-schemas/teams/v1.8/MicrosoftTeams.schema.json",
"manifestVersion": "1.8",
"id": "3ea203f0-07f0-46d2-8da3-4639b616cf37",
"version": "1.0",
"packageName": "com.NotifyMe",
"developer": {
"name": "Developer",
"websiteUrl": "https://www.microsoft.com",
"privacyUrl": "https://www.microsoft.com",
"termsOfUseUrl": "https://www.microsoft.com"
},
"name": {
"full": "NotifyMe",
"short": "NotifyMe"
},
"accentColor": "#FFFFFF",
"description": {
"full": "Sample to show how to configure a connector and send notifications inside teams",
"short": "Sample to show how connector works inside teams"
},
"icons": {
"outline": "outline_icon.png",
"color": "color_icon.png"
},
"connectors": [
{
"connectorId": "3ea203f0-07f0-46d2-8da3-4639b616cf37",
"configurationUrl": "https://671872397d19.ngrok.io/connectorconfig",
"scopes": [
"team"
]
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions nodejs/connector-generic/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "connectersample",
"version": "1.0.0",
"main": "app.js",
"dependencies": {
"async": "^2.3.0",
"body-parser": "^1.17.1",
"config": "^1.26.1",
"cookie-parser": "^1.4.3",
"express": "^4.15.2",
"express-partials": "^0.3.0",
"express-session": "^1.15.2",
"jade": "^1.11.0",
"jquery": "^3.2.1",
"method-override": "^2.3.8",
"passport": "^0.3.2"
},
"author": "",
"license": "ISC",
"description": ""
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit a7053b9

Please sign in to comment.