UNPKG

@botonic/core

Version:

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

33 lines 1.06 kB
import { TypingEventName } from '@botonic/shared'; import { BotServerMessageFactory } from '../factory'; const DEFAULT_TYPING_DELAY = 1; function typingEvent() { return BotServerMessageFactory.createTypingEvent({ eventName: TypingEventName.TypingOn, }); } function withDefaultDelay(msg) { if (msg.delay !== undefined) return msg; const clone = Object.create(Object.getPrototypeOf(msg)); return Object.assign(clone, msg, { delay: DEFAULT_TYPING_DELAY }); } export function injectTypingEvents(messages, mode) { if (!mode || messages.length === 0) return messages; if (mode === 'onlyFirst') { const [first, ...rest] = messages; return [typingEvent(), withDefaultDelay(first), ...rest]; } return messages.reduce((acc, msg, index) => { if (index > 0) { acc.push(typingEvent()); acc.push(withDefaultDelay(msg)); } else { acc.push(msg); } return acc; }, []); } //# sourceMappingURL=send-messages-utils.js.map