@cognigy/rest-api-client
Version:
Cognigy REST-Client
88 lines • 3.19 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SET_IFRAME_TILE = void 0;
/* Custom modules */
const createNodeDescriptor_1 = require("../../createNodeDescriptor");
const determineMetadata_1 = require("./helpers/determineMetadata");
const iframeUrlKey = "iframeUrl";
const iframeJsonKey = "iframeJSON";
const urlRegex = new RegExp(/^(https?:\/\/)?[\w\-]+(\.[\w\-]+)+[/#?]?.*$/i);
/**
* Node name: "setIFrameTile"
*
* Purpose:
* Set an IFrame Tile for the Agent Assist Workspace
*/
exports.SET_IFRAME_TILE = (0, createNodeDescriptor_1.createNodeDescriptor)({
type: "setIFrameTile",
defaultLabel: "Copilot: IFrame Tile",
summary: "UI__NODE_EDITOR__SET_IFRAME_TILE__SUMMARY",
appearance: {
showIcon: false,
},
tags: ["agentAssist"],
fields: [
{
key: "tileId",
label: "UI__NODE_EDITOR__SET_IFRAME_TILE__TILE_ID__LABEL",
type: "cognigyText",
description: "UI__NODE_EDITOR__SET_IFRAME_TILE__TILE_ID__DESCRIPTION",
defaultValue: "iframe-tile",
params: {
required: true,
},
},
{
key: iframeUrlKey,
label: "UI__NODE_EDITOR__SET_IFRAME_TILE__IFRAME_URL__LABEL",
type: "cognigyText",
description: "UI__NODE_EDITOR__SET_IFRAME_TILE__IFRAME_URL__DESCRIPTION",
defaultValue: "https://www.test.example",
params: {
required: true,
},
},
{
key: iframeJsonKey,
label: "UI__NODE_EDITOR__SET_IFRAME_TILE__IFRAME_JSON__LABEL",
type: "json",
description: "UI__NODE_EDITOR__SET_IFRAME_TILE__IFRAME_JSON__DESCRIPTION",
defaultValue: "{}",
},
],
sections: [],
form: [
{ type: "field", key: "tileId" },
{ type: "field", key: "iframeUrl" },
{ type: "field", key: "iframeJSON" },
].filter((element) => !!element),
function: async (params) => {
const { config, cognigy } = params;
const { api } = cognigy;
const url = config[iframeUrlKey];
const jsonData = config[iframeJsonKey];
if (!urlRegex.test(url)) {
api.log("error", "Please provide a valid URL in the IFrame URL field");
return;
}
try {
const data = Object.assign({ url }, (0, determineMetadata_1.determineMetadata)(jsonData));
cognigy.api.sendTileUpdateToAgentAssistWorkspace(Object.assign(Object.assign({}, params), { tile: {
id: config.tileId,
type: "iframe",
data,
} }));
api.logDebugMessage(`UI__DEBUG_MODE__SET_IFRAME_TILE__MESSAGE`);
}
catch (error) {
if (error instanceof SyntaxError) {
api.logDebugError("Please provide a valid JSON in the JSON Data field", "Copilot: IFrame Tile Error");
}
else {
api.logDebugError(error, "Copilot: IFrame Tile Error");
}
}
return;
},
});
//# sourceMappingURL=setIframeTile.js.map