@cognigy/rest-api-client
Version:
Cognigy REST-Client
72 lines • 2.5 kB
JavaScript
import { __awaiter } from "tslib";
/* Custom modules */
import { createNodeDescriptor } from "../../createNodeDescriptor";
import { determineMetadata } from "./helpers/determineMetadata";
const jsonKey = "json";
/**
* Node name: "sendData"
*
* Purpose:
* Send data to a tile in the Agent Assist Workspace
*/
export const SEND_TILE_DATA = 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: (params) => __awaiter(void 0, void 0, void 0, function* () {
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({}, 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