@humany/widget-chat
Version:
Humany Widget Chat Platform
77 lines (76 loc) • 3.66 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
var widget_data_1 = require("@humany/widget-data");
/**
* TODO: Consolidate `writeAgentMessage()`, `writeUserMessage()`, `writeInfoMessage()`,
* `writeStatusMessage()` below. Only differ by tags.
*/
var DataWriter = /** @class */ (function (_super) {
__extends(DataWriter, _super);
function DataWriter(dataSource, stream, clientName) {
var _this = _super.call(this, dataSource, stream || []) || this;
_this.clientName = clientName;
return _this;
}
DataWriter.prototype.writeAgentMessage = function (content, tags) {
if (tags === void 0) { tags = []; }
return this.create('Text', content, { tags: ['chat', 'agent'].concat(tags) });
};
DataWriter.prototype.writeUserMessage = function (content, tags) {
if (tags === void 0) { tags = []; }
var options = { tags: ['chat', 'user'].concat(tags) };
return this.create('Text', content, options);
};
DataWriter.prototype.writeInfoMessage = function (content, tags) {
if (tags === void 0) { tags = []; }
return this.create('Text', content, { tags: ['chat', 'info'].concat(tags) });
};
DataWriter.prototype.writeStatusMessage = function (content, tags) {
if (tags === void 0) { tags = []; }
return this.create('Text', content, { tags: ['chat', 'status'].concat(tags) });
};
DataWriter.prototype.writeFormMessage = function (formOptions, tags) {
if (tags === void 0) { tags = []; }
var alias = formOptions.alias, form = formOptions.form, type = formOptions.type, id = formOptions.id;
var entry = this.create('Contact', {}, {
tags: ['form', 'chat', 'info'].concat(tags),
actions: { submit: {} },
});
entry.content = __assign(__assign({}, entry.content), { alias: alias, type: type, id: id, clientName: "".concat(this.clientName, ".form"), entryId: entry.id, actionKey: 'submit', inline: true, title: '', expanded: true, body: { form: form } });
return entry;
};
DataWriter.prototype.create = function (type, content, options) {
if (content && !content.timestamp) {
content.timestamp = new Date().toString();
}
return _super.prototype.create.call(this, type, content, options);
};
return DataWriter;
}(widget_data_1.Writer));
exports.default = DataWriter;