Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DO NOT MERGE: Demo of Typescript ActivityHandler class #1202

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions samples/javascript_typescript/30.activity-handler/PREREQUISITES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Azure Deployment Prerequisites
This bot has prerequisite requirements in order to deploy the bot to Azure.

This document will enumerate the required prerequisites and show how to install them.

## Overview
There are a small set of CLI tools that will automate the process of deploying this bot to Azure. These CLI tools are only required for deployment. If you only plan to run the bot locally, these prerequisites are not required.

## Prerequisites
- If you don't have an Azure subscription, create a [free account][5].
- Install the latest version of the [Azure CLI][6] tool. Version 2.0.54 or higher.
- Install latest version of the `MSBot` CLI tool. Version 4.3.2 or higher.
```bash
# install msbot CLI tool
npm install -g msbot
```

[Return to README.md][3]


[3]: ./README.md
[4]: https://nodejs.org
[5]: https://azure.microsoft.com/free/
[6]: https://docs.microsoft.com/cli/azure/install-azure-cli?view=azure-cli-latest
114 changes: 114 additions & 0 deletions samples/javascript_typescript/30.activity-handler/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# ActivityHandler Bot
Bot Builder v4 ActivityHandler sample

This bot has been created using [Microsoft Bot Framework][1], it shows how to create a simple bot that demonstrates the use of the ActivityHandler class for
creating an event-driven bot.

## Prerequisites
- [Node.js][4] version 8.5 or higher
```bash
# determine node version
node --version
```

# To try this sample
- Clone the repository
```bash
git clone https://github.com/microsoft/botbuilder-samples.git
```
- In a console, navigate to `samples/javascript_typescript/02.a.echobot`
```bash
cd samples/javascript_typescript/02.a.echobot
```
- Install modules
```bash
npm install
```
- Start the bot
```bash
npm start
```

# Testing the bot using Bot Framework Emulator **v4**
[Microsoft Bot Framework Emulator][5] is a desktop application that allows bot developers to test and debug their bots on localhost or running remotely through a tunnel.

- Install the Bot Framework Emulator version 4.1.0 or greater from [here][6]

## Connect to the bot using Bot Framework Emulator **v4**
- Launch Bot Framework Emulator
- File -> Open Bot Configuration
- Navigate to `echobot` folder
- Select `samplebot.bot` file

# Deploy the bot to Azure
## Prerequisites
- [Azure Deployment Prerequisites][41]

## Provision a Bot with Azure Bot Service
After creating the bot and testing it locally, you can deploy it to Azure to make it accessible from anywhere. To deploy your bot to Azure:

```bash
# login to Azure
az login
```

```bash
# set you Azure subscription
az account set --subscription "<azure-subscription>"
```

```bash
# provision Azure Bot Services resources to host your bot
msbot clone services --name "<your_bot_name>" --code-dir "." --location westus --sdkLanguage "Node" --folder deploymentScripts/msbotClone --verbose

```

### Publishing Changes to Azure Bot Service
As you make changes to your bot running locally, and want to deploy those change to Azure Bot Service, you can _publish_ those change using either `publish.cmd` if you are on Windows or `./publish` if you are on a non-Windows platform. The following is an example of publishing

```bash
# build the TypeScript bot before you publish
npm run build
```

```bash
# run the publish helper (non-Windows) to update Azure Bot Service. Use publish.cmd if running on Windows
./publish
```

### Getting Additional Help with Deploying to Azure
To learn more about deploying a bot to Azure, see [Deploy your bot to Azure][40] for a complete list of deployment instructions.


# Further reading
- [Bot Framework Documentation][20]
- [Bot Basics][32]
- [Azure Bot Service Introduction][21]
- [Azure Bot Service Documentation][22]
- [Azure CLI][7]
- [msbot CLI][9]
- [Azure Portal][10]
- [Language Understanding using LUIS][11]
- [TypeScript][2]
- [Restify][30]
- [dotenv][31]

[1]: https://dev.botframework.com
[2]: https://www.typescriptlang.org
[3]: https://www.typescriptlang.org/#download-links
[4]: https://nodejs.org
[5]: https://github.com/microsoft/botframework-emulator
[6]: https://github.com/Microsoft/BotFramework-Emulator/releases
[7]: https://docs.microsoft.com/en-us/cli/azure/?view=azure-cli-latest
[8]: https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest
[9]: https://github.com/Microsoft/botbuilder-tools/tree/master/packages/MSBot
[10]: https://portal.azure.com
[11]: https://www.luis.ai
[20]: https://docs.botframework.com
[21]: https://docs.microsoft.com/en-us/azure/bot-service/bot-service-overview-introduction?view=azure-bot-service-4.0
[22]: https://docs.microsoft.com/en-us/azure/bot-service/?view=azure-bot-service-4.0
[30]: https://www.npmjs.com/package/restify
[31]: https://www.npmjs.com/package/dotenv
[32]: https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-basics?view=azure-bot-service-4.0
[40]: https://aka.ms/azuredeployment
[41]: ./PREREQUISITES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"version": "1.0",
"resources": [
{
"type": "endpoint",
"id": "1",
"name": "development",
"url": "http://localhost:3978/api/messages"
},
{
"type": "abs",
"id": "3",
"name": "echobot-abs"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

// DO NOT MODIFY THIS CODE
// This script is run as part of the Post Deploy step when
// deploying the bot to Azure. It ensures the Azure Web App
// is configured correctly to host a TypeScript authored bot.
const fs = require('fs');
const path = require('path');
const replace = require('replace');
const WEB_CONFIG_FILE = './web.config';

if (fs.existsSync(path.resolve(WEB_CONFIG_FILE))) {
replace({
regex: "url=\"index.js\"",
replacement: "url=\"lib/index.js\"",
paths: ['./web.config'],
recursive: false,
silent: true,
})
}
35 changes: 35 additions & 0 deletions samples/javascript_typescript/30.activity-handler/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "echobot",
"version": "1.0.0",
"description": "Bot Builder v4 echo bot sample",
"author": "Microsoft",
"license": "MIT",
"main": "./lib/index.js",
"scripts": {
"build": "node_modules/.bin/tsc --build",
"lint": "node_modules/.bin/tslint -c tslint.json 'src/**/*.ts'",
"postinstall": "npm run build && node ./deploymentScripts/webConfigPrep.js",
"start": "node_modules/.bin/tsc --build && node ./lib/index.js",
"test": "echo \"Error: no test specified\" && exit 1",
"watch": "node_modules/.bin/nodemon --watch ./src -e ts --exec \"npm run start\""
},
"repository": {
"type": "git",
"url": "https://github.com"
},
"dependencies": {
"botbuilder": "^4.1.5",
"botbuilder-dialogs": "^4.2.1",
"botframework-config": "^4.1.5",
"dotenv": "^6.1.0",
"replace": "^1.0.0",
"restify": "^7.2.3"
},
"devDependencies": {
"@types/dotenv": "6.1.0",
"@types/restify": "7.2.6",
"nodemon": "^1.18.6",
"tslint": "^5.11.0",
"typescript": "^3.1.6"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
user=Vishwac
bot=EchoBot

user: Hi
bot: 1: You said "Hi"
user: Hello
bot: 2: You said "Hello"
15 changes: 15 additions & 0 deletions samples/javascript_typescript/30.activity-handler/sample.bot
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "echobot",
"services": [
{
"type": "endpoint",
"name": "development",
"endpoint": "http://localhost:3978/api/messages",
"appId": "",
"appPassword": "",
"id": "1"
}
],
"padlock": "",
"version": "2.0"
}
Loading