recime-bot-runtime
Version:
This runtime is intended to run inside a micro-service container with platform specific integration and module interpreter.
49 lines (48 loc) • 1.88 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var request = require("request");
var Luis = /** @class */ (function () {
function Luis(bot) {
this.bot = bot;
}
Luis.prototype.process = function (payload) {
var _this = this;
return new Promise(function (resolve, reject) {
var errorMessages = [
'Model not published',
'Please re-train your application'
];
request({
uri: "https://" + _this.bot.meta.luis.region + ".api.cognitive.microsoft.com/luis/v2.0/apps/" + _this.bot.meta.luis.appId,
qs: {
'subscription-key': _this.bot.config['RECIME_LUIS_ENDPOINT_KEY'],
timezoneOffset: _this.bot.meta.luis.timezone,
verbose: true,
q: payload.text
},
json: true
}, function (error, response, body) {
if (typeof body === 'string') {
var notPublished = errorMessages.some(function (m) { return response.indexOf(m) > -1; });
var message = notPublished
? 'Your bot is still in training, please try again in a few minutes.'
: body;
reject({
message: message,
code: 503
});
}
else if (typeof response === 'object' &&
!Object.keys(body).length) {
reject({
message: 'Your bot is still in training, please try again in a few minutes.',
code: 503
});
}
resolve(body);
});
});
};
return Luis;
}());
exports.Luis = Luis;