botbuilder
Advanced tools
Comparing version 3.9.1 to 3.10.0
@@ -198,7 +198,18 @@ "use strict"; | ||
bot: address.bot, | ||
members: [address.user], | ||
channelData: address.channelData | ||
members: address.members || [address.user] | ||
}, | ||
json: true | ||
}; | ||
if (address.activity) { | ||
options.body.activity = address.activity; | ||
} | ||
if (address.channelData) { | ||
options.body.channelData = address.channelData; | ||
} | ||
if (address.isGroup !== undefined) { | ||
options.body.isGroup = address.isGroup; | ||
} | ||
if (address.topicName) { | ||
options.body.topicName = address.topicName; | ||
} | ||
this.authenticatedRequest(options, function (err, response, body) { | ||
@@ -212,2 +223,5 @@ var adr; | ||
adr.conversation = { id: obj['id'] }; | ||
if (obj['serviceUrl']) { | ||
adr.serviceUrl = obj['serviceUrl']; | ||
} | ||
if (adr.id) { | ||
@@ -540,36 +554,60 @@ delete adr.id; | ||
}; | ||
ChatConnector.prototype.getAccessToken = function (cb) { | ||
ChatConnector.prototype.tokenExpired = function () { | ||
return Date.now() >= this.accessTokenExpires; | ||
}; | ||
ChatConnector.prototype.tokenHalfWayExpired = function (secondstoHalfWayExpire, secondsToExpire) { | ||
if (secondstoHalfWayExpire === void 0) { secondstoHalfWayExpire = 1800; } | ||
if (secondsToExpire === void 0) { secondsToExpire = 300; } | ||
var timeToExpiration = (this.accessTokenExpires - Date.now()) / 1000; | ||
return timeToExpiration < secondstoHalfWayExpire | ||
&& timeToExpiration > secondsToExpire; | ||
}; | ||
ChatConnector.prototype.refreshAccessToken = function (cb) { | ||
var _this = this; | ||
if (!this.accessToken || new Date().getTime() >= this.accessTokenExpires) { | ||
var opt = { | ||
method: 'POST', | ||
url: this.settings.endpoint.refreshEndpoint, | ||
form: { | ||
grant_type: 'client_credentials', | ||
client_id: this.settings.appId, | ||
client_secret: this.settings.appPassword, | ||
scope: this.settings.endpoint.refreshScope | ||
var opt = { | ||
method: 'POST', | ||
url: this.settings.endpoint.refreshEndpoint, | ||
form: { | ||
grant_type: 'client_credentials', | ||
client_id: this.settings.appId, | ||
client_secret: this.settings.appPassword, | ||
scope: this.settings.endpoint.refreshScope | ||
} | ||
}; | ||
this.addUserAgent(opt); | ||
request(opt, function (err, response, body) { | ||
if (!err) { | ||
if (body && response.statusCode < 300) { | ||
var oauthResponse = JSON.parse(body); | ||
_this.accessToken = oauthResponse.access_token; | ||
_this.accessTokenExpires = new Date().getTime() + ((oauthResponse.expires_in - 300) * 1000); | ||
cb(null, _this.accessToken); | ||
} | ||
}; | ||
this.addUserAgent(opt); | ||
request(opt, function (err, response, body) { | ||
if (!err) { | ||
if (body && response.statusCode < 300) { | ||
var oauthResponse = JSON.parse(body); | ||
_this.accessToken = oauthResponse.access_token; | ||
_this.accessTokenExpires = new Date().getTime() + ((oauthResponse.expires_in - 300) * 1000); | ||
cb(null, _this.accessToken); | ||
} | ||
else { | ||
cb(new Error('Refresh access token failed with status code: ' + response.statusCode), null); | ||
} | ||
} | ||
else { | ||
cb(err, null); | ||
cb(new Error('Refresh access token failed with status code: ' + response.statusCode), null); | ||
} | ||
} | ||
else { | ||
cb(err, null); | ||
} | ||
}); | ||
}; | ||
ChatConnector.prototype.getAccessToken = function (cb) { | ||
var _this = this; | ||
if (this.accessToken == null || this.tokenExpired()) { | ||
this.refreshAccessToken(function (err, token) { | ||
cb(err, _this.accessToken); | ||
}); | ||
} | ||
else { | ||
else if (this.tokenHalfWayExpired()) { | ||
var oldToken = this.accessToken; | ||
this.refreshAccessToken(function (err, token) { | ||
if (!err) | ||
cb(null, _this.accessToken); | ||
else | ||
cb(null, oldToken); | ||
}); | ||
} | ||
else | ||
cb(null, this.accessToken); | ||
} | ||
}; | ||
@@ -576,0 +614,0 @@ ChatConnector.prototype.addUserAgent = function (options) { |
@@ -253,3 +253,10 @@ "use strict"; | ||
UniversalBot.prototype.loadSession = function (address, done) { | ||
this.loadSessionWithOptionalDispatch(address, false, done); | ||
}; | ||
UniversalBot.prototype.loadSessionWithoutDispatching = function (address, done) { | ||
this.loadSessionWithOptionalDispatch(address, false, done); | ||
}; | ||
UniversalBot.prototype.loadSessionWithOptionalDispatch = function (address, shouldDispatch, done) { | ||
var _this = this; | ||
var newStack = false; | ||
this.lookupUser(address, function (user) { | ||
@@ -275,3 +282,3 @@ var msg = { | ||
}; | ||
_this.createSession(storageCtx, msg, _this.settings.defaultDialogId || '/', _this.settings.defaultDialogArgs, done); | ||
_this.createSession(storageCtx, msg, _this.settings.defaultDialogId || '/', _this.settings.defaultDialogArgs, done, newStack, shouldDispatch); | ||
}, _this.errorLogger(done)); | ||
@@ -293,5 +300,6 @@ }, this.errorLogger(done)); | ||
}; | ||
UniversalBot.prototype.createSession = function (storageCtx, message, dialogId, dialogArgs, done, newStack) { | ||
UniversalBot.prototype.createSession = function (storageCtx, message, dialogId, dialogArgs, done, newStack, shouldDispatch) { | ||
var _this = this; | ||
if (newStack === void 0) { newStack = false; } | ||
if (shouldDispatch === void 0) { shouldDispatch = true; } | ||
var loadedData; | ||
@@ -346,3 +354,8 @@ this.getStorageData(storageCtx, function (data) { | ||
loadedData = data; | ||
session.dispatch(sessionState, message, function () { return done(null, session); }); | ||
if (shouldDispatch) { | ||
session.dispatch(sessionState, message, function () { return done(null, session); }); | ||
} | ||
else { | ||
done(null, session); | ||
} | ||
}, done); | ||
@@ -349,0 +362,0 @@ }; |
@@ -34,3 +34,3 @@ "use strict"; | ||
if (exp) { | ||
var matches = exp.exec(context.message.text); | ||
var matches = new RegExp(exp).exec(context.message.text); | ||
if (matches && matches.length) { | ||
@@ -37,0 +37,0 @@ var matched = matches[0]; |
@@ -5,3 +5,3 @@ { | ||
"description": "Bot Builder is a dialog system for building rich bots on virtually any platform.", | ||
"version": "3.9.1", | ||
"version": "3.10.0", | ||
"license": "MIT", | ||
@@ -8,0 +8,0 @@ "keywords": [ |
Sorry, the diff of this file is too big to display
615164
84
13174