block-obj-builder
Version:
Block object builder
113 lines (112 loc) • 3.73 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var bson_objectid_1 = require("bson-objectid");
var block_obj_enums_1 = require("../../const/block-obj-enums");
var BlockObjBuilder = /** @class */ (function () {
function BlockObjBuilder() {
this.obj = {
name: BlockObjBuilder.DEFAULT_NAME,
group: BlockObjBuilder.DEFAULT_GROUP,
version: 2,
blockId: new bson_objectid_1.default().toHexString(),
created: new Date(),
content: {},
meta: {}
};
}
BlockObjBuilder.prototype.addTitle = function (lang, title) {
var content = this.obj.content;
if (!content.title) {
content.title = {};
}
content.title[lang] = title;
return this;
};
BlockObjBuilder.prototype.name = function (s) {
this.obj.name = s;
return this;
};
BlockObjBuilder.prototype.group = function (s) {
if (s === '') {
s = 'default';
}
this.obj.group = s;
return this;
};
BlockObjBuilder.prototype.module = function (module) {
this.obj.module = module;
return this;
};
BlockObjBuilder.prototype.description = function (description) {
this.obj.meta.description = description;
return this;
};
BlockObjBuilder.prototype.type = function (bt) {
this.obj.type = bt;
return this;
};
BlockObjBuilder.prototype.blockId = function (blockId) {
this.obj.blockId = blockId;
return this;
};
BlockObjBuilder.prototype.next = function (blockId) {
this.obj.next = blockId;
return this;
};
BlockObjBuilder.prototype.onReply = function (blockId, args) {
this.obj.onReply = {
blockId: blockId,
args: args
};
return this;
};
BlockObjBuilder.prototype.formFieldCallback = function (formId, args) {
this.obj.formFieldCallback = {
formId: formId,
args: args
};
return this;
};
BlockObjBuilder.prototype.voiceAction = function (voiceAction) {
this.obj.voiceAction = voiceAction;
return this;
};
BlockObjBuilder.prototype.twilioVerb = function (twilioVerb) {
this.obj.meta.twilioVerb = twilioVerb;
return this;
};
BlockObjBuilder.prototype.twilioVerbAttributes = function (verbAttributes) {
this.obj.meta.twilioVerbAttributes = verbAttributes;
return this;
};
BlockObjBuilder.prototype.twilioGatherRepeats = function (numRepeats) {
this.obj.meta.twilioGatherRepeats = numRepeats;
return this;
};
BlockObjBuilder.prototype.jovoFollowUpState = function (state) {
this.obj.meta.jovoFollowUpState = state;
return this;
};
BlockObjBuilder.prototype.messengerTag = function (tag) {
this.obj.meta.messengerTag = tag;
return this;
};
BlockObjBuilder.prototype.addIntent = function (intentName, blockPointer) {
if (!this.obj.intentMap) {
this.obj.intentMap = {};
}
this.obj.intentMap[intentName] = blockPointer;
return this;
};
BlockObjBuilder.prototype.alexaPermissionRequired = function (userInfo) {
this.obj.meta.alexaPermissionRequired = userInfo;
return this;
};
BlockObjBuilder.prototype.build = function () {
return this.obj;
};
BlockObjBuilder.DEFAULT_NAME = block_obj_enums_1.CommonGroups.BUILT_AT_RUNTIME;
BlockObjBuilder.DEFAULT_GROUP = block_obj_enums_1.CommonGroups.BUILT_AT_RUNTIME;
return BlockObjBuilder;
}());
exports.default = BlockObjBuilder;