@botonic/plugin-flow-builder 0.27.5 → 0.27.7-alpha.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.
Files changed (49) hide show
  1. package/lib/cjs/action/first-interaction.d.ts +3 -0
  2. package/lib/cjs/action/first-interaction.js +72 -0
  3. package/lib/cjs/action/first-interaction.js.map +1 -0
  4. package/lib/cjs/action/index.js +10 -16
  5. package/lib/cjs/action/index.js.map +1 -1
  6. package/lib/cjs/action/knowledge-bases.js +7 -16
  7. package/lib/cjs/action/knowledge-bases.js.map +1 -1
  8. package/lib/cjs/action/payload.d.ts +3 -0
  9. package/lib/cjs/action/payload.js +17 -0
  10. package/lib/cjs/action/payload.js.map +1 -0
  11. package/lib/cjs/index.js +1 -3
  12. package/lib/cjs/index.js.map +1 -1
  13. package/lib/cjs/tracking.d.ts +0 -14
  14. package/lib/cjs/tracking.js +13 -14
  15. package/lib/cjs/tracking.js.map +1 -1
  16. package/lib/cjs/user-input/index.js +17 -5
  17. package/lib/cjs/user-input/index.js.map +1 -1
  18. package/lib/cjs/utils.d.ts +2 -1
  19. package/lib/cjs/utils.js +6 -1
  20. package/lib/cjs/utils.js.map +1 -1
  21. package/lib/esm/action/first-interaction.d.ts +3 -0
  22. package/lib/esm/action/first-interaction.js +68 -0
  23. package/lib/esm/action/first-interaction.js.map +1 -0
  24. package/lib/esm/action/index.js +9 -15
  25. package/lib/esm/action/index.js.map +1 -1
  26. package/lib/esm/action/knowledge-bases.js +7 -16
  27. package/lib/esm/action/knowledge-bases.js.map +1 -1
  28. package/lib/esm/action/payload.d.ts +3 -0
  29. package/lib/esm/action/payload.js +13 -0
  30. package/lib/esm/action/payload.js.map +1 -0
  31. package/lib/esm/index.js +2 -4
  32. package/lib/esm/index.js.map +1 -1
  33. package/lib/esm/tracking.d.ts +0 -14
  34. package/lib/esm/tracking.js +13 -13
  35. package/lib/esm/tracking.js.map +1 -1
  36. package/lib/esm/user-input/index.js +17 -5
  37. package/lib/esm/user-input/index.js.map +1 -1
  38. package/lib/esm/utils.d.ts +2 -1
  39. package/lib/esm/utils.js +4 -0
  40. package/lib/esm/utils.js.map +1 -1
  41. package/package.json +2 -2
  42. package/src/action/first-interaction.ts +111 -0
  43. package/src/action/index.tsx +9 -22
  44. package/src/action/knowledge-bases.ts +9 -16
  45. package/src/action/payload.ts +20 -0
  46. package/src/index.ts +2 -3
  47. package/src/tracking.ts +13 -13
  48. package/src/user-input/index.ts +21 -6
  49. package/src/utils.ts +5 -1
package/src/tracking.ts CHANGED
@@ -37,19 +37,20 @@ export async function trackFlowContent(
37
37
  ) {
38
38
  const flowBuilderPlugin = getFlowBuilderPlugin(request.plugins)
39
39
  const cmsApi = flowBuilderPlugin.cmsApi
40
- const firstNodeContent = cmsApi.getNodeById<HtNodeWithContent>(contents[0].id)
41
- const flowName = flowBuilderPlugin.getFlowName(firstNodeContent.flow_id)
42
- const eventArgs = getContentEventArgs(request, {
43
- code: firstNodeContent.code,
44
- flowId: firstNodeContent.flow_id,
45
- flowName,
46
- id: firstNodeContent.id,
47
- isMeaningful: firstNodeContent.is_meaningful ?? false,
48
- })
49
- await trackEvent(request, EventAction.FlowNode, eventArgs)
40
+ for (const content of contents) {
41
+ const nodeContent = cmsApi.getNodeById<HtNodeWithContent>(content.id)
42
+ const eventArgs = getContentEventArgs(request, {
43
+ code: nodeContent.code,
44
+ flowId: nodeContent.flow_id,
45
+ flowName: flowBuilderPlugin.getFlowName(nodeContent.flow_id),
46
+ id: nodeContent.id,
47
+ isMeaningful: nodeContent.is_meaningful ?? false,
48
+ })
49
+ await trackEvent(request, EventAction.FlowNode, eventArgs)
50
+ }
50
51
  }
51
52
 
52
- export function getContentEventArgs(
53
+ function getContentEventArgs(
53
54
  request: ActionRequest,
54
55
  contentInfo: {
55
56
  code: string
@@ -59,12 +60,11 @@ export function getContentEventArgs(
59
60
  isMeaningful: boolean
60
61
  }
61
62
  ) {
62
- const flowBuilderPlugin = getFlowBuilderPlugin(request.plugins)
63
63
  const flowThreadId = request.session.flow_thread_id ?? uuid()
64
64
  return {
65
65
  flowThreadId,
66
66
  flowId: contentInfo.flowId,
67
- flowName: flowBuilderPlugin.getFlowName(contentInfo.flowId),
67
+ flowName: contentInfo.flowName,
68
68
  flowNodeId: contentInfo.id,
69
69
  flowNodeContentId: contentInfo.code,
70
70
  flowNodeIsMeaningful: contentInfo.isMeaningful,
@@ -7,6 +7,7 @@ import {
7
7
  HtKeywordNode,
8
8
  HtSmartIntentNode,
9
9
  } from '../content-fields/hubtype-fields'
10
+ import { inputHasTextData } from '../utils'
10
11
  import { getIntentNodeByInput } from './intent'
11
12
  import { KeywordMatcher } from './keyword'
12
13
  import { SmartIntentsApi, SmartIntentsInferenceConfig } from './smart-intent'
@@ -17,25 +18,39 @@ export async function getNodeByUserInput(
17
18
  request: ActionRequest,
18
19
  smartIntentsConfig: SmartIntentsInferenceConfig
19
20
  ): Promise<HtSmartIntentNode | HtIntentNode | HtKeywordNode | undefined> {
20
- if (request.input.data && request.input.type === INPUT.TEXT) {
21
+ if (inputHasTextData(request.input)) {
21
22
  const keywordMatcher = new KeywordMatcher({
22
23
  cmsApi,
23
24
  locale,
24
25
  request,
25
26
  })
26
- const keywordNode = await keywordMatcher.getNodeByInput(request.input.data)
27
- if (keywordNode) return keywordNode
28
-
27
+ const keywordNode = await keywordMatcher.getNodeByInput(request.input.data!)
28
+ if (keywordNode) {
29
+ console.log('Keyword node found:', keywordNode.content.title, {
30
+ keywordNode,
31
+ })
32
+ return keywordNode
33
+ }
29
34
  const smartIntentsApi = new SmartIntentsApi(
30
35
  cmsApi,
31
36
  request,
32
37
  smartIntentsConfig
33
38
  )
34
39
  const smartIntentNode = await smartIntentsApi.getNodeByInput()
35
- if (smartIntentNode) return smartIntentNode
40
+ if (smartIntentNode) {
41
+ console.log('Smart intent node found:', smartIntentNode.content.title, {
42
+ smartIntentNode,
43
+ })
44
+ return smartIntentNode
45
+ }
36
46
 
37
47
  const intentNode = await getIntentNodeByInput(cmsApi, locale, request)
38
- if (intentNode) return intentNode
48
+ if (intentNode) {
49
+ console.log('Intent node found:', intentNode.content.title, {
50
+ intentNode,
51
+ })
52
+ return intentNode
53
+ }
39
54
  }
40
55
  return undefined
41
56
  }
package/src/utils.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Session } from '@botonic/core'
1
+ import { INPUT, Input, Session } from '@botonic/core'
2
2
  import { ActionRequest } from '@botonic/react'
3
3
 
4
4
  import { BotonicPluginFlowBuilderOptions, ProcessEnvNodeEnvs } from './types'
@@ -47,3 +47,7 @@ function resolveObjectKey(object: any, key: string): any {
47
47
  }
48
48
  return undefined
49
49
  }
50
+
51
+ export function inputHasTextData(input: Input): boolean {
52
+ return input.data !== undefined && input.type === INPUT.TEXT
53
+ }