Skip to content

Latest commit

 

History

History
 
 
page_type description products languages extensions urlFragment
sample
Sample that shows how to use dialog bot with bot sdk v4, messaging extension and facebook auth flow in Nodejs.
office-teams
office-365
nodejs
javascript
contentType technologies createdDate
samples
Tabs
05/08/2017 09:41:53 AM
officedev-microsoft-teams-samples-app-complete-sample-nodejs

Microsoft Teams Bot in Node.js

Sample that shows how to use dialog bot with bot sdk v4, messaging extension, facebook auth flow in Nodejs.

  • Interaction with app app-complete-sample

Prerequisites

To try this sample

  1. Register a new application in the Azure Active Directory – App Registrations portal.

  2. Register a bot with Azure Bot Service, following the instructions here.

  • Ensure that you've enabled the Teams Channel
  • While registering the bot, use https://<your_ngrok_url>/api/messages as the messaging endpoint.
  1. To test facebook auth flow [create a facebookapp](https://docs.microsoft.com/en-us/azure/bot-service/bot-service-channel-connect-facebook?view=azure-bot-service- 4.0) and get client id and secret for facebook app. Now go to your bot channel registartion -> configuration -> Add OAuth connection string
  • Provide connection Name : for eg facebookconnection
  • Select service provider ad facebook
  • Add clientid and secret of your facebook app that was created using Step 9.

Open the ".env" file in the project and add connection name which we have provided in bot channel registration E.g. ConnectionName = facebookconnection

  1. Setup NGROK

    • Run ngrok - point to port 3978
    # ngrok http -host-header=rewrite 3978
  2. Clone the repository

    git clone https://github.com/OfficeDev/Microsoft-Teams-Samples.git
  • In a terminal, navigate to samples/app-complete-sample/nodejs

  • Once you have saved your bot and gotten the confirmation that it is created, navigate back to your project. Open the ".env" file. There, copy/paste your App ID and App password from the step above.

    MicrosoftAppId=
    MicrosoftAppPassword=
    BaseUri=https://#####abc.ngrok.io
    
  • Install modules

    npm install
  • Run your bot at the command line:

    npm start
  1. Setup Manifest for Teams
  • This step is specific to Teams.

    • Edit the manifest.json contained in the ./AppPackage folder to replace your Microsoft App Id (that was created when you registered your app registration earlier) everywhere you see the place holder string {{Microsoft-App-Id}} (depending on the scenario the Microsoft App Id may occur multiple times in the manifest.json)
    • Edit the manifest.json for validDomains and replace {{domain-name}} with base Url of your domain. E.g. if you are using ngrok it would be https://1234.ngrok.io then your domain-name will be 1234.ngrok.io.
    • Zip up the contents of the AppPackage folder to create a manifest.zip (Make sure that zip file does not contains any subfolder otherwise you will get error while uploading your .zip package)
  • Upload the manifest.zip to Teams (in the Apps view click "Upload a custom app")

    • Go to Microsoft Teams. From the lower left corner, select Apps
    • From the lower left corner, choose Upload a custom App
    • Go to your project directory, the ./AppPackage folder, select the zip folder, and choose Open.
    • Select Add in the pop-up dialog box. Your app is uploaded to Teams.

Overview

This project is meant to help a Teams developer in two ways. First, it is meant to show many examples of how an app can integrate into Teams. Second, it is meant to give a set of patterns, templates, and tools that can be used as a starting point for creating a larger, scalable, more enterprise level bot to work within Teams. Although this project focuses on creating a robust bot, it does include simples examples of tabs as well as examples of how a bot can give links into these tabs.

What it is

At a high level, this project is written in TypeScript, built to run a Node server, uses Gulp to run its build steps, runs a TypeScript linting tool to keep the code uniform, and uses the BotFramework to handle the bot's requests and responses. This project is designed to be run in VSCode using its debugger in order to leverage breakpoints in TypeScript. Most directories will hold a README file which will describe what the files within that directory do.

The easiest way to get started is to follow the steps listed in the "Steps to get started running the Bot Emulator". Once this is complete and running, the easiest way to add your own content is to create a new dialog in src/dialogs by copying one from src/dialogs/examples, change it accordingly, and then instantiate it with the others in the RootDialog.ts.

Files and Directories

  • manifest

    This directory holds the skeleton of a manifest.json file that can be altered in order sideload this application into a team.

  • public and views

    This directory holds static html, image, and javascript files used by the tabs and bot. This is not the only public directory that is used for the tabs, though. This directory holds the html and javascript used for the configuration page of the configurable tab. The main content of the static and configurable tabs is created dynamically by the code in src/tab/TabSetup.ts or comes from the static files placed in build/src/public/exampleDialogs, which are created at build time based upon the TypeScript dialogs in src/dialogs/examples.

  • src

    This directory holds all of the TypeScript files, which run the entire application. These files, at build, are transpiled and their transpiled javascript files are placed in the build directory.

Running the sample

Contributing

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.