@cognigy/rest-api-client
Version:
Cognigy REST-Client
86 lines • 3.1 kB
JavaScript
import { __awaiter } from "tslib";
/* Custom modules */
import { createNodeDescriptor } from "../../createNodeDescriptor";
import { determineMetadata } from "./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
*/
export const SET_IFRAME_TILE = 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: (params) => __awaiter(void 0, void 0, void 0, function* () {
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 }, 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