@cognigy/rest-api-client
Version:
Cognigy REST-Client
100 lines • 3.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SET_HTML_TILE = exports.formExampleHTML = void 0;
/* Custom modules */
const createNodeDescriptor_1 = require("../../createNodeDescriptor");
const determineMetadata_1 = require("./helpers/determineMetadata");
const htmlContentKey = "htmlContent";
const htmlJsonKey = "htmlJSON";
exports.formExampleHTML = `<!DOCTYPE html>
<html>
<head> </head>
<body>
<script>
window.addEventListener("message", function (event) {
console.log("Content of message: " + event.data);
});
</script>
<h1>HTML Tile</h1>
</body>
</html>
`;
/**
* Node name: "setHTMLTile"
*
* Purpose:
* Set an HTML Tile for the Agent Assist Workspace
*/
exports.SET_HTML_TILE = (0, createNodeDescriptor_1.createNodeDescriptor)({
type: "setHTMLTile",
defaultLabel: "Copilot: HTML Tile",
summary: "UI__NODE_EDITOR__SET_HTML_TILE__SUMMARY",
appearance: {
showIcon: false,
},
tags: ["agentAssist"],
fields: [
{
key: "tileId",
label: "UI__NODE_EDITOR__SET_HTML_TILE__TILE_ID__LABEL",
type: "cognigyText",
description: "UI__NODE_EDITOR__SET_HTML_TILE__TILE_ID__DESCRIPTION",
defaultValue: "html-tile",
params: {
required: true,
},
},
{
key: htmlContentKey,
label: "UI__NODE_EDITOR__SET_HTML_TILE__HTML_CONTENT__LABEL",
type: "xml",
description: "UI__NODE_EDITOR__SET_HTML_TILE__HTML_CONTENT__DESCRIPTION",
defaultValue: exports.formExampleHTML,
params: {
required: true,
},
},
{
key: htmlJsonKey,
label: "UI__NODE_EDITOR__SET_HTML_TILE__HTML_JSON__LABEL",
type: "json",
description: "UI__NODE_EDITOR__SET_HTML_TILE__HTML_JSON__DESCRIPTION",
defaultValue: "{}",
},
],
sections: [],
form: [
{ type: "field", key: "tileId" },
{ type: "field", key: "htmlContent" },
{ type: "field", key: "htmlJSON" },
].filter((element) => !!element),
function: async (params) => {
const { cognigy, config } = params;
const { api } = cognigy;
const htmlContent = config[htmlContentKey];
const jsonData = config[htmlJsonKey];
if (!config.htmlContent || config.htmlContent.length === 0) {
api.log("error", "Please provide HTML content in the HTML Content field");
return;
}
try {
const data = Object.assign({ html: htmlContent }, (0, determineMetadata_1.determineMetadata)(jsonData));
cognigy.api.sendTileUpdateToAgentAssistWorkspace(Object.assign(Object.assign({}, params), { tile: {
id: config.tileId,
type: "html",
data,
} }));
api.logDebugMessage("Successfully set HTML Tile content");
}
catch (error) {
if (error instanceof SyntaxError) {
api.logDebugError("Please provide a valid JSON in the JSON Data field", "Copilot: HTML Tile Error");
}
else {
api.logDebugError(error, "Copilot: HTML Tile Error");
}
}
return;
},
});
//# sourceMappingURL=setHtmlTile.js.map