@cognigy/rest-api-client
Version:
Cognigy REST-Client
109 lines • 4.04 kB
JavaScript
import { __awaiter } from "tslib";
/* Custom modules */
import { createNodeDescriptor } from "../../createNodeDescriptor";
import transcriptAssistTemplate from "./htmlTemplates/transcriptAssistTemplate";
import { LAST_INPUT_PROMPT } from "./constants/constants";
import { sentimentAnalysis } from "./helpers/sentiment.helper";
import { getFontSizeFieldOptions } from "./helpers/getFontSizeFieldOptions";
/**
* Node name: "transcriptAssist"
*
* Purpose:
* The Transcript Assist widget will suggest agent responses and provide more information to draft messages.
*/
export const TRANSCRIPT_ASSIST = createNodeDescriptor({
type: "transcriptAssist",
defaultLabel: "Copilot: Transcript Tile",
summary: "UI__NODE_EDITOR__TRANSCRIPT_ASSIST__SUMMARY",
appearance: {
showIcon: false,
},
tags: ["agentAssist"],
fields: [
{
key: "tileId",
label: "UI__NODE_EDITOR__TRANSCRIPT_ASSIST__ID__LABEL",
type: "cognigyText",
description: "UI__NODE_EDITOR__TRANSCRIPT_ASSIST_TILE_ID__DESCRIPTION",
defaultValue: "transcript-assist",
params: {
required: true,
},
},
{
key: "enableSentiment",
label: "UI__NODE_EDITOR__TRANSCRIPT_ASSIST__ENABLE_SENTIMENT__LABEL",
type: "toggle",
defaultValue: false,
},
{
key: "fontSize",
type: "select",
label: "UI__NODE_EDITOR__COPILOT__TILE_UI_PREFERENCES__FONT_SIZE",
description: "UI__NODE_EDITOR__COPILOT__TILE_UI_PREFERENCES__FONT_SIZE__INFO",
defaultValue: "text-sm",
params: {
options: getFontSizeFieldOptions,
},
},
{
key: "messageFontSize",
type: "select",
label: "UI__NODE_EDITOR__COPILOT__TILE_UI_PREFERENCES__FONT_SIZE",
description: "UI__NODE_EDITOR__COPILOT__TILE_UI_PREFERENCES__FONT_SIZE__INFO",
defaultValue: "text-sm",
params: {
options: getFontSizeFieldOptions,
},
},
],
sections: [
{
key: "uiPreferences",
label: "UI__NODE_EDITOR__COPILOT__TILE_UI_PREFERENCES__TITLE",
defaultCollapsed: true,
fields: ["fontSize", "messageFontSize"],
},
],
form: [
{ type: "field", key: "tileId" },
{ type: "field", key: "enableSentiment" },
{ type: "section", key: "uiPreferences" },
].filter((element) => !!element),
function: (params) => __awaiter(void 0, void 0, void 0, function* () {
const { cognigy, config } = params;
const { api } = cognigy;
const sentimentEnabled = config["enableSentiment"];
let sentiment;
try {
const inputText = cognigy.input.text;
if (!inputText) {
return;
}
if (sentimentEnabled) {
const prompt = `${LAST_INPUT_PROMPT} ${inputText}`;
sentiment = yield sentimentAnalysis(api, prompt);
}
const data = {
html: transcriptAssistTemplate({
message: inputText,
assetsBaseURL: process.env.AGENT_ASSIST_WORKSPACE_FRONTEND_URL_WITH_PROTOCOL || "",
sentiment,
fontSize: config.fontSize,
messageFontSize: config.messageFontSize
}),
};
cognigy.api.sendTileUpdateToAgentAssistWorkspace(Object.assign(Object.assign({}, params), { tile: {
id: config.tileId,
type: "html",
data,
} }));
api.logDebugMessage(`UI__DEBUG_MODE__TRANSCRIPT_ASSIST__MESSAGE`);
}
catch (error) {
api.logDebugError(error, "Copilot: Transcript Tile Error");
}
return;
}),
});
//# sourceMappingURL=transcriptAssist.js.map