@botonic/plugin-flow-builder
Version:
Botonic plugin for **Hubtype Flow Builder**: run and bridge flow-driven logic from bots on the **current** line.
67 lines • 3.72 kB
JavaScript
import { __awaiter } from "tslib";
import { FlowAiAgent } from '../content-fields';
import { getFlowBuilderActionContext } from './context';
import { getContentsByFirstInteraction } from './first-interaction';
import { getContents } from './get-contents';
export class FlowBuilderAction {
static executeConversationStart(botonicContext) {
return __awaiter(this, void 0, void 0, function* () {
const fbContext = getFlowBuilderActionContext(botonicContext);
const contents = yield getContentsByFirstInteraction(fbContext);
const filteredContents = yield FlowBuilderAction.prepareContents(botonicContext, contents);
for (const content of filteredContents) {
// TODO: now toBotonic function is async and receives botonicContext as parameter,
// in a future PR refactor to resolve inside tracking, bot actions handoff and send messages
const message = yield content.toBotonic(botonicContext);
if (Array.isArray(message)) {
yield botonicContext.sendMessages(message);
}
else if (message) {
yield botonicContext.sendMessages([message]);
}
}
// TODO:Add for testing purposes, we can create a mock for botonicContext.sendMessages function
// and check messages sent by plugin-flow-builder instead of contents returned by this function
return filteredContents;
});
}
static botonicInit(botonicContext, contentID) {
return __awaiter(this, void 0, void 0, function* () {
const contents = yield getContents(botonicContext, contentID);
const filteredContents = yield FlowBuilderAction.prepareContents(botonicContext, contents);
for (const content of filteredContents) {
// TODO: now toBotonic function is async and receives botonicContext as parameter,
// in a future PR refactor to resolve inside tracking, bot actions handoff and send messages
const message = yield content.toBotonic(botonicContext);
// when is a content from an ai agent, toBotonic function can return an array of messages
// TODO: Rethink if we can send the messages from the action or we can send each message inside the toBotonic function
if (Array.isArray(message)) {
yield botonicContext.sendMessages(message);
}
else if (message) {
yield botonicContext.sendMessages([message]);
}
}
// TODO:Add for testing purposes, we can create a mock for botonicContext.sendMessages function
// and check messages sent by plugin-flow-builder instead of contents returned by this function
return filteredContents;
});
}
static prepareContents(botonicContext, contents) {
return __awaiter(this, void 0, void 0, function* () {
const processedContents = [];
for (const content of contents) {
let processedContent;
if (content instanceof FlowAiAgent) {
processedContent = yield content.processContent(botonicContext, processedContents.slice());
}
else {
processedContent = yield content.processContent(botonicContext);
}
processedContents.push(processedContent !== null && processedContent !== void 0 ? processedContent : content);
}
return processedContents;
});
}
}
//# sourceMappingURL=index.js.map