botbuilder
Advanced tools
Comparing version 0.8.0 to 0.9.0
@@ -66,8 +66,7 @@ var __extends = (this && this.__extends) || function (d, b) { | ||
}; | ||
BotConnectorBot.prototype.listen = function (options) { | ||
BotConnectorBot.prototype.listen = function (dialogId, dialogArgs) { | ||
var _this = this; | ||
this.configure(options); | ||
return function (req, res) { | ||
if (req.body) { | ||
_this.dispatchMessage(null, req.body, _this.options.defaultDialogId, _this.options.defaultDialogArgs, res); | ||
_this.dispatchMessage(null, req.body, { dialogId: dialogId, dialogArgs: dialogArgs }, res); | ||
} | ||
@@ -82,3 +81,3 @@ else { | ||
var msg = JSON.parse(requestData); | ||
_this.dispatchMessage(null, msg, _this.options.defaultDialogId, _this.options.defaultDialogArgs, res); | ||
_this.dispatchMessage(null, msg, { dialogId: dialogId, dialogArgs: dialogArgs }, res); | ||
} | ||
@@ -94,8 +93,8 @@ catch (e) { | ||
BotConnectorBot.prototype.beginDialog = function (address, dialogId, dialogArgs) { | ||
var msg = address; | ||
msg.type = 'Message'; | ||
if (!msg.from) { | ||
msg.from = this.options.defaultFrom; | ||
var message = address; | ||
message.type = 'Message'; | ||
if (!message.from) { | ||
message.from = this.options.defaultFrom; | ||
} | ||
if (!msg.to || !msg.from) { | ||
if (!message.to || !message.from) { | ||
throw new Error('Invalid address passed to BotConnectorBot.beginDialog().'); | ||
@@ -106,5 +105,5 @@ } | ||
} | ||
this.dispatchMessage(msg.to.id, msg, dialogId, dialogArgs); | ||
this.dispatchMessage(message.to.id, message, { dialogId: dialogId, dialogArgs: dialogArgs }); | ||
}; | ||
BotConnectorBot.prototype.dispatchMessage = function (userId, message, dialogId, dialogArgs, res) { | ||
BotConnectorBot.prototype.dispatchMessage = function (userId, message, options, res) { | ||
var _this = this; | ||
@@ -140,4 +139,4 @@ try { | ||
dialogs: this, | ||
dialogId: dialogId, | ||
dialogArgs: dialogArgs | ||
dialogId: options.dialogId || this.options.defaultDialogId, | ||
dialogArgs: options.dialogArgs || this.options.defaultDialogArgs | ||
}); | ||
@@ -209,3 +208,10 @@ ses.on('send', function (reply) { | ||
} | ||
ses.dispatch(sessionState, message); | ||
if (options.replyToDialogId) { | ||
if (sessionState && sessionState.callstack[sessionState.callstack.length - 1].id == options.replyToDialogId) { | ||
ses.dispatch(sessionState, message); | ||
} | ||
} | ||
else { | ||
ses.dispatch(sessionState, message); | ||
} | ||
} | ||
@@ -212,0 +218,0 @@ else { |
@@ -21,3 +21,3 @@ var __extends = (this && this.__extends) || function (d, b) { | ||
ambientMentionDuration: 300000, | ||
minSendDelay: 2000, | ||
minSendDelay: 1500, | ||
sendIsTyping: true | ||
@@ -24,0 +24,0 @@ }; |
@@ -10,3 +10,3 @@ var __extends = (this && this.__extends) || function (d, b) { | ||
var prompts = require('./Prompts'); | ||
var consts = require('../Consts'); | ||
var consts = require('../consts'); | ||
var DialogCollection = (function (_super) { | ||
@@ -13,0 +13,0 @@ __extends(DialogCollection, _super); |
@@ -122,3 +122,3 @@ var utils = require('../utils'); | ||
} | ||
return undefined; | ||
return Number.NaN; | ||
}; | ||
@@ -125,0 +125,0 @@ EntityRecognizer.parseBoolean = function (utterance) { |
@@ -141,5 +141,6 @@ var __extends = (this && this.__extends) || function (d, b) { | ||
if (!match) { | ||
topIntent = { intent: consts.Intents.Default, score: 1.0 }; | ||
match = { | ||
groupId: consts.Id.DefaultGroup, | ||
handler: this.getDefaultGroup()._intentHandler(consts.Intents.Default) | ||
handler: this.getDefaultGroup()._intentHandler(topIntent.intent) | ||
}; | ||
@@ -162,10 +163,12 @@ } | ||
var topIntent; | ||
for (var i = 0; i < intents.length; i++) { | ||
var intent = intents[i]; | ||
if (!topIntent) { | ||
topIntent = intent; | ||
if (intents) { | ||
for (var i = 0; i < intents.length; i++) { | ||
var intent = intents[i]; | ||
if (!topIntent) { | ||
topIntent = intent; | ||
} | ||
else if (intent.score > topIntent.score) { | ||
topIntent = intent; | ||
} | ||
} | ||
else if (intent.score > topIntent.score) { | ||
topIntent = intent; | ||
} | ||
} | ||
@@ -172,0 +175,0 @@ return topIntent; |
@@ -24,2 +24,3 @@ var __extends = (this && this.__extends) || function (d, b) { | ||
request.get(uri, function (err, res, body) { | ||
var calledCallback = false; | ||
try { | ||
@@ -31,5 +32,7 @@ if (!err) { | ||
} | ||
calledCallback = true; | ||
callback(null, result.intents, result.entities); | ||
} | ||
else { | ||
calledCallback = true; | ||
callback(err); | ||
@@ -39,3 +42,8 @@ } | ||
catch (e) { | ||
callback(e); | ||
if (!calledCallback) { | ||
callback(e); | ||
} | ||
else { | ||
console.error(e.toString()); | ||
} | ||
} | ||
@@ -42,0 +50,0 @@ }); |
var session = require('./Session'); | ||
var sprintf = require('sprintf-js'); | ||
var Message = (function () { | ||
@@ -10,3 +11,3 @@ function Message() { | ||
}; | ||
Message.prototype.setText = function (ses, msg) { | ||
Message.prototype.setText = function (ses, prompts) { | ||
var args = []; | ||
@@ -17,2 +18,3 @@ for (var _i = 2; _i < arguments.length; _i++) { | ||
var m = this; | ||
var msg = typeof prompts == 'string' ? msg : Message.randomPrompt(prompts); | ||
args.unshift(msg); | ||
@@ -27,2 +29,11 @@ m.text = session.Session.prototype.gettext.apply(ses, args); | ||
}; | ||
Message.prototype.composePrompt = function (ses, prompts) { | ||
var args = []; | ||
for (var _i = 2; _i < arguments.length; _i++) { | ||
args[_i - 2] = arguments[_i]; | ||
} | ||
var m = this; | ||
m.text = Message.composePrompt(ses, prompts, args); | ||
return this; | ||
}; | ||
Message.prototype.addAttachment = function (attachment) { | ||
@@ -41,4 +52,17 @@ var m = this; | ||
}; | ||
Message.randomPrompt = function (prompts) { | ||
var i = Math.round(Math.random() * prompts.length); | ||
return prompts[i]; | ||
}; | ||
Message.composePrompt = function (ses, prompts, args) { | ||
var connector = ''; | ||
var prompt = ''; | ||
for (var i = 0; i < prompts.length; i++) { | ||
prompt += connector + ses.gettext(Message.randomPrompt(prompts[1])); | ||
connector = ' '; | ||
} | ||
return args && args.length > 0 ? sprintf.vsprintf(prompt, args) : prompt; | ||
}; | ||
return Message; | ||
})(); | ||
exports.Message = Message; |
@@ -11,5 +11,5 @@ var __extends = (this && this.__extends) || function (d, b) { | ||
__extends(Session, _super); | ||
function Session(args) { | ||
function Session(options) { | ||
_super.call(this); | ||
this.args = args; | ||
this.options = options; | ||
this.msgSent = false; | ||
@@ -19,5 +19,5 @@ this._isReset = false; | ||
this.sendQueue = []; | ||
this.dialogs = args.dialogs; | ||
if (typeof this.args.minSendDelay !== 'number') { | ||
this.args.minSendDelay = 1000; | ||
this.dialogs = options.dialogs; | ||
if (typeof this.options.minSendDelay !== 'number') { | ||
this.options.minSendDelay = 1000; | ||
} | ||
@@ -65,4 +65,4 @@ } | ||
var tmpl; | ||
if (this.args.localizer && this.message) { | ||
tmpl = this.args.localizer.ngettext(this.message.language || '', msgid, msgid_plural, count); | ||
if (this.options.localizer && this.message) { | ||
tmpl = this.options.localizer.ngettext(this.message.language || '', msgid, msgid_plural, count); | ||
} | ||
@@ -133,2 +133,6 @@ else if (count == 1) { | ||
var ss = this.sessionState; | ||
if (!ss || !ss.callstack || ss.callstack.length == 0) { | ||
console.error('ERROR: Too many calls to session.endDialog().'); | ||
return this; | ||
} | ||
var m; | ||
@@ -179,2 +183,6 @@ var r = {}; | ||
this.sessionState.callstack = []; | ||
if (!dialogId) { | ||
dialogId = this.options.dialogId; | ||
dialogArgs = dialogArgs || this.options.dialogArgs; | ||
} | ||
this.beginDialog(dialogId, dialogArgs); | ||
@@ -199,3 +207,3 @@ return this; | ||
if (ss.callstack.length == 0) { | ||
this.beginDialog(this.args.dialogId, this.args.dialogArgs); | ||
this.beginDialog(this.options.dialogId, this.options.dialogArgs); | ||
} | ||
@@ -210,3 +218,3 @@ else if (this.validateCallstack()) { | ||
console.error('Callstack is invalid, resetting session.'); | ||
this.reset(this.args.dialogId, this.args.dialogArgs); | ||
this.reset(this.options.dialogId, this.options.dialogArgs); | ||
} | ||
@@ -220,4 +228,4 @@ } | ||
var tmpl; | ||
if (this.args.localizer && this.message) { | ||
tmpl = this.args.localizer.gettext(this.message.language || '', msgid); | ||
if (this.options.localizer && this.message) { | ||
tmpl = this.options.localizer.gettext(this.message.language || '', msgid); | ||
} | ||
@@ -250,7 +258,7 @@ else { | ||
} | ||
}, _this.args.minSendDelay - (now - _this.lastSendTime)); | ||
}, _this.options.minSendDelay - (now - _this.lastSendTime)); | ||
}; | ||
if (this.sendQueue.length == 0) { | ||
this.msgSent = true; | ||
if ((now - this.lastSendTime) >= this.args.minSendDelay) { | ||
if ((now - this.lastSendTime) >= this.options.minSendDelay) { | ||
this.lastSendTime = now; | ||
@@ -257,0 +265,0 @@ this.emit(event, message); |
@@ -1,2 +0,1 @@ | ||
var utils = require('../utils'); | ||
var MemoryStorage = (function () { | ||
@@ -8,3 +7,3 @@ function MemoryStorage() { | ||
if (this.store.hasOwnProperty(id)) { | ||
callback(null, utils.clone(this.store[id])); | ||
callback(null, JSON.parse(this.store[id])); | ||
} | ||
@@ -16,3 +15,3 @@ else { | ||
MemoryStorage.prototype.save = function (id, data, callback) { | ||
this.store[id] = utils.clone(data || {}); | ||
this.store[id] = JSON.stringify(data || {}); | ||
if (callback) { | ||
@@ -19,0 +18,0 @@ callback(null); |
@@ -5,5 +5,6 @@ { | ||
"description": "Bot Builder is a dialog system for building rich bots on virtually any platform.", | ||
"version": "0.8.0", | ||
"version": "0.9.0", | ||
"license": "MIT", | ||
"keywords": [ | ||
"botbuilder", | ||
"bots", | ||
@@ -10,0 +11,0 @@ "chatbots" |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
207816
4390