UNPKG

@cognigy/rest-api-client

Version:

Cognigy REST-Client

135 lines 4.51 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.buildCognigyWhisperAssistResponse = void 0; const buildCognigyWhisperAssistResponse = (config) => { const { cardType, title, subtitle, body, basicImage, basicActionTitle, basicActionUrl, suggestedActionTitles, tableFacts, customJson } = config; let adaptiveCard = {}; const basicCardData = { version: "1.5", $schema: "http://adaptivecards.io/schemas/adaptive-card.json", type: "AdaptiveCard", }; const actions = []; switch (cardType) { case "basic": if (basicActionTitle && basicActionUrl) { actions.push({ type: "Action.OpenUrl", title: basicActionTitle, url: basicActionUrl }); } adaptiveCard = Object.assign(Object.assign({}, basicCardData), { body: [ { type: "TextBlock", size: "default", weight: "bolder", text: title, }, { type: "TextBlock", spacing: "None", text: subtitle, isSubtle: true, wrap: true }, basicImage ? { type: "Image", url: basicImage } : {}, { type: "TextBlock", text: body, wrap: true }, { type: "ActionSet", actions } ] }); break; case "suggested": suggestedActionTitles.forEach((title) => { if (title) { actions.push({ type: "Action.Execute", title }); } }); adaptiveCard = Object.assign(Object.assign({}, basicCardData), { body: [ { type: "TextBlock", size: "default", weight: "bolder", text: title, }, { type: "TextBlock", spacing: "None", text: subtitle, isSubtle: true, wrap: true }, { type: "TextBlock", text: body, wrap: true }, { type: "ActionSet", actions } ] }); break; case "table": /** * @example * { * title: "Key1", * value: "Value 1", * } */ const facts = Object.keys(tableFacts).map(key => { return { "title": key, "value": tableFacts[key] }; }); adaptiveCard = Object.assign(Object.assign({}, basicCardData), { body: [ { type: "TextBlock", size: "default", weight: "bolder", text: title, }, { type: "TextBlock", spacing: "None", text: subtitle, isSubtle: true, wrap: true }, { type: "FactSet", facts }, ] }); break; case "custom": adaptiveCard = customJson; break; default: throw new Error(`Unknown card type: ${cardType}`); } return { _cognigy: { _whisperAssist: { cardType, adaptiveCard } } }; }; exports.buildCognigyWhisperAssistResponse = buildCognigyWhisperAssistResponse; //# sourceMappingURL=buildCognigyWhisperAssistResponse.js.map