@cognigy/rest-api-client
Version:
Cognigy REST-Client
98 lines • 3.3 kB
JavaScript
import { __awaiter } from "tslib";
/* Custom modules */
import { createNodeDescriptor } from "../../createNodeDescriptor";
import { determineMetadata } from "./helpers/determineMetadata";
const htmlContentKey = "htmlContent";
const htmlJsonKey = "htmlJSON";
export const formExampleHTML = /* html */ `<!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
*/
export const SET_HTML_TILE = 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: 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: (params) => __awaiter(void 0, void 0, void 0, function* () {
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 }, 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