Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pcostantini committed Apr 3, 2017
1 parent f0a6157 commit 881a030
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 17 deletions.
18 changes: 8 additions & 10 deletions Node/blog-LUISActionBinding/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,10 @@ var LuisModelUrl = process.env.LUIS_MODEL_URL;
var recognizer = new builder.LuisRecognizer(LuisModelUrl);
var intentDialog = bot.dialog('/', new builder.IntentDialog({ recognizers: [recognizer] })
.onDefault(function (session) {
session.endDialog(
'Sorry, I did not understand "%s". Use sentences like "What is the time in Miami?", "Search for 5 stars hotels in Barcelona", "Tell me the weather in Buenos Aires", "Location of SFO airport")',
session.message.text);
}));
session.endDialog(
'Sorry, I did not understand "%s". Use sentences like "What is the time in Miami?", "Search for 5 stars hotels in Barcelona", "Tell me the weather in Buenos Aires", "Location of SFO airport")',
session.message.text);
}));

// Import the Core stuff
var LuisActions = require('../../core');
Expand Down Expand Up @@ -340,13 +340,11 @@ The Bot sample has a [custom handler](samples/bot/app.js#L35-L67) that re-hydrat

In the [samples/web](samples/web) directory you can see how the Action samples are used within an Express web application.

> NOTE: Use `npm start` to run the sample from the `web` directory. The web application will launch by default at [http://localhost:3000](http://localhost:3000).
The most important parts are in the [main route](samples/web/routes/index.js) and its corresponding [view](samples/web/views/index.pug).

The first visit to the web page will display a simple query input. This is handled by the [`GET /`](samples/web/routes/index.js#L15) route and returns the `index` view with an empty query model.
The first visit to the web page will display a simple query input. This is handled by the [`GET /`](samples/web/routes/index.js#L14) route and returns the `index` view with an empty query model.

Once the user fills in a query like `How is the weather in Seattle`, the form will POST to the same address. The request is then handled by the [`POST /`](samples/web/routes/index.js#L19) route:
Once the user fills in a query like `How is the weather in Seattle`, the form will POST to the same address. The request is then handled by the [`POST /`](samples/web/routes/index.js#L18) route:

1. On the first POST, the handler will call the tryEvaluate function, which acts as a wrapper for the [`LuisAction.evaluate`](core/index.js#L35) low-level function. The `evaluate` function returns a Promise that resolves to an `actionModel`. This object has a `status` field (see possible values in [Status definition](core/index.js#L9-L12)) and the execution that follows depends on this value:

Expand All @@ -356,13 +354,13 @@ Once the user fills in a query like `How is the weather in Seattle`, the form wi

- `Status.MissingParameters`

An action was matched, but there are missing or invalid parameters. Proceed to display a form with input fields for each parameter. The input fields are built using the [`createFieldsViewModel`](samples/web/routes/index.js#L77-L87) helper function, along with the action (parameters) schema, the model parameter and its errors.
An action was matched, but there are missing or invalid parameters. Proceed to display a form with input fields for each parameter. The input fields are built using the [`createFieldsViewModel`](samples/web/routes/index.js#L76-L86) helper function, along with the action (parameters) schema, the model parameter and its errors.

- `Status.Fulfilled`

An action was matched, its parameters were validated and the action was fulfilled. The `actionModel` contains a `result` field with the action's result. Proceed to display the `fulfill` view that prints the result.

The sample provides a basic scaffolding for handling LUIS Action Bindings. It can be easily extended to provide custom views for specific Intent or Actions when returning the [validation errors](samples/web/routes/index.js#L41) or the [fulfillment view](samples/web/routes/index.js#L53).
The sample provides a basic scaffolding for handling LUIS Action Bindings. It can be easily extended to provide custom views for specific Intent or Actions when returning the [validation errors](samples/web/routes/index.js#L40) or the [fulfillment view](samples/web/routes/index.js#L52).

> NOTE: Contextual Actions, described in [Scenario #3](#scenario-3--trigger-a-contextual-action-with-no-previous-context-ie-from-scratch), are not supported on this Web application sample.
Expand Down
6 changes: 3 additions & 3 deletions Node/blog-LUISActionBinding/samples/bot/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ function onContextCreationHandler(action, actionModel, next, session) {

// NOTE: Remember to call next() to continue executing the action binding's logic

if(action.intentName === 'FindHotels') {
if(!actionModel.parameters.Checkin) {
if (action.intentName === 'FindHotels') {
if (!actionModel.parameters.Checkin) {
actionModel.parameters.Checkin = new Date();
}

if(!actionModel.parameters.Checkout) {
if (!actionModel.parameters.Checkout) {
actionModel.parameters.Checkout = new Date();
actionModel.parameters.Checkout.setDate(actionModel.parameters.Checkout.getDate() + 1);
}
Expand Down
3 changes: 0 additions & 3 deletions Node/blog-LUISActionBinding/samples/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
"description": "Bot Builder LUIS Action Binding - Web sample",
"author": "Microsoft Corp.",
"license": "MIT",
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"body-parser": "~1.16.0",
"cookie-parser": "~1.4.3",
Expand Down
1 change: 0 additions & 1 deletion Node/blog-LUISActionBinding/samples/web/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ var express = require('express');
var router = express.Router();
var _ = require('lodash');

var LuisRecognizer = require('botbuilder').LuisRecognizer;
var LuisActions = require('../../../core');

var ModelUrl = process.env.LUIS_MODEL_URL;
Expand Down

0 comments on commit 881a030

Please sign in to comment.