Skip to content

Commit

Permalink
feat(plugin-flow-builder): create executeConversationStart to allow h…
Browse files Browse the repository at this point in the history
…andoffs and bot actions in welcome action
  • Loading branch information
Iru89 committed Nov 29, 2024
1 parent 6cbb7c6 commit 7f9386f
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions packages/botonic-plugin-flow-builder/src/action/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ export type FlowBuilderActionProps = {
export class FlowBuilderAction extends React.Component<FlowBuilderActionProps> {
static contextType = RequestContext

static async executeConversationStart(
request: ActionRequest
): Promise<FlowBuilderActionProps> {
const context = getContext(request)
const contents = await getContentsByFirstInteraction(context)
const contentID = contents[0]?.code
return await FlowBuilderAction.botonicInit(request, contentID)
}

static async botonicInit(
request: ActionRequest,
contentID?: string
Expand Down Expand Up @@ -67,17 +76,7 @@ async function getContents(
request: ActionRequest,
contentID?: string
): Promise<FlowContent[]> {
const flowBuilderPlugin = getFlowBuilderPlugin(request.plugins)
const cmsApi = flowBuilderPlugin.cmsApi
const locale = flowBuilderPlugin.getLocale(request.session)
const resolvedLocale = flowBuilderPlugin.cmsApi.getResolvedLocale(locale)
const context = {
cmsApi,
flowBuilderPlugin,
request,
resolvedLocale,
contentID,
}
const context = getContext(request, contentID)

if (request.session.is_first_interaction) {
return await getContentsByFirstInteraction(context)
Expand Down Expand Up @@ -109,3 +108,20 @@ export interface FlowBuilderContext {
resolvedLocale: string
contentID?: string
}

function getContext(
request: ActionRequest,
contentID?: string
): FlowBuilderContext {
const flowBuilderPlugin = getFlowBuilderPlugin(request.plugins)
const cmsApi = flowBuilderPlugin.cmsApi
const locale = flowBuilderPlugin.getLocale(request.session)
const resolvedLocale = flowBuilderPlugin.cmsApi.getResolvedLocale(locale)
return {
cmsApi,
flowBuilderPlugin,
request,
resolvedLocale,
contentID,
}
}

0 comments on commit 7f9386f

Please sign in to comment.