@botonic/plugin-flow-builder 0.35.0-alpha.0 → 0.35.0-alpha.1
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/fallback.d.ts +1 -1
- package/lib/cjs/action/fallback.js +2 -2
- package/lib/cjs/action/fallback.js.map +1 -1
- package/lib/cjs/action/first-interaction.js +5 -5
- package/lib/cjs/action/first-interaction.js.map +1 -1
- package/lib/cjs/action/index.js +1 -2
- package/lib/cjs/action/index.js.map +1 -1
- package/lib/cjs/action/knowledge-bases.d.ts +1 -1
- package/lib/cjs/action/knowledge-bases.js +2 -2
- package/lib/cjs/action/knowledge-bases.js.map +1 -1
- package/lib/cjs/action/payload.d.ts +1 -1
- package/lib/cjs/action/payload.js +2 -2
- package/lib/cjs/action/payload.js.map +1 -1
- package/lib/cjs/api.d.ts +4 -1
- package/lib/cjs/api.js +20 -2
- package/lib/cjs/api.js.map +1 -1
- package/lib/cjs/content-fields/flow-handoff.js +2 -2
- package/lib/cjs/content-fields/flow-handoff.js.map +1 -1
- package/lib/cjs/functions/conditional-country.js +1 -1
- package/lib/cjs/functions/conditional-country.js.map +1 -1
- package/lib/cjs/index.d.ts +4 -5
- package/lib/cjs/index.js +13 -21
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/types.d.ts +1 -2
- package/lib/cjs/types.js.map +1 -1
- package/lib/esm/action/fallback.d.ts +1 -1
- package/lib/esm/action/fallback.js +2 -2
- package/lib/esm/action/fallback.js.map +1 -1
- package/lib/esm/action/first-interaction.js +5 -5
- package/lib/esm/action/first-interaction.js.map +1 -1
- package/lib/esm/action/index.js +1 -2
- package/lib/esm/action/index.js.map +1 -1
- package/lib/esm/action/knowledge-bases.d.ts +1 -1
- package/lib/esm/action/knowledge-bases.js +2 -2
- package/lib/esm/action/knowledge-bases.js.map +1 -1
- package/lib/esm/action/payload.d.ts +1 -1
- package/lib/esm/action/payload.js +2 -2
- package/lib/esm/action/payload.js.map +1 -1
- package/lib/esm/api.d.ts +4 -1
- package/lib/esm/api.js +20 -2
- package/lib/esm/api.js.map +1 -1
- package/lib/esm/content-fields/flow-handoff.js +2 -2
- package/lib/esm/content-fields/flow-handoff.js.map +1 -1
- package/lib/esm/functions/conditional-country.js +1 -1
- package/lib/esm/functions/conditional-country.js.map +1 -1
- package/lib/esm/index.d.ts +4 -5
- package/lib/esm/index.js +13 -21
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/types.d.ts +1 -2
- package/lib/esm/types.js.map +1 -1
- package/package.json +2 -2
- package/src/action/fallback.ts +2 -5
- package/src/action/first-interaction.ts +3 -6
- package/src/action/index.tsx +1 -2
- package/src/action/knowledge-bases.ts +1 -3
- package/src/action/payload.ts +1 -2
- package/src/api.ts +24 -3
- package/src/content-fields/flow-handoff.tsx +2 -2
- package/src/functions/conditional-country.ts +1 -1
- package/src/index.ts +11 -22
- package/src/types.ts +0 -1
package/src/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
BotContext,
|
|
2
3
|
Plugin,
|
|
3
4
|
PluginPreRequest,
|
|
4
5
|
ResolvedPlugins,
|
|
@@ -56,7 +57,6 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
56
57
|
private functions: Record<any, any>
|
|
57
58
|
private currentRequest: PluginPreRequest
|
|
58
59
|
public getAccessToken: (session: Session) => string
|
|
59
|
-
public getLocale: (session: Session) => string
|
|
60
60
|
public trackEvent?: TrackEventFunction
|
|
61
61
|
public getKnowledgeBaseResponse?: KnowledgeBaseFunction
|
|
62
62
|
public smartIntentsConfig: SmartIntentsInferenceConfig
|
|
@@ -70,12 +70,6 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
70
70
|
this.apiUrl = options.apiUrl || FLOW_BUILDER_API_URL_PROD
|
|
71
71
|
this.jsonVersion = options.jsonVersion || FlowBuilderJSONVersion.LATEST
|
|
72
72
|
this.flow = options.flow
|
|
73
|
-
this.getLocale =
|
|
74
|
-
typeof options.getLocale === 'function'
|
|
75
|
-
? options.getLocale
|
|
76
|
-
: (session: Session) => {
|
|
77
|
-
return session.user.system_locale
|
|
78
|
-
}
|
|
79
73
|
this.getAccessToken = resolveGetAccessToken(options.getAccessToken)
|
|
80
74
|
this.trackEvent = options.trackEvent
|
|
81
75
|
this.getKnowledgeBaseResponse = options.getKnowledgeBaseResponse
|
|
@@ -113,8 +107,7 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
113
107
|
inputHasTextData(request.input) && !request.input.payload
|
|
114
108
|
|
|
115
109
|
if (checkUserTextInput) {
|
|
116
|
-
const
|
|
117
|
-
const resolvedLocale = this.cmsApi.getResolvedLocale(locale)
|
|
110
|
+
const resolvedLocale = this.cmsApi.getResolvedLocale()
|
|
118
111
|
const nodeByUserInput = await getNodeByUserInput(
|
|
119
112
|
this.cmsApi,
|
|
120
113
|
resolvedLocale,
|
|
@@ -129,7 +122,7 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
129
122
|
|
|
130
123
|
private updateRequestBeforeRoutes(request: PluginPreRequest): void {
|
|
131
124
|
if (request.input.payload) {
|
|
132
|
-
request.input.payload = this.
|
|
125
|
+
request.input.payload = this.removeSourceSuffix(request.input.payload)
|
|
133
126
|
|
|
134
127
|
if (this.cmsApi.isBotAction(request.input.payload)) {
|
|
135
128
|
const cmsBotAction = this.cmsApi.getNodeById<HtBotActionNode>(
|
|
@@ -142,7 +135,7 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
142
135
|
}
|
|
143
136
|
}
|
|
144
137
|
|
|
145
|
-
private
|
|
138
|
+
private removeSourceSuffix(payload: string): string {
|
|
146
139
|
return payload.split(SOURCE_INFO_SEPARATOR)[0]
|
|
147
140
|
}
|
|
148
141
|
|
|
@@ -152,11 +145,10 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
152
145
|
|
|
153
146
|
async getContentsByContentID(
|
|
154
147
|
contentID: string,
|
|
155
|
-
locale: string,
|
|
156
148
|
prevContents?: FlowContent[]
|
|
157
149
|
): Promise<FlowContent[]> {
|
|
158
150
|
const node = this.cmsApi.getNodeByContentID(contentID) as HtNodeWithContent
|
|
159
|
-
return await this.getContentsByNode(node,
|
|
151
|
+
return await this.getContentsByNode(node, prevContents)
|
|
160
152
|
}
|
|
161
153
|
|
|
162
154
|
getUUIDByContentID(contentID: string): string {
|
|
@@ -166,31 +158,28 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
166
158
|
|
|
167
159
|
private async getContentsById(
|
|
168
160
|
id: string,
|
|
169
|
-
locale: string,
|
|
170
161
|
prevContents?: FlowContent[]
|
|
171
162
|
): Promise<FlowContent[]> {
|
|
172
163
|
const node = this.cmsApi.getNodeById(id) as HtNodeWithContent
|
|
173
|
-
return await this.getContentsByNode(node,
|
|
164
|
+
return await this.getContentsByNode(node, prevContents)
|
|
174
165
|
}
|
|
175
166
|
|
|
176
|
-
async getStartContents(
|
|
177
|
-
const resolvedLocale = this.cmsApi.getResolvedLocale(locale)
|
|
167
|
+
async getStartContents(): Promise<FlowContent[]> {
|
|
178
168
|
const startNode = this.cmsApi.getStartNode()
|
|
179
169
|
this.currentRequest.session.flow_thread_id = uuidv7()
|
|
180
|
-
return await this.getContentsByNode(startNode
|
|
170
|
+
return await this.getContentsByNode(startNode)
|
|
181
171
|
}
|
|
182
172
|
|
|
183
173
|
async getContentsByNode(
|
|
184
174
|
node: HtNodeWithContent,
|
|
185
|
-
locale: string,
|
|
186
175
|
prevContents?: FlowContent[]
|
|
187
176
|
): Promise<FlowContent[]> {
|
|
188
177
|
const contents = prevContents || []
|
|
189
|
-
const resolvedLocale = this.cmsApi.getResolvedLocale(
|
|
178
|
+
const resolvedLocale = this.cmsApi.getResolvedLocale()
|
|
190
179
|
|
|
191
180
|
if (node.type === HtNodeWithContentType.FUNCTION) {
|
|
192
181
|
const targetId = await this.callFunction(node, resolvedLocale)
|
|
193
|
-
return this.getContentsById(targetId,
|
|
182
|
+
return this.getContentsById(targetId, contents)
|
|
194
183
|
}
|
|
195
184
|
|
|
196
185
|
const content = this.getFlowContent(node, resolvedLocale)
|
|
@@ -205,7 +194,7 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
205
194
|
|
|
206
195
|
// TODO: prevent infinite recursive calls
|
|
207
196
|
if (node.follow_up) {
|
|
208
|
-
return this.getContentsById(node.follow_up.id,
|
|
197
|
+
return this.getContentsById(node.follow_up.id, contents)
|
|
209
198
|
}
|
|
210
199
|
|
|
211
200
|
return contents
|
package/src/types.ts
CHANGED
|
@@ -21,7 +21,6 @@ export interface BotonicPluginFlowBuilderOptions<
|
|
|
21
21
|
jsonVersion?: FlowBuilderJSONVersion
|
|
22
22
|
flow?: HtFlowBuilderData
|
|
23
23
|
customFunctions?: Record<any, any>
|
|
24
|
-
getLocale?: (session: Session) => string
|
|
25
24
|
getAccessToken: () => string
|
|
26
25
|
trackEvent?: TrackEventFunction<TPlugins, TExtraData>
|
|
27
26
|
getKnowledgeBaseResponse?: KnowledgeBaseFunction<TPlugins, TExtraData>
|