Skip to content

Commit

Permalink
refactor(plugin-flow-builder): use conditional outside updateBotActio…
Browse files Browse the repository at this point in the history
…nPayload function, and rename constant
  • Loading branch information
Iru89 committed May 8, 2024
1 parent 905fd0b commit 0903b96
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
4 changes: 2 additions & 2 deletions packages/botonic-plugin-flow-builder/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Input, PluginPreRequest } from '@botonic/core'
import axios from 'axios'

import {
BOT_ACTION_PAYLOAD_SEPARATOR,
BOT_ACTION_PAYLOAD_PREFIX,
REG_EXP_PATTERN,
SEPARATOR,
} from './constants'
Expand Down Expand Up @@ -213,7 +213,7 @@ export class FlowBuilderApi {
}

if (target.type === HtNodeWithoutContentType.BOT_ACTION) {
return `${BOT_ACTION_PAYLOAD_SEPARATOR}${target.id}`
return `${BOT_ACTION_PAYLOAD_PREFIX}${target.id}`
}

return target.id
Expand Down
2 changes: 1 addition & 1 deletion packages/botonic-plugin-flow-builder/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export const FLOW_BUILDER_API_URL_PROD =
'https://api.ent0.flowbuilder.prod.hubtype.com'
export const SEPARATOR = '|'
export const SOURCE_INFO_SEPARATOR = `${SEPARATOR}source_`
export const BOT_ACTION_PAYLOAD_SEPARATOR = `ba${SEPARATOR}`
export const BOT_ACTION_PAYLOAD_PREFIX = `ba${SEPARATOR}`
export const VARIABLE_PATTERN = /{([^}]+)}/g
export const ACCESS_TOKEN_VARIABLE_KEY = '_access_token'
export const REG_EXP_PATTERN = /^\/(.*)\/([gimyus]*)$/
21 changes: 11 additions & 10 deletions packages/botonic-plugin-flow-builder/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ActionRequest } from '@botonic/react'

import { FlowBuilderApi } from './api'
import {
BOT_ACTION_PAYLOAD_SEPARATOR,
BOT_ACTION_PAYLOAD_PREFIX,
FLOW_BUILDER_API_URL_PROD,
SEPARATOR,
SOURCE_INFO_SEPARATOR,
Expand Down Expand Up @@ -101,22 +101,23 @@ export default class BotonicPluginFlowBuilder implements Plugin {
request.input.payload = this.removeSourceSeparatorFromPayload(
request.input.payload
)
request.input.payload = this.updateBotActionPayload(request.input.payload)

if (request.input.payload.startsWith(BOT_ACTION_PAYLOAD_PREFIX)) {
request.input.payload = this.updateBotActionPayload(
request.input.payload
)
}
}
}

private removeSourceSeparatorFromPayload(payload: string): string {
return payload?.split(SOURCE_INFO_SEPARATOR)[0]
return payload.split(SOURCE_INFO_SEPARATOR)[0]
}

private updateBotActionPayload(payload: string): string {
if (payload.startsWith(BOT_ACTION_PAYLOAD_SEPARATOR)) {
const botActionId = payload.split(SEPARATOR)[1]
const botActionNode =
this.cmsApi.getNodeById<HtBotActionNode>(botActionId)
return this.cmsApi.createPayloadWithParams(botActionNode)
}
return payload
const botActionId = payload.split(SEPARATOR)[1]
const botActionNode = this.cmsApi.getNodeById<HtBotActionNode>(botActionId)
return this.cmsApi.createPayloadWithParams(botActionNode)
}

async getContentsByContentID(
Expand Down

0 comments on commit 0903b96

Please sign in to comment.