UNPKG

@botonic/core

Version:

Runtime and APIs for Botonic bots: actions, context, messaging, and integration hooks used by the **current** framework line.

51 lines 2.17 kB
import { __awaiter } from "tslib"; import { parseUpdateWebchatClientSettingsPayload, } from '@botonic/shared'; import { BotServerMessageFactory } from '../server'; function isSettingsPatch(value) { return (typeof value === 'object' && value !== null && !Array.isArray(value) && Object.keys(value).length > 0); } function mergeSettingsPatch(current, patch) { var _a, _b, _c, _d, _e; return { block_inputs: (_a = patch.block_inputs) !== null && _a !== void 0 ? _a : current.block_inputs, user_input_enabled: (_b = patch.user_input_enabled) !== null && _b !== void 0 ? _b : current.user_input_enabled, attachments_enabled: (_c = patch.attachments_enabled) !== null && _c !== void 0 ? _c : current.attachments_enabled, emoji_picker_enabled: (_d = patch.emoji_picker_enabled) !== null && _d !== void 0 ? _d : current.emoji_picker_enabled, custom: Object.assign(Object.assign({}, current.custom), ((_e = patch.custom) !== null && _e !== void 0 ? _e : {})), }; } export function updateWebchatClientSettingsAction(botonicContext) { return __awaiter(this, void 0, void 0, function* () { const payload = botonicContext.input.payload; if (!payload) { return { status: 400, response: 'No payload', }; } const { settings } = parseUpdateWebchatClientSettingsPayload(payload); if (!isSettingsPatch(settings)) { return { status: 400, response: 'No settings to update', }; } const mergedSettings = mergeSettingsPatch(botonicContext.session.webchatClientSettings, settings); yield botonicContext.updateBotSession({ webchatClientSettings: mergedSettings, }); yield botonicContext.sendMessages([ BotServerMessageFactory.createWebchatClientSettings({ settings: mergedSettings, }), ], { typingMode: false }); return { status: 200, response: 'OK', }; }); } //# sourceMappingURL=update-webchat-client-settings.js.map