@cognigy/rest-api-client
Version:
Cognigy REST-Client
74 lines • 2.59 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SEND_TILE_DATA = void 0;
/* Custom modules */
const createNodeDescriptor_1 = require("../../createNodeDescriptor");
const determineMetadata_1 = require("./helpers/determineMetadata");
const jsonKey = "json";
/**
* Node name: "sendData"
*
* Purpose:
* Send data to a tile in the Agent Assist Workspace
*/
exports.SEND_TILE_DATA = (0, createNodeDescriptor_1.createNodeDescriptor)({
type: "sendData",
defaultLabel: "Copilot: Send Data",
summary: "UI__NODE_EDITOR__SEND_TILE_DATA__SUMMARY",
appearance: {
showIcon: false,
},
tags: ["agentAssist"],
fields: [
{
key: "tileId",
label: "UI__NODE_EDITOR__SEND_TILE_DATA__TILE_ID__LABEL",
type: "cognigyText",
description: "UI__NODE_EDITOR__SEND_TILE_DATA__TILE_ID__DESCRIPTION",
defaultValue: "html-tile",
params: {
required: true,
},
},
{
key: jsonKey,
label: "UI__NODE_EDITOR__SEND_TILE_DATA__JSON__LABEL",
type: "json",
description: "UI__NODE_EDITOR__SEND_TILE_DATA__JSON__DESCRIPTION",
defaultValue: "{}",
},
],
sections: [],
form: [
{ type: "field", key: "tileId" },
{ type: "field", key: "json" },
].filter((element) => !!element),
function: async (params) => {
const { cognigy, config } = params;
const { api } = cognigy;
const jsonData = config[jsonKey];
if (!config.json || config.json.length === 0) {
api.log("error", "Please provide JSON data in the JSON Data field");
return;
}
try {
const data = Object.assign({}, (0, determineMetadata_1.determineMetadata)(jsonData));
cognigy.api.sendTileUpdateToAgentAssistWorkspace(Object.assign(Object.assign({}, params), { tile: {
id: config.tileId,
type: "sendTileData",
data,
} }));
api.logDebugMessage("Successfully sent data to the Agent Assist Workspace");
}
catch (error) {
if (error instanceof SyntaxError) {
api.logDebugError("Please provide a valid JSON in the JSON Data field", "Copilot: Send Tile Data Error");
}
else {
api.logDebugError(error, "Copilot: Send Tile Data Error");
}
}
return;
},
});
//# sourceMappingURL=sendData.js.map