leopard-tie-client
Version:
Extended TIE Client that accepts additional custom request headers
140 lines (105 loc) • 3.72 kB
JavaScript
;
exports.__esModule = true;
exports["default"] = void 0;
var TeneoResponse =
/*#__PURE__*/
function () {
function TeneoResponse(json) {
var type = typeof json;
if (!(type === 'function' || type === 'object' && !!json)) {
console.error('ERROR: TeneoResponse: Not an Object', json);
throw new Error("Teneo Response constructed with something that isn't an object");
}
if (!('output' in json)) {
console.error('ERROR: TeneoResponse: Obj incorrect', json);
throw new Error("Teneo Response constructed with an Object without an 'output' property");
}
this.json = json;
}
var _proto = TeneoResponse.prototype;
_proto.getJson = function getJson() {
return this.json;
};
_proto.getSessionId = function getSessionId() {
return this.json.getSessionId;
};
_proto.getOutputText = function getOutputText() {
return this.json.output.text;
};
_proto.getInputText = function getInputText() {
return this.json.input.text;
};
_proto.getEmotion = function getEmotion() {
return this.json.output.emotion;
};
_proto.hasEmotion = function hasEmotion() {
return this.json.output.emotion || false;
};
_proto.getLink = function getLink() {
return this.json.output.link;
};
_proto.hasLink = function hasLink() {
return this.json.output.link || false;
};
_proto.addParameter = function addParameter(name, value) {
this.json.output.parameters[name] = value;
};
_proto.hasParameter = function hasParameter(name) {
return name in this.json.output.parameters;
};
_proto.getParameter = function getParameter(name) {
return this.json.output.parameters[name];
};
_proto.getParameterNames = function getParameterNames() {
var paramNames = [];
for (var _i = 0, _Object$entries = Object.entries(this.json.output.parameters); _i < _Object$entries.length; _i++) {
var _Object$entries$_i = _Object$entries[_i],
key = _Object$entries$_i[0];
paramNames.push(key);
}
return paramNames;
};
_proto.hasParametersStartingWith = function hasParametersStartingWith(prefix) {
var result = false;
for (var _i2 = 0, _Object$entries2 = Object.entries(this.json.output.parameters); _i2 < _Object$entries2.length; _i2++) {
var _Object$entries2$_i = _Object$entries2[_i2],
key = _Object$entries2$_i[0],
value = _Object$entries2$_i[1];
if (key.startsWith(prefix)) {
result = true;
}
}
return result;
};
_proto.hasParametersContaining = function hasParametersContaining(strMatch) {
var result = false;
for (var _i3 = 0, _Object$entries3 = Object.entries(this.json.output.parameters); _i3 < _Object$entries3.length; _i3++) {
var _Object$entries3$_i = _Object$entries3[_i3],
key = _Object$entries3$_i[0],
value = _Object$entries3$_i[1];
if (key.indexOf(strMatch) > -1) {
result = true;
}
}
return result;
};
_proto.getParametersStartingWith = function getParametersStartingWith(prefix) {
var result = {};
for (var _i4 = 0, _Object$entries4 = Object.entries(this.json.output.parameters); _i4 < _Object$entries4.length; _i4++) {
var _Object$entries4$_i = _Object$entries4[_i4],
key = _Object$entries4$_i[0],
value = _Object$entries4$_i[1];
if (key.startsWith(prefix)) {
result[key] = value;
}
}
return result;
};
_proto.isObject = function isObject(obj) {
var type = typeof obj;
return type === 'function' || type === 'object' && !!obj;
};
return TeneoResponse;
}();
exports["default"] = TeneoResponse;
module.exports = exports.default;