@botonic/plugin-flow-builder 0.22.2 → 0.22.4-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 (108) hide show
  1. package/lib/cjs/{action.d.ts → action/index.d.ts} +1 -2
  2. package/lib/cjs/action/index.js +72 -0
  3. package/lib/cjs/action/index.js.map +1 -0
  4. package/lib/cjs/action/intent.d.ts +4 -0
  5. package/lib/cjs/action/intent.js +33 -0
  6. package/lib/cjs/action/intent.js.map +1 -0
  7. package/lib/cjs/action/keyword.d.ts +3 -0
  8. package/lib/cjs/action/keyword.js +21 -0
  9. package/lib/cjs/action/keyword.js.map +1 -0
  10. package/lib/cjs/action/tracking.d.ts +3 -0
  11. package/lib/cjs/action/tracking.js +13 -0
  12. package/lib/cjs/action/tracking.js.map +1 -0
  13. package/lib/cjs/action/user-input.d.ts +4 -0
  14. package/lib/cjs/action/user-input.js +28 -0
  15. package/lib/cjs/action/user-input.js.map +1 -0
  16. package/lib/cjs/api.d.ts +4 -4
  17. package/lib/cjs/api.js +4 -10
  18. package/lib/cjs/api.js.map +1 -1
  19. package/lib/cjs/content-fields/content-fields-base.d.ts +2 -1
  20. package/lib/cjs/content-fields/content-fields-base.js +3 -0
  21. package/lib/cjs/content-fields/content-fields-base.js.map +1 -1
  22. package/lib/cjs/content-fields/flow-handoff.d.ts +15 -0
  23. package/lib/cjs/content-fields/flow-handoff.js +60 -0
  24. package/lib/cjs/content-fields/flow-handoff.js.map +1 -0
  25. package/lib/cjs/content-fields/index.d.ts +3 -1
  26. package/lib/cjs/content-fields/index.js +3 -1
  27. package/lib/cjs/content-fields/index.js.map +1 -1
  28. package/lib/cjs/content-fields/whatsapp-button-list/flow-whatsapp-button-list-row.d.ts +1 -1
  29. package/lib/cjs/content-fields/whatsapp-button-list/flow-whatsapp-button-list-section.d.ts +1 -1
  30. package/lib/cjs/content-fields/whatsapp-button-list/flow-whatsapp-button-list.js +1 -4
  31. package/lib/cjs/content-fields/whatsapp-button-list/flow-whatsapp-button-list.js.map +1 -1
  32. package/lib/cjs/functions/conditional-queue-status.d.ts +10 -1
  33. package/lib/cjs/functions/conditional-queue-status.js +11 -16
  34. package/lib/cjs/functions/conditional-queue-status.js.map +1 -1
  35. package/lib/cjs/helpers.d.ts +0 -2
  36. package/lib/cjs/helpers.js +1 -6
  37. package/lib/cjs/helpers.js.map +1 -1
  38. package/lib/cjs/index.d.ts +5 -7
  39. package/lib/cjs/index.js +15 -11
  40. package/lib/cjs/index.js.map +1 -1
  41. package/lib/esm/{action.d.ts → action/index.d.ts} +1 -2
  42. package/lib/esm/action/index.js +66 -0
  43. package/lib/esm/action/index.js.map +1 -0
  44. package/lib/esm/action/intent.d.ts +4 -0
  45. package/lib/esm/action/intent.js +29 -0
  46. package/lib/esm/action/intent.js.map +1 -0
  47. package/lib/esm/action/keyword.d.ts +3 -0
  48. package/lib/esm/action/keyword.js +17 -0
  49. package/lib/esm/action/keyword.js.map +1 -0
  50. package/lib/esm/action/tracking.d.ts +3 -0
  51. package/lib/esm/action/tracking.js +9 -0
  52. package/lib/esm/action/tracking.js.map +1 -0
  53. package/lib/esm/action/user-input.d.ts +4 -0
  54. package/lib/esm/action/user-input.js +24 -0
  55. package/lib/esm/action/user-input.js.map +1 -0
  56. package/lib/esm/api.d.ts +4 -4
  57. package/lib/esm/api.js +4 -10
  58. package/lib/esm/api.js.map +1 -1
  59. package/lib/esm/content-fields/content-fields-base.d.ts +2 -1
  60. package/lib/esm/content-fields/content-fields-base.js +3 -0
  61. package/lib/esm/content-fields/content-fields-base.js.map +1 -1
  62. package/lib/esm/content-fields/flow-handoff.d.ts +15 -0
  63. package/lib/esm/content-fields/flow-handoff.js +55 -0
  64. package/lib/esm/content-fields/flow-handoff.js.map +1 -0
  65. package/lib/esm/content-fields/index.d.ts +3 -1
  66. package/lib/esm/content-fields/index.js +1 -0
  67. package/lib/esm/content-fields/index.js.map +1 -1
  68. package/lib/esm/content-fields/whatsapp-button-list/flow-whatsapp-button-list-row.d.ts +1 -1
  69. package/lib/esm/content-fields/whatsapp-button-list/flow-whatsapp-button-list-section.d.ts +1 -1
  70. package/lib/esm/content-fields/whatsapp-button-list/flow-whatsapp-button-list.js +1 -4
  71. package/lib/esm/content-fields/whatsapp-button-list/flow-whatsapp-button-list.js.map +1 -1
  72. package/lib/esm/functions/conditional-queue-status.d.ts +10 -1
  73. package/lib/esm/functions/conditional-queue-status.js +8 -14
  74. package/lib/esm/functions/conditional-queue-status.js.map +1 -1
  75. package/lib/esm/helpers.d.ts +0 -2
  76. package/lib/esm/helpers.js +0 -4
  77. package/lib/esm/helpers.js.map +1 -1
  78. package/lib/esm/index.d.ts +5 -7
  79. package/lib/esm/index.js +16 -12
  80. package/lib/esm/index.js.map +1 -1
  81. package/package.json +3 -2
  82. package/src/action/index.tsx +102 -0
  83. package/src/action/intent.ts +48 -0
  84. package/src/action/keyword.ts +28 -0
  85. package/src/action/tracking.ts +12 -0
  86. package/src/action/user-input.ts +40 -0
  87. package/src/api.ts +6 -14
  88. package/src/content-fields/content-fields-base.ts +8 -0
  89. package/src/content-fields/flow-handoff.tsx +106 -0
  90. package/src/content-fields/index.ts +3 -0
  91. package/src/content-fields/whatsapp-button-list/flow-whatsapp-button-list-row.tsx +1 -1
  92. package/src/content-fields/whatsapp-button-list/flow-whatsapp-button-list-section.tsx +1 -1
  93. package/src/content-fields/whatsapp-button-list/flow-whatsapp-button-list.tsx +2 -4
  94. package/src/functions/conditional-queue-status.ts +19 -16
  95. package/src/helpers.ts +0 -9
  96. package/src/index.ts +28 -20
  97. package/lib/cjs/action.js +0 -52
  98. package/lib/cjs/action.js.map +0 -1
  99. package/lib/cjs/handoff.d.ts +0 -3
  100. package/lib/cjs/handoff.js +0 -53
  101. package/lib/cjs/handoff.js.map +0 -1
  102. package/lib/esm/action.js +0 -46
  103. package/lib/esm/action.js.map +0 -1
  104. package/lib/esm/handoff.d.ts +0 -3
  105. package/lib/esm/handoff.js +0 -49
  106. package/lib/esm/handoff.js.map +0 -1
  107. package/src/action.tsx +0 -77
  108. package/src/handoff.ts +0 -76
@@ -1 +1 @@
1
- {"version":3,"file":"conditional-queue-status.js","sourceRoot":"","sources":["../../../src/functions/conditional-queue-status.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAE3C,MAAM,iBAAiB,GAAG,gBAAgB;AACxC,aAAa;AACb,OAAO,eAAe,KAAK,WAAW,IAAI,eAAe,EACzD,iBAAiB,EACjB,yBAAyB,CAC1B,CAAA;AAQD,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,EAC3C,OAAO,EACP,QAAQ,EACR,UAAU,GACiB;IAC3B,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAC9B,GAAG,iBAAiB,cAAc,QAAQ,gBAAgB;IAC1D,2CAA2C;IAC3C;QACE,MAAM,EAAE;YACN,oBAAoB,EAAE,IAAI;YAC1B,mBAAmB,EAAE,KAAK;YAC1B,sBAAsB,EAAE,KAAK;SAC9B;KACF,CACF,CAAA;IACD,MAAM,WAAW,GAAG,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAA;IAE3C,MAAM,iBAAiB,GAAG,oBAAoB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IAC/D,IAAI,iBAAiB,CAAC,UAAU,EAAE;QAChC,MAAM,SAAS,GAAG,SAAS,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAA;QAC5D,MAAM,IAAI,GAAG;YACX,QAAQ;YACR,UAAU;SACX,CAAA;QACD,MAAM,iBAAiB,CAAC,UAAU,CAAC,OAAO,EAAE,SAAS,EAAE,IAAI,CAAC,CAAA;KAC7D;IAED,OAAO,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAA;AACxC,CAAC"}
1
+ {"version":3,"file":"conditional-queue-status.js","sourceRoot":"","sources":["../../../src/functions/conditional-queue-status.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAE3C,MAAM,iBAAiB,GAAG,gBAAgB;AACxC,aAAa;AACb,OAAO,eAAe,KAAK,WAAW,IAAI,eAAe,EACzD,iBAAiB,EACjB,yBAAyB,CAC1B,CAAA;AAQD,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,EAC3C,QAAQ,GACmB;IAC3B,MAAM,IAAI,GAAG,MAAM,oBAAoB,CAAC,QAAQ,CAAC,CAAA;IACjD,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAA;IAClC,OAAO,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAA;AACxC,CAAC;AAWD,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,OAAe;IAEf,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAC9B,GAAG,iBAAiB,cAAc,OAAO,gBAAgB;IACzD,2CAA2C;IAC3C;QACE,MAAM,EAAE;YACN,oBAAoB,EAAE,IAAI;YAC1B,mBAAmB,EAAE,KAAK;YAC1B,sBAAsB,EAAE,KAAK;SAC9B;KACF,CACF,CAAA;IACD,OAAO,QAAQ,CAAC,IAAI,CAAA;AACtB,CAAC"}
@@ -1,7 +1,5 @@
1
1
  import { Plugin } from '@botonic/core';
2
- import { HtHandoffNode, HtNodeWithContent } from './content-fields/hubtype-fields';
3
2
  import BotonicPluginFlowBuilder from './index';
4
3
  export declare function getFlowBuilderPlugin(plugins: {
5
4
  [id: string]: Plugin;
6
5
  }): BotonicPluginFlowBuilder;
7
- export declare function isHandoffNode(node: HtNodeWithContent): node is HtHandoffNode;
@@ -1,4 +1,3 @@
1
- import { HtNodeWithContentType, } from './content-fields/hubtype-fields';
2
1
  const FLOW_BUILDER_PLUGIN_NAME = 'BotonicPluginFlowBuilder';
3
2
  export function getFlowBuilderPlugin(plugins) {
4
3
  const flowBuilderPlugin = Object.values(plugins).find(
@@ -8,7 +7,4 @@ export function getFlowBuilderPlugin(plugins) {
8
7
  throw new Error(`You must include '@botonic/plugin-flow-builder' in your plugins file.`);
9
8
  return flowBuilderPlugin;
10
9
  }
11
- export function isHandoffNode(node) {
12
- return node.type === HtNodeWithContentType.HANDOFF;
13
- }
14
10
  //# sourceMappingURL=helpers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,qBAAqB,GACtB,MAAM,iCAAiC,CAAA;AAGxC,MAAM,wBAAwB,GAAG,0BAA0B,CAAA;AAE3D,MAAM,UAAU,oBAAoB,CAAC,OAEpC;IACC,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI;IACnD,aAAa;IACb,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,wBAAwB,CAAC,CAC7B,CAAA;IAC7B,IAAI,CAAC,iBAAiB;QACpB,MAAM,IAAI,KAAK,CACb,uEAAuE,CACxE,CAAA;IACH,OAAO,iBAAiB,CAAA;AAC1B,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,IAAuB;IACnD,OAAO,IAAI,CAAC,IAAI,KAAK,qBAAqB,CAAC,OAAO,CAAA;AACpD,CAAC"}
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":"AAIA,MAAM,wBAAwB,GAAG,0BAA0B,CAAA;AAE3D,MAAM,UAAU,oBAAoB,CAAC,OAEpC;IACC,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI;IACnD,aAAa;IACb,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,wBAAwB,CAAC,CAC7B,CAAA;IAC7B,IAAI,CAAC,iBAAiB;QACpB,MAAM,IAAI,KAAK,CACb,uEAAuE,CACxE,CAAA;IACH,OAAO,iBAAiB,CAAA;AAC1B,CAAC"}
@@ -1,8 +1,8 @@
1
- import { Plugin, PluginPostRequest, PluginPreRequest, Session } from '@botonic/core';
1
+ import { Plugin, PluginPreRequest, Session } from '@botonic/core';
2
2
  import { ActionRequest } from '@botonic/react';
3
3
  import { FlowBuilderApi } from './api';
4
4
  import { FlowContent } from './content-fields';
5
- import { HtFunctionNode, HtHandoffNode, HtNodeWithContent } from './content-fields/hubtype-fields';
5
+ import { HtFunctionNode, HtNodeWithContent } from './content-fields/hubtype-fields';
6
6
  import { BotonicPluginFlowBuilderOptions } from './types';
7
7
  export default class BotonicPluginFlowBuilder implements Plugin {
8
8
  readonly options: BotonicPluginFlowBuilderOptions;
@@ -16,11 +16,9 @@ export default class BotonicPluginFlowBuilder implements Plugin {
16
16
  trackEvent?: (request: ActionRequest, eventName: string, args?: Record<string, any>) => Promise<void>;
17
17
  constructor(options: BotonicPluginFlowBuilderOptions);
18
18
  pre(request: PluginPreRequest): Promise<void>;
19
- post(_request: PluginPostRequest): Promise<void>;
20
- getContents(nodeOrId: HtNodeWithContent | string, locale: string, prevContents?: FlowContent[]): Promise<{
21
- contents: FlowContent[];
22
- handoffNode?: HtHandoffNode;
23
- }>;
19
+ getContentsByCode(code: string, locale: string, prevContents?: FlowContent[]): Promise<FlowContent[]>;
20
+ getContentsById(id: string, locale: string, prevContents?: FlowContent[]): Promise<FlowContent[]>;
21
+ getContentsByNode(node: HtNodeWithContent, locale: string, prevContents?: FlowContent[]): Promise<FlowContent[]>;
24
22
  private getFlowContent;
25
23
  callFunction(functionNode: HtFunctionNode, locale: string): Promise<string>;
26
24
  }
package/lib/esm/index.js CHANGED
@@ -1,8 +1,7 @@
1
1
  import { FlowBuilderApi } from './api';
2
- import { FlowCarousel, FlowImage, FlowText, FlowVideo, FlowWhatsappButtonList, } from './content-fields';
2
+ import { FlowCarousel, FlowHandoff, FlowImage, FlowText, FlowVideo, FlowWhatsappButtonList, } from './content-fields';
3
3
  import { HtNodeWithContentType, } from './content-fields/hubtype-fields';
4
4
  import { DEFAULT_FUNCTIONS } from './functions';
5
- import { isHandoffNode } from './helpers';
6
5
  import { resolveGetAccessToken } from './utils';
7
6
  export default class BotonicPluginFlowBuilder {
8
7
  constructor(options) {
@@ -23,26 +22,29 @@ export default class BotonicPluginFlowBuilder {
23
22
  accessToken: this.getAccessToken(request.session),
24
23
  });
25
24
  }
26
- async post(_request) { }
27
- async getContents(nodeOrId, locale, prevContents) {
25
+ getContentsByCode(code, locale, prevContents) {
26
+ const node = this.cmsApi.getNodeByCode(code);
27
+ return this.getContentsByNode(node, locale, prevContents);
28
+ }
29
+ async getContentsById(id, locale, prevContents) {
30
+ const node = this.cmsApi.getNodeById(id);
31
+ return this.getContentsByNode(node, locale, prevContents);
32
+ }
33
+ async getContentsByNode(node, locale, prevContents) {
28
34
  const contents = prevContents || [];
29
- let node = nodeOrId;
30
- if (typeof nodeOrId === 'string') {
31
- node = this.cmsApi.getNodeById(nodeOrId);
32
- }
33
- const content = await this.getFlowContent(node, locale);
35
+ const content = this.getFlowContent(node, locale);
34
36
  if (node.type === HtNodeWithContentType.FUNCTION) {
35
37
  const targetId = await this.callFunction(node, locale);
36
- return this.getContents(targetId, locale, contents);
38
+ return this.getContentsById(targetId, locale, contents);
37
39
  }
38
40
  else {
39
41
  if (content)
40
42
  contents.push(content);
41
43
  // TODO: prevent infinite recursive calls
42
44
  if (node.follow_up)
43
- return this.getContents(node.follow_up.id, locale, contents);
45
+ return this.getContentsById(node.follow_up.id, locale, contents);
44
46
  }
45
- return { contents, handoffNode: isHandoffNode(node) ? node : undefined };
47
+ return contents;
46
48
  }
47
49
  getFlowContent(hubtypeContent, locale) {
48
50
  switch (hubtypeContent.type) {
@@ -56,6 +58,8 @@ export default class BotonicPluginFlowBuilder {
56
58
  return FlowVideo.fromHubtypeCMS(hubtypeContent, locale);
57
59
  case HtNodeWithContentType.WHATSAPP_BUTTON_LIST:
58
60
  return FlowWhatsappButtonList.fromHubtypeCMS(hubtypeContent, locale);
61
+ case HtNodeWithContentType.HANDOFF:
62
+ return FlowHandoff.fromHubtypeCMS(hubtypeContent, locale, this.cmsApi);
59
63
  default:
60
64
  return undefined;
61
65
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AACtC,OAAO,EACL,YAAY,EAEZ,SAAS,EACT,QAAQ,EACR,SAAS,EACT,sBAAsB,GACvB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAML,qBAAqB,GACtB,MAAM,iCAAiC,CAAA;AACxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAEzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAE/C,MAAM,CAAC,OAAO,OAAO,wBAAwB;IAc3C,YAAqB,OAAwC;QAAxC,YAAO,GAAP,OAAO,CAAiC;QAC3D,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAA;QAC9B,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAA;QACxB,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAA;QAClC,IAAI,CAAC,cAAc,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAA;QACpD,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAA;QACpC,MAAM,eAAe,GAAG,OAAO,CAAC,eAAe,IAAI,EAAE,CAAA;QACrD,IAAI,CAAC,SAAS,mCAAQ,iBAAiB,GAAK,eAAe,CAAE,CAAA;IAC/D,CAAC;IAED,KAAK,CAAC,GAAG,CA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;CACF;AAED,cAAc,UAAU,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botonic/plugin-flow-builder",
3
- "version": "0.22.2",
3
+ "version": "0.22.4-alpha.0",
4
4
  "main": "./lib/cjs/index.js",
5
5
  "module": "./lib/esm/index.js",
6
6
  "description": "Use Flow Builder to show your contents",
@@ -47,7 +47,8 @@
47
47
  },
48
48
  "dependencies": {
49
49
  "@babel/runtime": "^7.21.0",
50
- "@botonic/react": "^0.22.0",
50
+ "@botonic/react": "^0.22.2",
51
+ "@botonic/plugin-hubtype-analytics": "0.22.0-alpha.5",
51
52
  "axios": "^1.3.6"
52
53
  }
53
54
  }
@@ -0,0 +1,102 @@
1
+ import {
2
+ EventBotFaq,
3
+ EventFallback,
4
+ EventName,
5
+ } from '@botonic/plugin-hubtype-analytics/lib/cjs/types'
6
+ import { ActionRequest, Multichannel, RequestContext } from '@botonic/react'
7
+ import React from 'react'
8
+
9
+ import { FlowBuilderApi } from '../api'
10
+ import { FlowContent, FlowHandoff } from '../content-fields'
11
+ import { HtNodeWithContent } from '../content-fields/hubtype-fields'
12
+ import { getFlowBuilderPlugin } from '../helpers'
13
+ import { trackEvent } from './tracking'
14
+ import { getNodeByUserInput } from './user-input'
15
+
16
+ type FlowBuilderActionProps = {
17
+ contents: FlowContent[]
18
+ }
19
+
20
+ export class FlowBuilderAction extends React.Component<FlowBuilderActionProps> {
21
+ static contextType = RequestContext
22
+
23
+ static async botonicInit(request: ActionRequest): Promise<any> {
24
+ const flowBuilderPlugin = getFlowBuilderPlugin(request.plugins)
25
+ const locale = flowBuilderPlugin.getLocale(request.session)
26
+
27
+ const targetNode = await getTargetNode(
28
+ flowBuilderPlugin.cmsApi,
29
+ locale,
30
+ request
31
+ )
32
+
33
+ const contents = await flowBuilderPlugin.getContentsByNode(
34
+ targetNode,
35
+ locale
36
+ )
37
+
38
+ const renderContents = contents.filter(async content => {
39
+ if (content instanceof FlowHandoff) {
40
+ await content.doHandoff(request)
41
+ return false
42
+ }
43
+ return true
44
+ })
45
+
46
+ return { contents: renderContents }
47
+ }
48
+
49
+ render(): JSX.Element | JSX.Element[] {
50
+ const { contents } = this.props
51
+ return contents.map(content => content.toBotonic(content.id))
52
+ }
53
+ }
54
+
55
+ export class FlowBuilderMultichannelAction extends FlowBuilderAction {
56
+ render(): JSX.Element | JSX.Element[] {
57
+ const { contents } = this.props
58
+ return (
59
+ <Multichannel text={{ buttonsAsText: false }}>
60
+ {contents.map(content => content.toBotonic(content.id))}
61
+ </Multichannel>
62
+ )
63
+ }
64
+ }
65
+
66
+ async function getTargetNode(
67
+ cmsApi: FlowBuilderApi,
68
+ locale: string,
69
+ request: ActionRequest
70
+ ) {
71
+ const contentId = request.input.payload
72
+ let targetNode: HtNodeWithContent | undefined
73
+ if (!contentId) {
74
+ targetNode = await getNodeByUserInput(cmsApi, locale, request)
75
+ } else {
76
+ targetNode = cmsApi.getNodeById(contentId) as HtNodeWithContent
77
+ }
78
+ if (targetNode) {
79
+ const event: EventBotFaq = {
80
+ event_type: EventName.botFaq,
81
+ event_data: {
82
+ faq_name: targetNode.code,
83
+ },
84
+ }
85
+ await trackEvent(request, event)
86
+ return targetNode
87
+ }
88
+ return await getFallbackNode(cmsApi, request)
89
+ }
90
+
91
+ async function getFallbackNode(cmsApi: FlowBuilderApi, request: ActionRequest) {
92
+ const isFirstFallbackOption =
93
+ request.session.user.extra_data.isFirstFallbackOption || true
94
+ const fallbackNode = cmsApi.getFallbackNode(isFirstFallbackOption)
95
+ request.session.user.extra_data.isFirstFallbackOption = !isFirstFallbackOption
96
+
97
+ const event: EventFallback = {
98
+ event_type: EventName.fallback,
99
+ }
100
+ await trackEvent(request, event)
101
+ return fallbackNode
102
+ }
@@ -0,0 +1,48 @@
1
+ import {
2
+ EventBotAiModel,
3
+ EventName,
4
+ } from '@botonic/plugin-hubtype-analytics/lib/cjs/types'
5
+ import { ActionRequest } from '@botonic/react'
6
+
7
+ import { FlowBuilderApi } from '../api'
8
+ import {
9
+ HtIntentNode,
10
+ HtNodeWithContent,
11
+ } from '../content-fields/hubtype-fields'
12
+ import { trackEvent } from './tracking'
13
+
14
+ export async function getNodeByIntent(
15
+ cmsApi: FlowBuilderApi,
16
+ locale: string,
17
+ request: ActionRequest
18
+ ) {
19
+ const intentNode = cmsApi.getIntentNode(request.input, locale)
20
+ const eventBotAiModel: EventBotAiModel = {
21
+ event_type: EventName.botAiModel,
22
+ event_data: {
23
+ intent: request.input.intent as string,
24
+ confidence: request.input.confidence as number,
25
+ confidence_successful: true,
26
+ },
27
+ }
28
+ if (isIntentValid(intentNode, request, cmsApi) && intentNode?.target?.id) {
29
+ await trackEvent(request, eventBotAiModel)
30
+ return cmsApi.getNodeById<HtNodeWithContent>(intentNode.target.id)
31
+ } else {
32
+ eventBotAiModel.event_data.confidence_successful = false
33
+ await trackEvent(request, eventBotAiModel)
34
+ return undefined
35
+ }
36
+ }
37
+
38
+ function isIntentValid(
39
+ intentNode: HtIntentNode | undefined,
40
+ request: ActionRequest,
41
+ cmsApi: FlowBuilderApi
42
+ ) {
43
+ return (
44
+ intentNode &&
45
+ request.input.confidence &&
46
+ cmsApi.hasMetConfidenceThreshold(intentNode, request.input.confidence)
47
+ )
48
+ }
@@ -0,0 +1,28 @@
1
+ import {
2
+ EventBotKeywordModel,
3
+ EventName,
4
+ } from '@botonic/plugin-hubtype-analytics/lib/cjs/types'
5
+ import { ActionRequest } from '@botonic/react'
6
+
7
+ import { FlowBuilderApi } from '../api'
8
+ import { trackEvent } from './tracking'
9
+
10
+ export async function getNodeByKeyword(
11
+ cmsApi: FlowBuilderApi,
12
+ locale: string,
13
+ request: ActionRequest,
14
+ userInput: string
15
+ ) {
16
+ const keywordNode = cmsApi.getNodeByKeyword(userInput, locale)
17
+ const eventBotKeywordModel: EventBotKeywordModel = {
18
+ event_type: EventName.botKeywordsModel,
19
+ event_data: {
20
+ confidence_successful: true,
21
+ },
22
+ }
23
+ if (keywordNode) {
24
+ await trackEvent(request, eventBotKeywordModel)
25
+ return keywordNode
26
+ }
27
+ return undefined
28
+ }
@@ -0,0 +1,12 @@
1
+ import { HtEventProps } from '@botonic/plugin-hubtype-analytics/lib/cjs/types'
2
+ import { ActionRequest } from '@botonic/react'
3
+
4
+ import { getFlowBuilderPlugin } from '../helpers'
5
+
6
+ export async function trackEvent(request: ActionRequest, event: HtEventProps) {
7
+ const flowBuilderPlugin = getFlowBuilderPlugin(request.plugins)
8
+ if (flowBuilderPlugin.trackEvent) {
9
+ await flowBuilderPlugin.trackEvent(request, event.event_type, event)
10
+ }
11
+ return
12
+ }
@@ -0,0 +1,40 @@
1
+ import {
2
+ EventBotStart,
3
+ EventName,
4
+ } from '@botonic/plugin-hubtype-analytics/lib/cjs/types'
5
+ import { ActionRequest } from '@botonic/react'
6
+
7
+ import { FlowBuilderApi } from '../api'
8
+ import { HtNodeWithContent } from '../content-fields/hubtype-fields'
9
+ import { getNodeByIntent } from './intent'
10
+ import { getNodeByKeyword } from './keyword'
11
+ import { trackEvent } from './tracking'
12
+
13
+ export async function getNodeByUserInput(
14
+ cmsApi: FlowBuilderApi,
15
+ locale: string,
16
+ request: ActionRequest
17
+ ): Promise<HtNodeWithContent | undefined> {
18
+ if (request.session.is_first_interaction) {
19
+ const startNode = cmsApi.getStartNode()
20
+ const event: EventBotStart = {
21
+ event_type: EventName.botStart,
22
+ }
23
+ await trackEvent(request, event)
24
+ return startNode
25
+ }
26
+
27
+ if (request.input.data) {
28
+ const nodeByIntent = await getNodeByIntent(cmsApi, locale, request)
29
+ if (nodeByIntent) return nodeByIntent
30
+
31
+ const keywordNode = await getNodeByKeyword(
32
+ cmsApi,
33
+ locale,
34
+ request,
35
+ request.input.data
36
+ )
37
+ if (keywordNode) return keywordNode
38
+ }
39
+ return undefined
40
+ }
package/src/api.ts CHANGED
@@ -78,24 +78,16 @@ export class FlowBuilderApi {
78
78
  : this.getNodeById(fallbackSecondMessage.id)
79
79
  }
80
80
 
81
- getNodeByIntent(input: Input, locale: string): HtNodeWithContent | undefined {
81
+ getIntentNode(input: Input, locale: string): HtIntentNode | undefined {
82
82
  try {
83
- const intents = this.flow.nodes.filter(
83
+ const intentsNodes = this.flow.nodes.filter(
84
84
  node => node.type === HtNodeWithContentType.INTENT
85
85
  ) as HtIntentNode[]
86
86
  const inputIntent = input.intent
87
- const inputConfidence = input.confidence
88
87
  if (inputIntent) {
89
- const matchedIntentNode = intents.find(
88
+ return intentsNodes.find(
90
89
  node =>
91
- inputIntent &&
92
- this.hasIntent(node, inputIntent, locale) &&
93
- inputConfidence &&
94
- this.hasMetConfidenceThreshold(node, inputConfidence)
95
- )
96
- return (
97
- matchedIntentNode?.target &&
98
- this.getNodeById<HtNodeWithContent>(matchedIntentNode?.target.id)
90
+ inputIntent && this.nodeContainsIntent(node, inputIntent, locale)
99
91
  )
100
92
  }
101
93
  } catch (error) {
@@ -105,7 +97,7 @@ export class FlowBuilderApi {
105
97
  return undefined
106
98
  }
107
99
 
108
- private hasIntent(
100
+ private nodeContainsIntent(
109
101
  node: HtIntentNode,
110
102
  intent: string,
111
103
  locale: string
@@ -115,7 +107,7 @@ export class FlowBuilderApi {
115
107
  )
116
108
  }
117
109
 
118
- private hasMetConfidenceThreshold(
110
+ hasMetConfidenceThreshold(
119
111
  node: HtIntentNode,
120
112
  predictedConfidence: number
121
113
  ): boolean {
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  HtMediaFileLocale,
3
+ HtQueueLocale,
3
4
  HtTextLocale,
4
5
  HtVideoLocale,
5
6
  } from './hubtype-fields'
@@ -21,4 +22,11 @@ export abstract class ContentFieldsBase {
21
22
  const result = video.find(v => v.locale === locale)
22
23
  return result?.url ?? ''
23
24
  }
25
+
26
+ static getQueueByLocale(
27
+ locale: string,
28
+ queues: HtQueueLocale[]
29
+ ): HtQueueLocale | undefined {
30
+ return queues.find(queue => queue.locale === locale)
31
+ }
24
32
  }
@@ -0,0 +1,106 @@
1
+ import { HandOffBuilder } from '@botonic/core'
2
+ import {
3
+ EventHandoffSuccess,
4
+ EventName,
5
+ } from '@botonic/plugin-hubtype-analytics/lib/cjs/types'
6
+ import { ActionRequest } from '@botonic/react'
7
+ import React from 'react'
8
+
9
+ import { trackEvent } from '../action/tracking'
10
+ import { FlowBuilderApi } from '../api'
11
+ import { getQueueAvailability } from '../functions/conditional-queue-status'
12
+ import { ContentFieldsBase } from './content-fields-base'
13
+ import {
14
+ HtCarouselNode,
15
+ HtHandoffNode,
16
+ HtImageNode,
17
+ HtPayloadNode,
18
+ HtQueueLocale,
19
+ HtTextNode,
20
+ HtVideoNode,
21
+ HtWhatsappButtonListNode,
22
+ } from './hubtype-fields'
23
+
24
+ type HtAfterHandoff =
25
+ | HtTextNode
26
+ | HtImageNode
27
+ | HtVideoNode
28
+ | HtCarouselNode
29
+ | HtWhatsappButtonListNode
30
+
31
+ export class FlowHandoff extends ContentFieldsBase {
32
+ public code: string
33
+ public queue?: HtQueueLocale
34
+ public onFinishPayload?: string
35
+ public handoffAutoAssign: boolean
36
+
37
+ static fromHubtypeCMS(
38
+ cmsHandoff: HtHandoffNode,
39
+ locale: string,
40
+ cmsApi: FlowBuilderApi
41
+ ): FlowHandoff {
42
+ const newHandoff = new FlowHandoff(cmsHandoff.id)
43
+ newHandoff.code = cmsHandoff.code
44
+ newHandoff.queue = this.getQueueByLocale(locale, cmsHandoff.content.queue)
45
+ newHandoff.onFinishPayload = this.getOnFinishPayload(
46
+ cmsHandoff,
47
+ locale,
48
+ cmsApi
49
+ )
50
+ newHandoff.handoffAutoAssign = cmsHandoff.content.has_auto_assign
51
+
52
+ return newHandoff
53
+ }
54
+
55
+ private static getOnFinishPayload(
56
+ cmsHandoff: HtHandoffNode,
57
+ locale: string,
58
+ cmsApi: FlowBuilderApi
59
+ ): string | undefined {
60
+ if (cmsHandoff.target?.id) {
61
+ const handoffTargetNode = cmsApi.getNodeById<HtAfterHandoff>(
62
+ cmsHandoff.target?.id
63
+ )
64
+ if (handoffTargetNode?.id) return handoffTargetNode?.id
65
+ }
66
+
67
+ const payloadId = cmsHandoff.content.payload.find(
68
+ payload => payload.locale === locale
69
+ )?.id
70
+
71
+ if (!payloadId) return undefined
72
+
73
+ const actionPayload = cmsApi.getNodeById(payloadId)
74
+
75
+ return (actionPayload as HtPayloadNode).content.payload
76
+ }
77
+
78
+ async doHandoff(request: ActionRequest) {
79
+ // @ts-ignore
80
+ const handOffBuilder = new HandOffBuilder(request.session)
81
+ handOffBuilder.withAutoAssignOnWaiting(this.handoffAutoAssign)
82
+ if (this.onFinishPayload) {
83
+ handOffBuilder.withOnFinishPayload(this.onFinishPayload)
84
+ }
85
+ if (this.queue) {
86
+ const availabilityData = await getQueueAvailability(this.queue.id)
87
+ const event: EventHandoffSuccess = {
88
+ event_type: EventName.handoffSuccess,
89
+ event_data: {
90
+ queue_open: availabilityData.open,
91
+ available_agents: availabilityData.available_agents > 0,
92
+ threshold_reached:
93
+ availabilityData.availability_threshold_waiting_cases > 0,
94
+ },
95
+ }
96
+ await trackEvent(request, event)
97
+
98
+ handOffBuilder.withQueue(this.queue.id)
99
+ await handOffBuilder.handOff()
100
+ }
101
+ }
102
+
103
+ toBotonic(): JSX.Element {
104
+ return <></>
105
+ }
106
+ }
@@ -1,4 +1,5 @@
1
1
  import { FlowCarousel } from './flow-carousel'
2
+ import { FlowHandoff } from './flow-handoff'
2
3
  import { FlowImage } from './flow-image'
3
4
  import { FlowText } from './flow-text'
4
5
  import { FlowVideo } from './flow-video'
@@ -8,6 +9,7 @@ export { ContentFieldsBase } from './content-fields-base'
8
9
  export { FlowButton } from './flow-button'
9
10
  export { FlowElement } from './flow-element'
10
11
  export { FlowCarousel, FlowImage, FlowText, FlowVideo, FlowWhatsappButtonList }
12
+ export { FlowHandoff } from './flow-handoff'
11
13
 
12
14
  export type FlowContent =
13
15
  | FlowCarousel
@@ -15,3 +17,4 @@ export type FlowContent =
15
17
  | FlowText
16
18
  | FlowVideo
17
19
  | FlowWhatsappButtonList
20
+ | FlowHandoff
@@ -1,4 +1,4 @@
1
- import { WhatsappButtonListRowProps } from '@botonic/react/lib/cjs/components/whatsapp-button-list'
1
+ import { WhatsappButtonListRowProps } from '@botonic/react'
2
2
 
3
3
  import { ContentFieldsBase } from '../content-fields-base'
4
4
  import { HtWhatsappButtonListRow } from '../hubtype-fields'
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  WhatsappButtonListRowProps,
3
3
  WhatsappButtonListSectionProps,
4
- } from '@botonic/react/lib/cjs/components/whatsapp-button-list'
4
+ } from '@botonic/react'
5
5
 
6
6
  import { HtWhatsappButtonListSection } from '../hubtype-fields'
7
7
  import { ContentFieldsBase } from './../content-fields-base'
@@ -36,10 +36,8 @@ export class FlowWhatsappButtonList extends ContentFieldsBase {
36
36
  <WhatsappButtonList
37
37
  key={id}
38
38
  body={this.text}
39
- action={{
40
- button: this.listButtonText,
41
- sections: this.sections.map(section => section.toBotonic()),
42
- }}
39
+ button={this.listButtonText}
40
+ sections={this.sections.map(section => section.toBotonic())}
43
41
  ></WhatsappButtonList>
44
42
  )
45
43
  }