@botonic/plugin-flow-builder 0.22.6-alpha.1 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/action/index.js +7 -32
- package/lib/cjs/action/index.js.map +1 -1
- package/lib/cjs/action/intent.js +7 -11
- package/lib/cjs/action/intent.js.map +1 -1
- package/lib/cjs/action/keyword.js +3 -7
- package/lib/cjs/action/keyword.js.map +1 -1
- package/lib/cjs/action/tracking.d.ts +16 -2
- package/lib/cjs/action/tracking.js +19 -3
- package/lib/cjs/action/tracking.js.map +1 -1
- package/lib/cjs/action/user-input.js +1 -5
- package/lib/cjs/action/user-input.js.map +1 -1
- package/lib/cjs/api.d.ts +2 -1
- package/lib/cjs/api.js +1 -0
- package/lib/cjs/api.js.map +1 -1
- package/lib/cjs/content-fields/flow-handoff.js +6 -9
- package/lib/cjs/content-fields/flow-handoff.js.map +1 -1
- package/lib/cjs/content-fields/flow-text.d.ts +1 -0
- package/lib/cjs/content-fields/flow-text.js +15 -1
- package/lib/cjs/content-fields/flow-text.js.map +1 -1
- package/lib/cjs/index.d.ts +2 -0
- package/lib/cjs/index.js +2 -0
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/types.d.ts +2 -1
- package/lib/cjs/types.js.map +1 -1
- package/lib/esm/action/index.js +10 -35
- package/lib/esm/action/index.js.map +1 -1
- package/lib/esm/action/intent.js +8 -12
- package/lib/esm/action/intent.js.map +1 -1
- package/lib/esm/action/keyword.js +4 -8
- package/lib/esm/action/keyword.js.map +1 -1
- package/lib/esm/action/tracking.d.ts +16 -2
- package/lib/esm/action/tracking.js +18 -2
- package/lib/esm/action/tracking.js.map +1 -1
- package/lib/esm/action/user-input.js +2 -6
- package/lib/esm/action/user-input.js.map +1 -1
- package/lib/esm/api.d.ts +2 -1
- package/lib/esm/api.js +1 -0
- package/lib/esm/api.js.map +1 -1
- package/lib/esm/content-fields/flow-handoff.js +7 -10
- package/lib/esm/content-fields/flow-handoff.js.map +1 -1
- package/lib/esm/content-fields/flow-text.d.ts +1 -0
- package/lib/esm/content-fields/flow-text.js +15 -1
- package/lib/esm/content-fields/flow-text.js.map +1 -1
- package/lib/esm/index.d.ts +2 -0
- package/lib/esm/index.js +2 -0
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/types.d.ts +2 -1
- package/lib/esm/types.js.map +1 -1
- package/package.json +2 -3
- package/src/action/index.tsx +10 -46
- package/src/action/intent.ts +9 -16
- package/src/action/keyword.ts +4 -11
- package/src/action/tracking.ts +22 -3
- package/src/action/user-input.ts +2 -9
- package/src/api.ts +3 -1
- package/src/content-fields/flow-handoff.tsx +8 -14
- package/src/content-fields/flow-text.tsx +23 -1
- package/src/index.ts +3 -0
- package/src/types.ts +2 -1
|
@@ -2,6 +2,7 @@ import { Text } from '@botonic/react'
|
|
|
2
2
|
import React from 'react'
|
|
3
3
|
|
|
4
4
|
import { FlowBuilderApi } from '../api'
|
|
5
|
+
import { VARIABLE_REGEX } from '../constants'
|
|
5
6
|
import { ContentFieldsBase } from './content-fields-base'
|
|
6
7
|
import { FlowButton } from './flow-button'
|
|
7
8
|
import { HtButtonStyle, HtTextNode } from './hubtype-fields'
|
|
@@ -20,13 +21,34 @@ export class FlowText extends ContentFieldsBase {
|
|
|
20
21
|
const newText = new FlowText(cmsText.id)
|
|
21
22
|
newText.code = cmsText.code
|
|
22
23
|
newText.buttonStyle = cmsText.content.buttons_style || HtButtonStyle.BUTTON
|
|
23
|
-
newText.text = this.
|
|
24
|
+
newText.text = this.replaceVariables(
|
|
25
|
+
this.getTextByLocale(locale, cmsText.content.text),
|
|
26
|
+
cmsApi.request.session.user.extra_data
|
|
27
|
+
)
|
|
24
28
|
newText.buttons = cmsText.content.buttons.map(button =>
|
|
25
29
|
FlowButton.fromHubtypeCMS(button, locale, cmsApi)
|
|
26
30
|
)
|
|
27
31
|
return newText
|
|
28
32
|
}
|
|
29
33
|
|
|
34
|
+
static replaceVariables(
|
|
35
|
+
text: string,
|
|
36
|
+
extraData?: Record<string, any>
|
|
37
|
+
): string {
|
|
38
|
+
const matches = text.match(VARIABLE_REGEX)
|
|
39
|
+
|
|
40
|
+
let replacedText = text
|
|
41
|
+
if (matches && extraData) {
|
|
42
|
+
matches.forEach(match => {
|
|
43
|
+
const variable = match.slice(1, -1)
|
|
44
|
+
const value = extraData[variable] ?? match
|
|
45
|
+
replacedText = replacedText.replace(match, value)
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return replacedText
|
|
50
|
+
}
|
|
51
|
+
|
|
30
52
|
toBotonic(id: string): JSX.Element {
|
|
31
53
|
return (
|
|
32
54
|
<Text key={id}>
|
package/src/index.ts
CHANGED
|
@@ -52,6 +52,7 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
52
52
|
url: this.flowUrl,
|
|
53
53
|
flow: this.flow,
|
|
54
54
|
accessToken: this.getAccessToken(request.session),
|
|
55
|
+
request: this.currentRequest,
|
|
55
56
|
})
|
|
56
57
|
}
|
|
57
58
|
|
|
@@ -152,3 +153,5 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
152
153
|
}
|
|
153
154
|
|
|
154
155
|
export * from './action'
|
|
156
|
+
export * from './content-fields'
|
|
157
|
+
export { BotonicPluginFlowBuilderOptions } from './types'
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Session } from '@botonic/core'
|
|
1
|
+
import { PluginPreRequest, Session } from '@botonic/core'
|
|
2
2
|
import { ActionRequest } from '@botonic/react'
|
|
3
3
|
|
|
4
4
|
import { HtFlowBuilderData } from './content-fields/hubtype-fields'
|
|
@@ -20,6 +20,7 @@ export interface FlowBuilderApiOptions {
|
|
|
20
20
|
url: string
|
|
21
21
|
flow?: HtFlowBuilderData
|
|
22
22
|
accessToken: string
|
|
23
|
+
request: PluginPreRequest
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
export enum ProcessEnvNodeEnvs {
|