Skip to content

Commit 45ad121

Browse files
committed
Updated LKG build and package.json version
1 parent c712691 commit 45ad121

12 files changed

+567
-109
lines changed

Node/lib/Channel.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
function maxButtons(session) {
2-
var account = session.message.from || session.message.to;
3-
switch (account.channelId.toLowerCase()) {
1+
function preferButtons(session, choiceCnt, rePrompt) {
2+
switch (getChannelId(session)) {
43
case 'facebook':
5-
return 3;
4+
return (choiceCnt <= 3);
65
case 'telegram':
6+
return !rePrompt;
77
case 'kik':
8-
return 100;
8+
return true;
99
default:
10-
return 0;
10+
return false;
1111
}
1212
}
13-
exports.maxButtons = maxButtons;
13+
exports.preferButtons = preferButtons;
14+
function getChannelId(session) {
15+
var account = session.message.from || session.message.to;
16+
return account.channelId.toLowerCase();
17+
}
18+
exports.getChannelId = getChannelId;

Node/lib/Message.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,13 @@ var Message = (function () {
4747
return this;
4848
};
4949
Message.randomPrompt = function (prompts) {
50-
var i = Math.floor(Math.random() * prompts.length);
51-
return prompts[i];
50+
if (Array.isArray(prompts)) {
51+
var i = Math.floor(Math.random() * prompts.length);
52+
return prompts[i];
53+
}
54+
else {
55+
return prompts;
56+
}
5257
};
5358
Message.composePrompt = function (ses, prompts, args) {
5459
var connector = '';

Node/lib/Session.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var __extends = (this && this.__extends) || function (d, b) {
66
var dialog = require('./dialogs/Dialog');
77
var sprintf = require('sprintf-js');
88
var events = require('events');
9+
var utils = require('./utils');
910
var Session = (function (_super) {
1011
__extends(Session, _super);
1112
function Session(options) {
@@ -137,7 +138,7 @@ var Session = (function (_super) {
137138
if (typeof result === 'string') {
138139
m = this.createMessage(result, args);
139140
}
140-
else if (result.hasOwnProperty('text') || result.hasOwnProperty('channelData')) {
141+
else if (result.hasOwnProperty('text') || result.hasOwnProperty('attachments') || result.hasOwnProperty('channelData')) {
141142
m = result;
142143
}
143144
else {
@@ -243,7 +244,7 @@ var Session = (function (_super) {
243244
setTimeout(function () {
244245
var entry = _this.sendQueue.shift();
245246
_this.lastSendTime = now = new Date().getTime();
246-
_this.emit(entry.event, entry.msg);
247+
_this.emit(entry.event, utils.clone(entry.msg));
247248
if (_this.sendQueue.length > 0) {
248249
delaySend();
249250
}
@@ -253,7 +254,7 @@ var Session = (function (_super) {
253254
this.msgSent = true;
254255
if ((now - this.lastSendTime) >= this.options.minSendDelay) {
255256
this.lastSendTime = now;
256-
this.emit(event, message);
257+
this.emit(event, utils.clone(message));
257258
}
258259
else {
259260
this.sendQueue.push({ event: event, msg: message });

Node/lib/botbuilder.d.ts

Lines changed: 113 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,37 @@ export interface IPromptsOptions {
417417
defaultRetryPrompt?: string;
418418
}
419419

420+
/** Context information passed to field related handlers. */
421+
export interface IFieldConext {
422+
userData: any;
423+
form: any;
424+
field: string;
425+
}
426+
427+
/**
428+
* Handler that gets called anytime a field is about to invoke a prompt.
429+
*/
430+
export interface IFieldPromptHandler {
431+
/**
432+
* @param context Contextual information related to the current field.
433+
* @param next Function to call to continue execution of the prompt.
434+
* Passing _true_ for __skip__ will cause the current field to be skipped.
435+
*/
436+
(context: IFieldConext, next: (skip: boolean) => void): void;
437+
}
438+
439+
/** Options passed to form fields. */
440+
export interface IFieldOptions extends IPromptOptions {
441+
/**
442+
* Called anytime a given field is about to invoke the prompt. This function lets the
443+
* developer progromatically determine if a prompt should be skipped or not.
444+
*
445+
* The handler can also manipulate the forms current values. For instance a fields value
446+
* could be pulled from context.userData if not already specified on the form.
447+
*/
448+
onPrompt?: IFieldPromptHandler;
449+
}
450+
420451
/** A recognized intent. */
421452
export interface IIntent {
422453
/** Intent that was recognized. */
@@ -1318,7 +1349,7 @@ export class Prompts extends Dialog {
13181349
* * __prompt:__ _{string}_ - Initial message to send the user.
13191350
* * __prompt:__ _{string[]}_ - Array of possible messages to send user. One will be chosen at random.
13201351
* * __prompt:__ _{IMessage}_ - Initial message to send the user. Message can contain attachments.
1321-
* @param options Optional flags parameters to control the behaviour of the prompt.
1352+
* @param options Optional parameters to control the behaviour of the prompt.
13221353
*/
13231354
static number(session: Session, prompt: string|string[]|IMessage, options?: IPromptOptions): void;
13241355

@@ -1329,7 +1360,7 @@ export class Prompts extends Dialog {
13291360
* * __prompt:__ _{string}_ - Initial message to send the user.
13301361
* * __prompt:__ _{string[]}_ - Array of possible messages to send user. One will be chosen at random.
13311362
* * __prompt:__ _{IMessage}_ - Initial message to send the user. Message can contain attachments.
1332-
* @param options Optional flags parameters to control the behaviour of the prompt.
1363+
* @param options Optional parameters to control the behaviour of the prompt.
13331364
*/
13341365
static confirm(session: Session, prompt: string|string[]|IMessage, options?: IPromptOptions): void;
13351366

@@ -1344,7 +1375,7 @@ export class Prompts extends Dialog {
13441375
* * __choices:__ _{string}_ - List of choices as a pipe ('|') delimted string.
13451376
* * __choices:__ _{Object}_ - List of choices expressed as an Object map. The objects field names will be used to build the list of values.
13461377
* * __choices:__ _{string[]}_ - List of choices as an array of strings.
1347-
* @param options Optional flags parameters to control the behaviour of the prompt.
1378+
* @param options Optional parameters to control the behaviour of the prompt.
13481379
*/
13491380
static choice(session: Session, prompt: string|string[]|IMessage, choices: string|Object|string[], options?: IPromptOptions): void;
13501381

@@ -1355,11 +1386,89 @@ export class Prompts extends Dialog {
13551386
* * __prompt:__ _{string}_ - Initial message to send the user.
13561387
* * __prompt:__ _{string[]}_ - Array of possible messages to send user. One will be chosen at random.
13571388
* * __prompt:__ _{IMessage}_ - Initial message to send the user. Message can contain attachments.
1358-
* @param options Optional flags parameters to control the behaviour of the prompt.
1389+
* @param options Optional parameters to control the behaviour of the prompt.
13591390
*/
13601391
static time(session: Session, prompt: string|string[]|IMessage, options?: IPromptOptions): void;
13611392
}
13621393

1394+
/**
1395+
*
1396+
*/
1397+
export class Fields {
1398+
/**
1399+
* Captures from the user a raw string of text and saves it to a field on a form.
1400+
* @param field Name of the field to save the users response to.
1401+
* @param prompt
1402+
* * __prompt:__ _{string}_ - Initial message to send the user.
1403+
* * __prompt:__ _{string[]}_ - Array of possible messages to send user. One will be chosen at random.
1404+
* @param options Optional parameters to control the behaviour of the field.
1405+
*/
1406+
static text(field: string, prompt: string|string[], options?: IFieldOptions): IDialogWaterfallStep;
1407+
1408+
/**
1409+
* Prompts the user to enter a number and saves it to a field on a form.
1410+
* @param field Name of the field to save the users response to.
1411+
* @param prompt
1412+
* * __prompt:__ _{string}_ - Initial message to send the user.
1413+
* * __prompt:__ _{string[]}_ - Array of possible messages to send user. One will be chosen at random.
1414+
* @param options Optional parameters to control the behaviour of the field.
1415+
*/
1416+
static number(field: string, prompt: string|string[], options?: IFieldOptions): IDialogWaterfallStep;
1417+
1418+
/**
1419+
* Prompts the user to enter a boolean yes/no response and saves their answer to a field on a form.
1420+
* @param field Name of the field to save the users response to.
1421+
* @param prompt
1422+
* * __prompt:__ _{string}_ - Initial message to send the user.
1423+
* * __prompt:__ _{string[]}_ - Array of possible messages to send user. One will be chosen at random.
1424+
* @param options Optional parameters to control the behaviour of the field.
1425+
*/
1426+
static confirm(field: string, prompt: string|string[], options?: IFieldOptions): IDialogWaterfallStep;
1427+
1428+
/**
1429+
* Prompts the user to choose from a list of options and saves their selection to a field on a form.
1430+
* @param field Name of the field to save the users response to.
1431+
* @param prompt
1432+
* * __prompt:__ _{string}_ - Initial message to send the user.
1433+
* * __prompt:__ _{string[]}_ - Array of possible messages to send user. One will be chosen at random.
1434+
* @param choices
1435+
* * __choices:__ _{string}_ - List of choices as a pipe ('|') delimted string.
1436+
* * __choices:__ _{Object}_ - List of choices expressed as an Object map. The objects field names will be used to build the list of values.
1437+
* * __choices:__ _{string[]}_ - List of choices as an array of strings.
1438+
* @param options Optional parameters to control the behaviour of the field.
1439+
*/
1440+
static choice(field: string, prompt: string|string[], choices: string|Object|string[], options?: IFieldOptions): IDialogWaterfallStep;
1441+
1442+
/**
1443+
* Prompts the user to enter a time saves it to a field on a form as a timestamp.
1444+
* @param field Name of the field to save the users response to.
1445+
* @param prompt
1446+
* * __prompt:__ _{string}_ - Initial message to send the user.
1447+
* * __prompt:__ _{string[]}_ - Array of possible messages to send user. One will be chosen at random.
1448+
* @param options Optional parameters to control the behaviour of the field.
1449+
*/
1450+
static time(field: string, prompt: string|string[], options?: IPromptOptions): IDialogWaterfallStep;
1451+
1452+
/**
1453+
* Finalizes the form by saving the response from the last prompt and then passes the completed
1454+
* form to the next step of the waterfall for processing.
1455+
*/
1456+
static endForm(): IDialogWaterfallStep;
1457+
1458+
/**
1459+
* Finalizes the form by saving the response from the last prompt and then returns the completed
1460+
* form to the parent dialog by calling [endDialog()](http://docs.botframework.com/sdkreference/nodejs/classes/_botbuilder_d_.session.html#enddialog).
1461+
*/
1462+
static returnForm(): IDialogWaterfallStep;
1463+
1464+
/**
1465+
* Handler for IFieldOptions.onPrompt that will copy a default value from Session.userData if
1466+
* a field is empty. The default value must be in a property with the same name as the field.
1467+
* If successfully copied the prompt will be skipped.
1468+
*/
1469+
static onPromptUseDefault(): IFieldPromptHandler
1470+
}
1471+
13631472
/**
13641473
* Implements a simple pattern based recognizer for parsing the built-in prompts. Derived classes can
13651474
* inherit from SimplePromptRecognizer and override the recognize() method to change the recognition

Node/lib/bots/BotConnectorBot.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var BotConnectorBot = (function (_super) {
1313
function BotConnectorBot(options) {
1414
_super.call(this);
1515
this.options = {
16-
endpoint: process.env['endpoint'] || 'https://api.botframework.com',
16+
endpoint: process.env['endpoint'],
1717
appId: process.env['appId'] || '',
1818
appSecret: process.env['appSecret'] || '',
1919
defaultDialogId: '/',
@@ -148,14 +148,12 @@ var BotConnectorBot = (function (_super) {
148148
};
149149
data.perUserConversationData[consts.Data.SessionState] = ses.sessionState;
150150
_this.saveData(userId, sessionId, data, reply, function (err) {
151+
var endpoint;
151152
if (ses.message.to.channelId == 'emulator') {
152-
if (_this.options.endpoint) {
153-
var settings = _this.options;
154-
} else {
155-
var settings = { endpoint: 'http://localhost:9000' };
156-
}
157-
} else {
158-
var settings = _this.options;
153+
endpoint = _this.options.endpoint || 'http://localhost:9000';
154+
}
155+
else {
156+
endpoint = _this.options.endpoint || 'https://api.botframework.com';
159157
}
160158
if (res) {
161159
_this.emit('reply', reply);
@@ -172,7 +170,7 @@ var BotConnectorBot = (function (_super) {
172170
reply.participants = ses.message.participants;
173171
reply.totalParticipants = ses.message.totalParticipants;
174172
_this.emit('reply', reply);
175-
post(settings, '/bot/v1.0/messages', reply, function (err) {
173+
post(_this.options, endpoint, '/bot/v1.0/messages', reply, function (err) {
176174
if (err) {
177175
_this.emit('error', err);
178176
}
@@ -182,7 +180,7 @@ var BotConnectorBot = (function (_super) {
182180
reply.from = ses.message.from;
183181
reply.to = ses.message.to;
184182
_this.emit('send', reply);
185-
post(settings, '/bot/v1.0/messages', reply, function (err) {
183+
post(_this.options, endpoint, '/bot/v1.0/messages', reply, function (err) {
186184
if (err) {
187185
_this.emit('error', err);
188186
}
@@ -319,10 +317,10 @@ var BotConnectorSession = (function (_super) {
319317
return BotConnectorSession;
320318
})(session.Session);
321319
exports.BotConnectorSession = BotConnectorSession;
322-
function post(settings, path, body, callback) {
320+
function post(settings, endpoint, path, body, callback) {
323321
var options = {
324322
method: 'POST',
325-
url: settings.endpoint + path,
323+
url: endpoint + path,
326324
body: body,
327325
json: true
328326
};

Node/lib/consts.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ exports.Data = {
44
Handler: 'BotBuilder.Data.Handler',
55
Group: 'BotBuilder.Data.Group',
66
Intent: 'BotBuilder.Data.Intent',
7-
WaterfallStep: 'BotBuilder.Data.WaterfallStep'
7+
WaterfallStep: 'BotBuilder.Data.WaterfallStep',
8+
Form: 'BotBuilder.Data.Form',
9+
Field: 'BotBuilder.Data.Field'
810
};
911
exports.DialogId = {
10-
Prompts: 'BotBuilder.Dialogs.Prompts'
12+
Prompts: 'BotBuilder.Dialogs.Prompts',
13+
Field: 'BotBuilder.Dialogs.Field'
1114
};
1215
exports.Id = {
1316
DefaultGroup: 'BotBuilder.Id.DefaultGroup'

Node/lib/dialogs/DialogAction.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var session = require('../Session');
1+
var ses = require('../Session');
22
var consts = require('../consts');
33
var utils = require('../utils');
44
var dialog = require('./Dialog');
@@ -12,7 +12,7 @@ var DialogAction = (function () {
1212
}
1313
args.splice(0, 0, msg);
1414
return function sendAction(s) {
15-
session.Session.prototype.send.apply(s, args);
15+
ses.Session.prototype.send.apply(s, args);
1616
};
1717
};
1818
DialogAction.beginDialog = function (id, args) {

Node/lib/dialogs/DialogCollection.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@ var __extends = (this && this.__extends) || function (d, b) {
66
var actions = require('./DialogAction');
77
var simpleDialog = require('./SimpleDialog');
88
var events = require('events');
9-
var prompts = require('./Prompts');
10-
var consts = require('../consts');
9+
exports.systemDialogs = {};
1110
var DialogCollection = (function (_super) {
1211
__extends(DialogCollection, _super);
1312
function DialogCollection() {
1413
_super.call(this);
1514
this.middleware = [];
1615
this.dialogs = {};
17-
this.add(consts.DialogId.Prompts, new prompts.Prompts());
16+
this.add(exports.systemDialogs);
1817
}
1918
DialogCollection.prototype.add = function (id, dialog) {
2019
var dialogs;

Node/lib/dialogs/EntityRecognizer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ var EntityRecognizer = (function () {
194194
}
195195
};
196196
EntityRecognizer.dateExp = /^\d{4}-\d{2}-\d{2}/i;
197-
EntityRecognizer.yesExp = /^(1|y|yes|yep|sure|ok|true)/i;
198-
EntityRecognizer.noExp = /^(0|n|no|nope|not|false)/i;
197+
EntityRecognizer.yesExp = /^(y|yes|yep|sure|ok|true)/i;
198+
EntityRecognizer.noExp = /^(n|no|nope|not|false)/i;
199199
EntityRecognizer.numberExp = /[+-]?(?:\d+\.?\d*|\d*\.?\d+)/;
200200
return EntityRecognizer;
201201
})();

0 commit comments

Comments
 (0)