@cognigy/rest-api-client
Version:
Cognigy REST-Client
484 lines • 18.6 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.INIT_APP_SESSION = void 0;
/* Custom modules */
const createNodeDescriptor_1 = require("../../createNodeDescriptor");
const buildAppUrl_1 = require("./utils/buildAppUrl");
/**
* Node name: 'initAppSession'
*
* Purpose:
* Initializes a new Cognigy App Session.
*/
exports.INIT_APP_SESSION = (0, createNodeDescriptor_1.createNodeDescriptor)({
type: "initAppSession",
defaultLabel: "xApp: Init Session",
summary: "UI__NODE_EDITOR__INIT_APP_SESSION__SUMMARY",
appearance: {
showIcon: false,
},
fields: [
// Style Customization
{
type: "cognigyText",
key: "backgroundColor",
label: "UI__NODE_EDITOR__INIT_APP_SESSION__BACKGROUND_COLOR__LABEL",
description: "UI__NODE_EDITOR__INIT_APP_SESSION__BACKGROUND_COLOR__DESCRIPTION",
},
{
type: "cognigyText",
key: "textColor",
label: "UI__NODE_EDITOR__INIT_APP_SESSION__TEXT_COLOR__LABEL",
description: "UI__NODE_EDITOR__INIT_APP_SESSION__TEXT_COLOR__DESCRIPTION",
},
{
type: "select",
key: "logo",
label: "UI__NODE_EDITOR__INIT_APP_SESSION__LOGO__LABEL",
description: "UI__NODE_EDITOR__INIT_APP_SESSION__LOGO__DESCRIPTION",
params: {
options: [
{
label: "UI__NODE_EDITOR__INIT_APP_SESSION__LOGO__DEFAULT__LABEL",
value: "default",
},
{
label: "UI__NODE_EDITOR__INIT_APP_SESSION__LOGO__NONE__LABEL",
value: "none",
},
{
label: "UI__NODE_EDITOR__INIT_APP_SESSION__LOGO__CUSTOM__LABEL",
value: "custom",
},
],
},
defaultValue: "default",
},
{
type: "cognigyText",
key: "logoUrl",
label: "UI__NODE_EDITOR__INIT_APP_SESSION__LOGO_URL__LABEL",
description: "UI__NODE_EDITOR__INIT_APP_SESSION__LOGO_URL__DESCRIPTION",
condition: {
key: "logo",
value: "custom",
},
},
{
type: "cognigyText",
key: "faviconUrl",
label: "UI__NODE_EDITOR__INIT_APP_SESSION__FAVICON_URL__LABEL",
description: "UI__NODE_EDITOR__INIT_APP_SESSION__FAVICON_URL__DESCRIPTION",
params: {
maxLength: 256,
},
},
{
type: "cognigyText",
key: "pageTitle",
label: "UI__NODE_EDITOR__INIT_APP_SESSION__PAGE_TITLE__LABEL",
description: "UI__NODE_EDITOR__INIT_APP_SESSION__PAGE_TITLE__DESCRIPTION",
params: {
maxLength: 256,
},
},
// App Pages
{
type: "description",
key: "appSectionDescription",
label: " ",
params: {
text: "UI__NODE_EDITOR__INIT_APP_SESSION__APP_SECTION_DESCRIPTION__TEXT",
},
},
{
type: "cognigyText",
key: "appLoadingText",
label: "UI__NODE_EDITOR__INIT_APP_SESSION__APP_LOADING_TEXT__LABEL",
description: "UI__NODE_EDITOR__INIT_APP_SESSION__APP_LOADING_TEXT__DESCRIPTION",
params: {
maxLength: 256,
},
},
{
type: "cognigyText",
key: "appLaunchErrorText",
label: "UI__NODE_EDITOR__INIT_APP_SESSION__APP_LAUNCH_ERROR_TEXT__LABEL",
description: "UI__NODE_EDITOR__INIT_APP_SESSION__APP_LAUNCH_ERROR_TEXT__DESCRIPTION",
params: {
maxLength: 256,
},
},
{
type: "cognigyText",
key: "appErrorText",
label: "UI__NODE_EDITOR__INIT_APP_SESSION__APP_ERROR_TEXT__LABEL",
description: "UI__NODE_EDITOR__INIT_APP_SESSION__APP_ERROR_TEXT__DESCRIPTION",
params: {
maxLength: 256,
},
},
// Intermediate Screen
{
type: "description",
key: "intermediateScreenDescription",
label: " ",
params: {
text: "UI__NODE_EDITOR__INIT_APP_SESSION__INTERMEDIATE_SCREEN_DESCRIPTION__TEXT",
},
},
{
type: "select",
key: "intermediateScreenCustomizationType",
label: "UI__NODE_EDITOR__INIT_APP_SESSION__INTERMEDIATE_SCREEN_CUSTOMIZATION_TYPE__LABEL",
params: {
options: [
{
label: "UI__NODE_EDITOR__INIT_APP_SESSION__INTERMEDIATE_SCREEN_CUSTOMIZATION_TYPE__NONE__LABEL",
value: "none",
},
{
label: "UI__NODE_EDITOR__INIT_APP_SESSION__INTERMEDIATE_SCREEN_CUSTOMIZATION_TYPE__OVERRIDE__LABEL",
value: "override",
},
{
label: "UI__NODE_EDITOR__INIT_APP_SESSION__INTERMEDIATE_SCREEN_CUSTOMIZATION_TYPE__APP__LABEL",
value: "app",
},
],
},
defaultValue: "none",
},
// Intermediate Screen - Override
{
type: "cognigyText",
key: "intermediateScreenOverrideText",
label: "UI__NODE_EDITOR__INIT_APP_SESSION__INTERMEDIATE_SCREEN_OVERRIDE_TEXT__LABEL",
description: "UI__NODE_EDITOR__INIT_APP_SESSION__INTERMEDIATE_SCREEN_OVERRIDE_TEXT__DESCRIPTION",
defaultValue: "Nothing to do...",
condition: {
key: "intermediateScreenCustomizationType",
value: "override",
},
params: {
maxLength: 256,
},
},
// Intermediate Screen - Custom App
{
type: "cognigyText",
key: "intermediateScreenAppTemplateId",
label: "UI__NODE_EDITOR__INIT_APP_SESSION__INTERMEDIATE_SCREEN_APP_TEMPLATE_ID__LABEL",
description: "UI__NODE_EDITOR__INIT_APP_SESSION__INTERMEDIATE_SCREEN_APP_TEMPLATE_ID__DESCRIPTION",
defaultValue: "",
condition: {
key: "intermediateScreenCustomizationType",
value: "app",
},
params: {
required: true,
},
},
{
type: "json",
key: "intermediateScreenAppTemplateData",
label: "UI__NODE_EDITOR__INIT_APP_SESSION__INTERMEDIATE_SCREEN_APP_TEMPLATE_DATA__LABEL",
description: "UI__NODE_EDITOR__INIT_APP_SESSION__INTERMEDIATE_SCREEN_APP_TEMPLATE_DATA__DESCRIPTION",
defaultValue: "{}",
condition: {
key: "intermediateScreenCustomizationType",
value: "app",
},
},
// Connection Screen
{
type: "description",
key: "connectionScreenDescription",
label: " ",
params: {
text: "UI__NODE_EDITOR__INIT_APP_SESSION__CONNECTION_SCREEN_DESCRIPTION__TEXT",
},
},
{
type: "select",
key: "connectionScreenCustomizationType",
label: "UI__NODE_EDITOR__INIT_APP_SESSION__CONNECTION_SCREEN_CUSTOMIZATION_TYPE__LABEL",
params: {
options: [
{
label: "UI__NODE_EDITOR__INIT_APP_SESSION__CONNECTION_SCREEN_CUSTOMIZATION_TYPE__NONE__LABEL",
value: "none",
},
{
label: "UI__NODE_EDITOR__INIT_APP_SESSION__CONNECTION_SCREEN_CUSTOMIZATION_TYPE__OVERRIDE__LABEL",
value: "override",
},
{
label: "UI__NODE_EDITOR__INIT_APP_SESSION__CONNECTION_SCREEN_CUSTOMIZATION_TYPE__APP__LABEL",
value: "app",
},
],
},
defaultValue: "none",
},
// Connection Screen - Override
{
type: "cognigyText",
key: "connectionScreenOverrideConnectingText",
label: "UI__NODE_EDITOR__INIT_APP_SESSION__CONNECTION_SCREEN_OVERRIDE_CONNECTING_TEXT__LABEL",
description: "UI__NODE_EDITOR__INIT_APP_SESSION__CONNECTION_SCREEN_OVERRIDE_CONNECTING_TEXT__DESCRIPTION",
defaultValue: "Connecting...",
condition: {
key: "connectionScreenCustomizationType",
value: "override",
},
params: {
maxLength: 256,
},
},
{
type: "cognigyText",
key: "connectionScreenOverrideInvalidText",
label: "UI__NODE_EDITOR__INIT_APP_SESSION__CONNECTION_SCREEN_OVERRIDE_INVALID_TEXT__LABEL",
description: "UI__NODE_EDITOR__INIT_APP_SESSION__CONNECTION_SCREEN_OVERRIDE_INVALID_TEXT__DESCRIPTION",
defaultValue: "This session does not exist or is no longer active.",
condition: {
key: "connectionScreenCustomizationType",
value: "override",
},
params: {
maxLength: 256,
},
},
{
type: "cognigyText",
key: "connectionScreenOverrideUnavailableText",
label: "UI__NODE_EDITOR__INIT_APP_SESSION__CONNECTION_SCREEN_OVERRIDE_UNAVAILABLE_TEXT__LABEL",
description: "UI__NODE_EDITOR__INIT_APP_SESSION__CONNECTION_SCREEN_OVERRIDE_UNAVAILABLE_TEXT__DESCRIPTION",
defaultValue: "The application is not available right now.",
condition: {
key: "connectionScreenCustomizationType",
value: "override",
},
params: {
maxLength: 256,
},
},
// Connection Screen - Custom App
{
type: "cognigyText",
key: "connectionScreenAppTemplateId",
label: "UI__NODE_EDITOR__INIT_APP_SESSION__CONNECTION_SCREEN_APP_TEMPLATE_ID__LABEL",
description: "UI__NODE_EDITOR__INIT_APP_SESSION__CONNECTION_SCREEN_APP_TEMPLATE_ID__DESCRIPTION",
defaultValue: "",
condition: {
key: "connectionScreenCustomizationType",
value: "app",
},
params: {
required: true,
},
},
{
type: "json",
key: "connectionScreenAppTemplateData",
label: "UI__NODE_EDITOR__INIT_APP_SESSION__CONNECTION_SCREEN_APP_TEMPLATE_DATA__LABEL",
description: "UI__NODE_EDITOR__INIT_APP_SESSION__CONNECTION_SCREEN_APP_TEMPLATE_DATA__DESCRIPTION",
defaultValue: "{}",
condition: {
key: "connectionScreenCustomizationType",
value: "app",
},
},
],
sections: [
{
label: "UI__NODE_EDITOR__INIT_APP_SESSION__STYLE_SECTION__LABEL",
key: "styleSection",
fields: [
"backgroundColor",
"textColor",
"errorTextColor",
"logo",
"logoUrl",
"faviconUrl",
"pageTitle",
],
defaultCollapsed: false,
},
{
label: "UI__NODE_EDITOR__INIT_APP_SESSION__APP_SCREENS_SECTION__LABEL",
key: "appScreensSection",
fields: ["appLoadingText", "appLaunchErrorText", "appErrorText"],
defaultCollapsed: false,
},
{
label: "UI__NODE_EDITOR__INIT_APP_SESSION__INTERMEDIATE_SCREEN_SECTION__LABEL",
key: "intermediateScreenSection",
fields: [
"intermediateScreenDescription",
"intermediateScreenCustomizationType",
"intermediateScreenOverrideText",
"intermediateScreenAppTemplateId",
"intermediateScreenAppTemplateData",
],
defaultCollapsed: false,
},
{
label: "UI__NODE_EDITOR__INIT_APP_SESSION__CONNECTION_SCREEN_SECTION__LABEL",
key: "connectionScreenSection",
fields: [
"connectionScreenDescription",
"connectionScreenCustomizationType",
"connectionScreenOverrideConnectingText",
"connectionScreenOverrideInvalidText",
"connectionScreenOverrideUnavailableText",
"connectionScreenAppTemplateId",
"connectionScreenAppTemplateData",
],
defaultCollapsed: false,
},
],
form: [
{
type: "section",
key: "styleSection",
},
{
type: "section",
key: "appScreensSection",
},
{
type: "section",
key: "intermediateScreenSection",
},
{
type: "section",
key: "connectionScreenSection",
},
],
tags: ["basic", "apps", "xApps"],
tokens: [
{
type: "input",
label: "UI__NODE_EDITOR__INIT_APP_SESSION__TOKEN_XAPP_SESSION_URL__LABEL",
script: "input.apps.url || ''",
},
],
function: async ({ cognigy, config }) => {
var _a;
const { api, input } = cognigy;
const {
// styling
backgroundColor, textColor, errorTextColor, logo, logoUrl, faviconUrl, pageTitle,
// apps screen
appLoadingText, appLaunchErrorText, appErrorText,
// intermediate screen
intermediateScreenCustomizationType, intermediateScreenOverrideText, intermediateScreenAppTemplateId, intermediateScreenAppTemplateData,
// status screen
connectionScreenCustomizationType, connectionScreenOverrideConnectingText, connectionScreenOverrideInvalidText, connectionScreenOverrideUnavailableText, connectionScreenAppTemplateId, connectionScreenAppTemplateData, } = config;
const style = (() => {
const ret = {};
if (backgroundColor !== "" && backgroundColor !== undefined) {
ret.backgroundColor = backgroundColor;
}
if (textColor !== "" && textColor !== undefined) {
ret.textColor = textColor;
}
if (errorTextColor !== "" && errorTextColor !== undefined) {
ret.errorTextColor = errorTextColor;
}
if (faviconUrl) {
ret.faviconUrl = faviconUrl;
}
if (pageTitle) {
ret.pageTitle = pageTitle;
}
switch (logo) {
case "none":
ret.logoUrl = null;
break;
case "custom":
if (logoUrl !== "" && logoUrl !== undefined) {
ret.logoUrl = logoUrl;
}
break;
default:
case "default":
break;
}
return ret;
})();
const appScreenCustomization = {
loadingText: appLoadingText,
launchErrorText: appLaunchErrorText,
appErrorText: appErrorText,
};
const intermediateScreenCustomization = (() => {
switch (intermediateScreenCustomizationType) {
case "override": {
return {
type: "regular",
idleText: intermediateScreenOverrideText || "",
// TODO successText
};
}
case "app": {
return {
type: "app",
appTemplateUrl: intermediateScreenAppTemplateId,
appTemplateData: intermediateScreenAppTemplateData,
};
}
case "none":
default: {
return undefined;
}
}
})();
const statusScreenCustomization = (() => {
switch (connectionScreenCustomizationType) {
case "override": {
return {
type: "regular",
connectingText: connectionScreenOverrideConnectingText || "",
invalidTokenText: connectionScreenOverrideInvalidText || "",
unavailableText: connectionScreenOverrideUnavailableText || "",
// TODO connectionErrorText
};
}
case "app": {
return {
type: "app",
appTemplateUrl: connectionScreenAppTemplateId,
appTemplateData: connectionScreenAppTemplateData,
};
}
case "none":
default: {
return undefined;
}
}
})();
const customization = (() => {
// TODO filter empty values
return {
style: style,
intermediateScreen: intermediateScreenCustomization,
statusScreen: statusScreenCustomization,
appScreen: appScreenCustomization,
};
})();
if (!input.apps.session.token) {
const appSessionToken = await api.initAppSession({
styleConfig: customization,
});
api.addToInput("apps.session.token", appSessionToken);
}
const finalUrl = (0, buildAppUrl_1.buildAppUrl)(input.apps.baseUrl, (_a = input.apps.session) === null || _a === void 0 ? void 0 : _a.token);
api.addToInput("apps.url", finalUrl);
api.addToInput("apps.customization", customization || null);
api.logDebugMessage(`Token: ${input.apps.session.token}<br>URL: <a href="${input.apps.url} " target="_blank">${input.apps.url}</a>`);
},
});
//# sourceMappingURL=initAppSession.js.map