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

[Node-Samples] Update to botbuilder 3.5.1 #51

Merged
merged 25 commits into from
Jan 23, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b89f797
[Node-ReceiveAttachment] Update to botbuilder 3.5.1
pcostantini Jan 10, 2017
b4a92e2
[Node-SendAttachment] Update to botbuilder 3.5.1
pcostantini Jan 10, 2017
2e75ceb
[Node-CarouselCards] Update to botbuilder 3.5.1
pcostantini Jan 10, 2017
ebd2b5c
[Node-RichCards] Update to botbuilder 3.5.1
pcostantini Jan 10, 2017
68cbb60
[Node-State] Update to botbuilder 3.5.1
pcostantini Jan 10, 2017
e7f0182
[Node-MultiDialogs] Update to botbuilder 3.5.1
pcostantini Jan 10, 2017
28f8252
[Node-GetConversationMembers] Update to botbuilder 3.5.1
pcostantini Jan 10, 2017
0ef8a55
[Node-DirectLine] Update to botbuilder 3.5.1 and DirectLine 3.0
pcostantini Jan 10, 2017
178bb46
[Node-CreateNewConversation] Update to botbuilder 3.5.1
pcostantini Jan 10, 2017
dfac8f5
[Node-ChannelData] Update to botbuilder 3.5.1
pcostantini Jan 10, 2017
c3f9f2e
[Node-AppInsights] Update to botbuilder 3.5.1
pcostantini Jan 10, 2017
e27a151
[Node-AzureSearch] Update to botbuilder 3.5.1
pcostantini Jan 10, 2017
57927e4
[Node-SimilarProducts] Update to botbuilder 3.5.1
pcostantini Jan 10, 2017
aeb96b3
[Node-SpeechToText] Update to botbuilder 3.5.1
pcostantini Jan 10, 2017
c5cbc3a
[Node-LUIS] Update to botbuilder 3.5.1
pcostantini Jan 10, 2017
295400d
[Node-ImageCaption] Update to botbuilder 3.5.1
pcostantini Jan 10, 2017
13b7000
Fix typo in code comment
pcostantini Jan 10, 2017
74eb448
[Node] Update Emulator screenshots
pcostantini Jan 10, 2017
275b754
[Node-ContosoFlowers] Update to botbuilder 3.5.1 and add Localization…
pcostantini Jan 11, 2017
fa62d28
[Node] Updates for Microsoft Teams support
pcostantini Jan 12, 2017
6eeb67c
Add repository, bugs and keywords to package.json
pcostantini Jan 12, 2017
ee36c2b
[Node] RichCards - limitations of new Media Cards on channels
pcostantini Jan 12, 2017
5edcce6
Merge branch 'master' into node-samples-updates
pcostantini Jan 13, 2017
02a6c8b
[Node] Update remaining API Keys and azuredeploy.json templates
pcostantini Jan 13, 2017
51ed21e
[Node-SpeechToText] Do not consider video/mp4 as valid audio file
pcostantini Jan 16, 2017
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
Prev Previous commit
Next Next commit
[Node-LUIS] Update to botbuilder 3.5.1
- update to botbuilder 3.5.1
- other dependencies updated as well
- updated to LUIS v2 endpoint
  • Loading branch information
pcostantini committed Jan 10, 2017
commit c5cbc3aedbcd8723f69e5d65f8b5c4ccabb8aef6
5 changes: 4 additions & 1 deletion Node/intelligence-LUIS/.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
MICROSOFT_APP_ID=
MICROSOFT_APP_PASSWORD=

# This Url can be obtained by uploading or creating your model from the LUIS portal: https://www.luis.ai/
LUIS_MODEL_URL=https://api.projectoxford.ai/luis/v2.0/apps/162bf6ee-379b-4ce4-a519-5f5af90086b5?subscription-key=11be6373fca44ded80fbe2afa8597c18&verbose=true

# This is a free trial Microsoft Bing Spell Check key with limited QPS.
# Please subscribe to create your own key and try it out further.
# Subscription URL: https://www.microsoft.com/cognitive-services/en-us/subscriptions?productId=/products/56ec2df6dbe2d91324586008
BING_Spell_Check_API_KEY=da7b8d56645e4adba07fc26eee6c6d8a
BING_SPELL_CHECK_API_KEY=da7b8d56645e4adba07fc26eee6c6d8a

# Boolean value to enable correcting the text before processing it
IS_SPELL_CORRECTION_ENABLED=false
6 changes: 0 additions & 6 deletions Node/intelligence-LUIS/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@
"runtimeArgs": [
"--nolazy"
],
"env": {
"NODE_ENV": "development",
"MICROSOFT_APP_ID": "",
"MICROSOFT_APP_PASSWORD": "",
"LUIS_MODEL_URL": "https://api.projectoxford.ai/luis/v1/application?id=162bf6ee-379b-4ce4-a519-5f5af90086b5&subscription-key=11be6373fca44ded80fbe2afa8597c18"
},
"externalConsole": false,
"sourceMaps": false,
"outDir": null
Expand Down
1 change: 1 addition & 0 deletions Node/intelligence-LUIS/LuisBot.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
}
],
"composites": [],
"closedLists": [],
"bing_entities": [
"geography"
],
Expand Down
24 changes: 13 additions & 11 deletions Node/intelligence-LUIS/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ A sample bot using IntentDialog to integrate with a LUIS.ai application.

The minimum prerequisites to run this sample are:
* Latest Node.js with NPM. Download it from [here](https://nodejs.org/en/download/).
* The Bot Framework Emulator. To install the Bot Framework Emulator, download it from [here](https://aka.ms/bf-bc-emulator). Please refer to [this documentation article](https://docs.botframework.com/en-us/csharp/builder/sdkreference/gettingstarted.html#emulator) to know more about the Bot Framework Emulator.
* The Bot Framework Emulator. To install the Bot Framework Emulator, download it from [here](https://emulator.botframework.com/). Please refer to [this documentation article](https://github.com/microsoft/botframework-emulator/wiki/Getting-Started) to know more about the Bot Framework Emulator.
* **[Recommended]** Visual Studio Code for IntelliSense and debugging, download it from [here](https://code.visualstudio.com/) for free.

#### LUIS Application
Expand All @@ -22,7 +22,7 @@ In the case you choose to import the application, the first step to using LUIS i

Once you imported the application you'll need to "train" the model ([Training](https://www.luis.ai/Help#Training)) before you can "Publish" the model in an HTTP endpoint. For more information, take a look at [Publishing a Model](https://www.luis.ai/Help#PublishingModel).

Finally, edit [app.js](app.js#L21-L22) file and update the `LuisModelUrl` variable, or if you are using Visual Studio Code to run the sample edit [launch.json](.vscode/launch.json#L21) and update the `LUIS_MODEL_URL` environment variable.
Finally, edit the [.env](.env#L5) file and update the `LUIS_MODEL_URL` variable with your's Model URL.

#### Where to find the Model URL

Expand All @@ -36,19 +36,21 @@ One of the key problems in human-computer interactions is the ability of the com

The IntentDialog class lets you listen for the user to say a specific keyword or phrase. We call this intent detection because you are attempting to determine what the user is intending to do. IntentDialogs are useful for building more open ended bots that support natural language style understanding.

The IntentDialog class can be configured to use cloud based intent recognition services like [LUIS](http://luis.ai/) through an extensible set of recognizer plugins. Out of the box, Bot Builder comes with a [LuisRecognizer](https://docs.botframework.com/en-us/node/builder/chat-reference/classes/_botbuilder_d_.luisrecognizer) that can be used to call a machine learning model you have trained via their web site. You can create a LuisRecognizer that is pointed at your model and then pass that recognizer into your IntentDialog at creation time using the [options](https://docs.botframework.com/en-us/node/builder/chat-reference/interfaces/_botbuilder_d_.iintentdialogoptions) structure. Check out how [app.js initializes the IntentDialog](app.js#L21-L26):
The IntentDialog class can be configured to use cloud based intent recognition services like [LUIS](http://luis.ai/) through an extensible set of recognizer plugins. Out of the box, Bot Builder comes with a [LuisRecognizer](https://docs.botframework.com/en-us/node/builder/chat-reference/classes/_botbuilder_d_.luisrecognizer) that can be used to call a machine learning model you have trained via their web site. You can create a LuisRecognizer that is pointed at your model and then pass that recognizer into your IntentDialog at creation time using the [options](https://docs.botframework.com/en-us/node/builder/chat-reference/interfaces/_botbuilder_d_.iintentdialogoptions) structure. Check out how [app.js initializes the IntentDialog](app.js#L27-L29):

````JavaScript
const LuisModelUrl = 'https://api.projectoxford.ai/luis/v1/application?id=...&subscription-key=...';

// Main dialog with LUIS
var recognizer = new builder.LuisRecognizer(LuisModelUrl);
var intents = new builder.IntentDialog({ recognizers: [recognizer] });

bot.dialog('/', intents);
````

#### Intent Recognizers

Intent recognizers return matches as named intents. To match against an intent from a recognizer you pass the name of the intent you want to handle to [IntentDialog.matches()](https://docs.botframework.com/en-us/node/builder/chat-reference/classes/_botbuilder_d_.intentdialog#matches) as a string instead of a RegExp. This lets you mix in the matching of regular expressions alongside your cloud based recognition model. See how the bot matches the [`SearchHotels`](app.js#L27), [`ShowHotelsReviews`](app.js#L77) and [`Help`](app.js#L91) intents.
Intent recognizers return matches as named intents. To match against an intent from a recognizer you pass the name of the intent you want to handle to [IntentDialog.matches()](https://docs.botframework.com/en-us/node/builder/chat-reference/classes/_botbuilder_d_.intentdialog#matches) as a string instead of a RegExp. This lets you mix in the matching of regular expressions alongside your cloud based recognition model. See how the bot matches the [`SearchHotels`](app.js#L30), [`ShowHotelsReviews`](app.js#L80) and [`Help`](app.js#L94) intents.

````JavaScript
intents.matches('SearchHotels', [ ...waterfall dialog handler... ]);
Expand All @@ -60,7 +62,7 @@ intents.matches('Help', builder.DialogAction.send('Hi! Try asking me things like

LUIS can not only identify a users intention given an utterance, it can extract entities from their utterance as well. Any entities recognized in the users utterance will be passed to the intent handler via its [`args`](https://docs.botframework.com/en-us/node/builder/chat-reference/interfaces/_botbuilder_d_.iintentrecognizerresult) parameter.

Bot Builder includes an [`EntityRecognizer`](https://docs.botframework.com/en-us/node/builder/chat-reference/classes/_botbuilder_d_.entityrecognizer.html) class to simplify working with these entities. You can use [`EntityRecognizer.findEntity()`](https://docs.botframework.com/en-us/node/builder/chat-reference/classes/_botbuilder_d_.entityrecognizer.html#findentity) and [`EntityRecognizer.findAllEntities()`](https://docs.botframework.com/en-us/node/builder/chat-reference/classes/_botbuilder_d_.entityrecognizer.html#findallentities) to search for entities of a specific type by name. Check out how [city and airport entities are extracted](app.js#L32-L33).
Bot Builder includes an [`EntityRecognizer`](https://docs.botframework.com/en-us/node/builder/chat-reference/classes/_botbuilder_d_.entityrecognizer.html) class to simplify working with these entities. You can use [`EntityRecognizer.findEntity()`](https://docs.botframework.com/en-us/node/builder/chat-reference/classes/_botbuilder_d_.entityrecognizer.html#findentity) and [`EntityRecognizer.findAllEntities()`](https://docs.botframework.com/en-us/node/builder/chat-reference/classes/_botbuilder_d_.entityrecognizer.html#findallentities) to search for entities of a specific type by name. Check out how [city and airport entities are extracted](app.js#L34-L36).

````JavaScript
var cityEntity = builder.EntityRecognizer.findEntity(args.entities, 'builtin.geography.city');
Expand All @@ -79,7 +81,7 @@ Another LUIS Model Feature used is Phrase List Features, for instance, the model

In our sample, we are using a [waterfall dialog](https://docs.botframework.com/en-us/node/builder/chat/dialogs/#waterfall) for the hotel search. This is a common pattern that you'll likely use for most of your intent handlers. The way waterfalls work in Bot Builder is the very first step of the waterfall is called when a dialog (or in this case intent handler) is triggered. The step then does some work and continues execution of the waterfall by either calling another dialog (like a built-in prompt) or calling the optional `next()` function passed in. When a dialog is called in a step, any result returned from the dialog will be passed as input to the results parameter for the next step.

Our bot tries to check if an entity of city or airport type were [matched and forwards it](app.js#L31-L45) to the next step. If that's not the case, the user is [prompted with a destination](app.js#L44). The [next step](app.js#L47-L49) will receive the destination or airport code in the `results` argument.
Our bot tries to check if an entity of city or airport type were [matched and forwards it](app.js#L37-L44) to the next step. If that's not the case, the user is [prompted with a destination](app.js#L47). The [next step](app.js#L50) will receive the destination or airport code in the `results` argument.

````JavaScript
intents.matches('SearchHotels', [
Expand Down Expand Up @@ -119,7 +121,7 @@ intents.matches('SearchHotels', [
}]);
````

Similarly, the [`ShowHotelsReviews`](app.js#L77) uses a single closure to search for hotel reviews.
Similarly, the [`ShowHotelsReviews`](app.js#L80) uses a single closure to search for hotel reviews.

````
intents.matches('ShowHotelsReviews', (session, args) => {
Expand All @@ -132,7 +134,7 @@ intents.matches('ShowHotelsReviews', (session, args) => {
var message = new builder.Message()
.attachmentLayout(builder.AttachmentLayout.carousel)
.attachments(reviews.map(reviewAsAttachment));
session.send(message)
session.send(message);
});
}
});
Expand All @@ -150,16 +152,16 @@ intents.onDefault((session) => {

### Spelling Correction

IF you want to enable spelling correction, set the `IS_SPELL_CORRECTION_ENABLED` key to `true` in the [.env](.env) file.
If you want to enable spelling correction, set the `IS_SPELL_CORRECTION_ENABLED` key to `true` in the [.env](.env) file.

Microsoft Bing Spell Check API provides a module that allows you to to correct the spelling of the text. Check out the [reference](https://dev.cognitive.microsoft.com/docs/services/56e73033cf5ff80c2008c679/operations/56e73036cf5ff81048ee6727) to know more about the modules available.

[spell-service.js](spell-service.js) is the core component illustrating how to call the Bing Spell Check RESTful API.

In this sample we added spell correction as a middleware. Check out the middleware in [app.js](app.js).
In this sample we added spell correction as a middleware. Check out the middleware in [app.js](app.js#L99-L114).

````JavaScript
if (process.env.IS_SPELL_CORRECTION_ENABLED == "true") {
if (process.env.IS_SPELL_CORRECTION_ENABLED === "true") {
bot.use({
botbuilder: function (session, next) {
spellService
Expand Down
19 changes: 8 additions & 11 deletions Node/intelligence-LUIS/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ server.post('/api/messages', connector.listen());

// You can provide your own model by specifing the 'LUIS_MODEL_URL' environment variable
// This Url can be obtained by uploading or creating your model from the LUIS portal: https://www.luis.ai/
const LuisModelUrl = process.env.LUIS_MODEL_URL ||
'https://api.projectoxford.ai/luis/v1/application?id=162bf6ee-379b-4ce4-a519-5f5af90086b5&subscription-key=11be6373fca44ded80fbe2afa8597c18';
const LuisModelUrl = process.env.LUIS_MODEL_URL;

// Main dialog with LUIS
var recognizer = new builder.LuisRecognizer(LuisModelUrl);
var intents = new builder.IntentDialog({ recognizers: [recognizer] })
bot.dialog('/', new builder.IntentDialog({ recognizers: [recognizer] })
.matches('SearchHotels', [
function (session, args, next) {
session.send('Welcome to the Hotels finder! we are analyzing your message: \'%s\'', session.message.text);
session.send('Welcome to the Hotels finder! We are analyzing your message: \'%s\'', session.message.text);

// try extracting entities
var cityEntity = builder.EntityRecognizer.findEntity(args.entities, 'builtin.geography.city');
Expand Down Expand Up @@ -88,16 +87,16 @@ var intents = new builder.IntentDialog({ recognizers: [recognizer] })
var message = new builder.Message()
.attachmentLayout(builder.AttachmentLayout.carousel)
.attachments(reviews.map(reviewAsAttachment));
session.send(message)
session.send(message);
});
}
})
.matches('Help', builder.DialogAction.send('Hi! Try asking me things like \'search hotels in Seattle\', \'search hotels near LAX airport\' or \'show me the reviews of The Bot Resort\''))
.onDefault((session) => {
session.send('Sorry, I did not understand \'%s\'. Type \'help\' if you need assistance.', session.message.text);
});
}));

if (process.env.IS_SPELL_CORRECTION_ENABLED == "true") {
if (process.env.IS_SPELL_CORRECTION_ENABLED === 'true') {
bot.use({
botbuilder: function (session, next) {
spellService
Expand All @@ -111,11 +110,9 @@ if (process.env.IS_SPELL_CORRECTION_ENABLED == "true") {
next();
});
}
})
});
}

bot.dialog('/', intents);

// Helpers
function hotelAsAttachment(hotel) {
return new builder.HeroCard()
Expand All @@ -134,5 +131,5 @@ function reviewAsAttachment(review) {
return new builder.ThumbnailCard()
.title(review.title)
.text(review.text)
.images([new builder.CardImage().url(review.image)])
.images([new builder.CardImage().url(review.image)]);
}
Binary file modified Node/intelligence-LUIS/images/prereqs-publish.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions Node/intelligence-LUIS/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
"author": "",
"license": "MIT",
"dependencies": {
"bluebird": "^3.4.1",
"botbuilder": "^3.2.3",
"dotenv-extended": "^1.0.3",
"request": "^2.75.0",
"restify": "^4.1.1"
"bluebird": "^3.4.7",
"botbuilder": "^3.5.1",
"dotenv-extended": "^1.0.4",
"request": "^2.79.0",
"restify": "^4.3.0"
}
}
6 changes: 3 additions & 3 deletions Node/intelligence-LUIS/spell-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// https://dev.cognitive.microsoft.com/docs/services/56e73033cf5ff80c2008c679/operations/56e73036cf5ff81048ee6727
const request = require('request');

const SPELL_CHECK_API_URL = "https://api.cognitive.microsoft.com/bing/v5.0/spellcheck/?form=BCSSCK",
SPELL_CHECK_API_KEY = process.env.BING_Spell_Check_API_KEY;
const SPELL_CHECK_API_URL = 'https://api.cognitive.microsoft.com/bing/v5.0/spellcheck/?form=BCSSCK',
SPELL_CHECK_API_KEY = process.env.BING_SPELL_CHECK_API_KEY;

/**
* Gets the correct spelling for the given text
Expand Down Expand Up @@ -35,7 +35,7 @@ exports.getCorrectedText = text => {
}
else {
var previousOffset = 0;
var result = "";
var result = '';

for (var i = 0; i < body.flaggedTokens.length; i++) {
var element = body.flaggedTokens[i];
Expand Down