UNPKG

umbot

Version:

Мультиплатформенный фреймворк для создания голосовых навыков и чат-ботов с единой бизнес-логикой. Встроенная поддержка ВКонтакте, Telegram, Viber, MAX, Яндекс Алисы, Маруси и Сбера SmartApp. Архитектура на адаптерах позволяет подключать любые другие платф

167 lines (166 loc) 4.89 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.cardProcessing = cardProcessing; const Button_1 = require("./Button"); function buttonCardProcessing(buttons) { return (0, Button_1.buttonProcessing)(buttons, true); } function getOneElement(image) { const res = []; if (image.imageDir) { res.push({ type: 'image_cell_view', content: { url: image.imageDir, }, }); } if (image.title) { res.push({ type: 'text_cell_view', paddings: { top: '6x', left: '8x', right: '8x', }, content: { text: image.title, typeface: image.params.titleTypeface || 'title1', text_color: image.params.titleText_color || 'default', }, }); } if (image.desc) { res.push({ type: 'text_cell_view', paddings: { top: '4x', left: '8x', right: '8x', }, content: { text: image.desc, typeface: image.params.descTypeface || 'footnote1', text_color: image.params.descText_color || 'secondary', }, }); } const button = image.button?.getButtons(buttonCardProcessing); if (button) { res.push({ type: 'text_cell_view', paddings: { top: '12x', left: '8x', right: '8x', }, content: { actions: [button], text: button.text, typeface: 'button1', text_color: 'brand', }, }); } return res; } function getCardItem(image, showOne = false) { if (showOne) { return getOneElement(image); } const cardItem = { type: 'left_right_cell_view', paddings: { left: '4x', top: '4x', right: '4x', bottom: '4x', }, left: { type: 'fast_answer_left_view', icon_vertical_gravity: 'top', icon_and_value: { value: { text: image.desc, typeface: image.params.descTypeface || 'body3', text_color: image.params.descText_color || 'default', max_lines: image.params.descMax_lines || 0, }, }, label: { text: image.title, typeface: image.params.titleTypeface || 'headline2', text_color: image.params.titleText_color || 'default', max_lines: image.params.titleMax_lines || 0, }, }, }; if (image.imageDir) { cardItem.left.icon_and_value.icon = { address: { type: 'url', url: image.imageDir, }, size: { width: 'xlarge', height: 'xlarge', }, margin: { left: '0x', right: '6x', }, }; } const button = image.button?.getButtons(buttonCardProcessing); if (button) { cardItem.bottom_text ??= { text: image.title, typeface: image.params.descTypeface || 'body3', text_color: image.params.descText_color || 'default', }; cardItem.bottom_text.actions = button; } return cardItem; } /** * Получает карточку для отображения в Сбер Салют (SmartApp). * @param cardInfo Информация о карточке */ function cardProcessing(cardInfo) { const countImage = cardInfo.images.length; if (countImage) { if (cardInfo.showOne) { const card = { type: 'list_card', }; card.cells = getCardItem(cardInfo.images[0], true); return { card }; } else { const card = { type: 'list_card', cells: [], }; if (cardInfo.title) { card.cells.push({ type: 'text_cell_view', paddings: { top: '4x', left: '2x', right: '2x', }, content: { text: cardInfo.title, typeface: 'title1', text_color: 'default', }, }); } cardInfo.images.forEach((image) => { card.cells.push(getCardItem(image)); }); return { card }; } } return null; }