Skip to content

Commit

Permalink
Updated LKG build and package.json version.
Browse files Browse the repository at this point in the history
  • Loading branch information
Stevenic committed Feb 2, 2017
1 parent d795866 commit b59c28d
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 25 deletions.
10 changes: 10 additions & 0 deletions Node/core/lib/botbuilder.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,10 @@ export interface IUniversalBotSettings {

/** Implemented by connector plugins for the UniversalBot. */
export interface IConnector {

/** Used to register a handler for receiving incoming invoke events. */
onInvoke?(handler: (event: IEvent, cb?: (err: Error, body: any, status?: number) => void) => void): void;

/** Called by the UniversalBot at registration time to register a handler for receiving incoming events from a channel. */
onEvent(handler: (events: IEvent[], callback?: (err: Error) => void) => void): void;

Expand Down Expand Up @@ -3040,6 +3044,9 @@ export class ChatConnector implements IConnector, IBotStorage {
/** Registers an Express or Restify style hook to listen for new messages. */
listen(): (req: any, res: any) => void;

/** Used to register a handler for receiving incoming invoke events. */
onInvoke(handler: (event: IEvent, cb?: (err: Error, body: any, status?: number) => void) => void): void;

/** Called by the UniversalBot at registration time to register a handler for receiving incoming events from a channel. */
onEvent(handler: (events: IEvent[], callback?: (err: Error) => void) => void): void;

Expand All @@ -3064,6 +3071,9 @@ export class ConsoleConnector implements IConnector {
/** Sends a message through the connector. */
processMessage(line: string): ConsoleConnector;

/** Used to register a handler for receiving incoming invoke events. */
onInvoke(handler: (event: IEvent, cb?: (err: Error, body: any, status?: number) => void) => void): void;

/** Called by the UniversalBot at registration time to register a handler for receiving incoming events from a channel. */
onEvent(handler: (events: IEvent[], callback?: (err: Error) => void) => void): void;

Expand Down
46 changes: 32 additions & 14 deletions Node/core/lib/bots/ChatConnector.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ var ChatConnector = (function () {
}
};
ChatConnector.prototype.onEvent = function (handler) {
this.handler = handler;
this.onEventHandler = handler;
};
ChatConnector.prototype.onInvoke = function (handler) {
this.onInvokeHandler = handler;
};
ChatConnector.prototype.send = function (messages, done) {
var _this = this;
Expand Down Expand Up @@ -358,21 +361,36 @@ var ChatConnector = (function () {
}
}
};
ChatConnector.prototype.dispatch = function (messages, res) {
var _this = this;
var list = Array.isArray(messages) ? messages : [messages];
list.forEach(function (msg) {
try {
_this.prepIncomingMessage(msg);
logger.info(msg, 'ChatConnector: message received.');
_this.handler([msg]);
ChatConnector.prototype.dispatch = function (msg, res) {
try {
this.prepIncomingMessage(msg);
logger.info(msg, 'ChatConnector: message received.');
if (this.isInvoke(msg)) {
this.onInvokeHandler(msg, function (err, body, status) {
if (err) {
res.status(500);
res.end();
logger.error('Received error from invoke handler: ', err.message || '');
}
else {
res.send(status || 200, body);
}
});
}
catch (e) {
console.error(e instanceof Error ? e.stack : e.toString());
else {
this.onEventHandler([msg]);
res.status(202);
res.end();
}
});
res.status(202);
res.end();
}
catch (e) {
console.error(e instanceof Error ? e.stack : e.toString());
res.status(500);
res.end();
}
};
ChatConnector.prototype.isInvoke = function (message) {
return (message && message.type && message.type.toLowerCase() == consts.invokeType);
};
ChatConnector.prototype.postMessage = function (msg, cb) {
logger.info(address, 'ChatConnector: sending message.');
Expand Down
9 changes: 6 additions & 3 deletions Node/core/lib/bots/ConsoleConnector.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var ConsoleConnector = (function () {
return this;
};
ConsoleConnector.prototype.processMessage = function (line) {
if (this.handler) {
if (this.onEventHandler) {
var msg = new Message_1.Message()
.address({
channelId: 'console',
Expand All @@ -33,12 +33,15 @@ var ConsoleConnector = (function () {
})
.timestamp()
.text(line);
this.handler([msg.toMessage()]);
this.onEventHandler([msg.toMessage()]);
}
return this;
};
ConsoleConnector.prototype.onEvent = function (handler) {
this.handler = handler;
this.onEventHandler = handler;
};
ConsoleConnector.prototype.onInvoke = function (handler) {
this.onInvokeHandler = handler;
};
ConsoleConnector.prototype.send = function (messages, done) {
for (var i = 0; i < messages.length; i++) {
Expand Down
5 changes: 2 additions & 3 deletions Node/core/lib/bots/Library.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,11 @@ var Library = (function (_super) {
return this._localePath;
};
Library.prototype.recognize = function (context, callback) {
var skipRecognize = (context.intent && context.libraryName === this.name);
if (this.recognizers.length > 0 && !skipRecognize) {
if (this.recognizers.length > 0 && context.libraryName !== this.name) {
this.recognizers.recognize(context, callback);
}
else {
callback(null, context.intent);
callback(null, context.intent || { intent: 'None', score: 0.0 });
}
};
Library.prototype.recognizer = function (plugin) {
Expand Down
6 changes: 2 additions & 4 deletions Node/core/lib/bots/UniversalBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,8 @@ var UniversalBot = (function (_super) {
var _this = this;
var context = session.toRecognizeContext();
this.recognize(context, function (err, topIntent) {
if (topIntent && topIntent.score > 0) {
context.intent = topIntent;
context.libraryName = _this.name;
}
context.intent = topIntent;
context.libraryName = _this.name;
var results = Library_1.Library.addRouteResult({ score: 0.0, libraryName: _this.name });
async.each(_this.libraryList(), function (lib, cb) {
lib.findRoutes(context, function (err, routes) {
Expand Down
1 change: 1 addition & 0 deletions Node/core/lib/consts.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use strict";
exports.agent = 'botbuilder';
exports.messageType = 'message';
exports.invokeType = 'invoke';
exports.defaultConnector = '*';
exports.emulatorChannel = 'emulator';
exports.Errors = {
Expand Down
2 changes: 1 addition & 1 deletion Node/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "botbuilder",
"author": "Microsoft Corp.",
"description": "Bot Builder is a dialog system for building rich bots on virtually any platform.",
"version": "3.5.4",
"version": "3.6.0",
"license": "MIT",
"keywords": [
"botbuilder",
Expand Down

0 comments on commit b59c28d

Please sign in to comment.