@botonic/plugin-flow-builder 0.22.3 → 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 (99) 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/functions/conditional-queue-status.d.ts +10 -1
  29. package/lib/cjs/functions/conditional-queue-status.js +11 -16
  30. package/lib/cjs/functions/conditional-queue-status.js.map +1 -1
  31. package/lib/cjs/helpers.d.ts +0 -2
  32. package/lib/cjs/helpers.js +1 -6
  33. package/lib/cjs/helpers.js.map +1 -1
  34. package/lib/cjs/index.d.ts +5 -7
  35. package/lib/cjs/index.js +15 -11
  36. package/lib/cjs/index.js.map +1 -1
  37. package/lib/esm/{action.d.ts → action/index.d.ts} +1 -2
  38. package/lib/esm/action/index.js +66 -0
  39. package/lib/esm/action/index.js.map +1 -0
  40. package/lib/esm/action/intent.d.ts +4 -0
  41. package/lib/esm/action/intent.js +29 -0
  42. package/lib/esm/action/intent.js.map +1 -0
  43. package/lib/esm/action/keyword.d.ts +3 -0
  44. package/lib/esm/action/keyword.js +17 -0
  45. package/lib/esm/action/keyword.js.map +1 -0
  46. package/lib/esm/action/tracking.d.ts +3 -0
  47. package/lib/esm/action/tracking.js +9 -0
  48. package/lib/esm/action/tracking.js.map +1 -0
  49. package/lib/esm/action/user-input.d.ts +4 -0
  50. package/lib/esm/action/user-input.js +24 -0
  51. package/lib/esm/action/user-input.js.map +1 -0
  52. package/lib/esm/api.d.ts +4 -4
  53. package/lib/esm/api.js +4 -10
  54. package/lib/esm/api.js.map +1 -1
  55. package/lib/esm/content-fields/content-fields-base.d.ts +2 -1
  56. package/lib/esm/content-fields/content-fields-base.js +3 -0
  57. package/lib/esm/content-fields/content-fields-base.js.map +1 -1
  58. package/lib/esm/content-fields/flow-handoff.d.ts +15 -0
  59. package/lib/esm/content-fields/flow-handoff.js +55 -0
  60. package/lib/esm/content-fields/flow-handoff.js.map +1 -0
  61. package/lib/esm/content-fields/index.d.ts +3 -1
  62. package/lib/esm/content-fields/index.js +1 -0
  63. package/lib/esm/content-fields/index.js.map +1 -1
  64. package/lib/esm/functions/conditional-queue-status.d.ts +10 -1
  65. package/lib/esm/functions/conditional-queue-status.js +8 -14
  66. package/lib/esm/functions/conditional-queue-status.js.map +1 -1
  67. package/lib/esm/helpers.d.ts +0 -2
  68. package/lib/esm/helpers.js +0 -4
  69. package/lib/esm/helpers.js.map +1 -1
  70. package/lib/esm/index.d.ts +5 -7
  71. package/lib/esm/index.js +16 -12
  72. package/lib/esm/index.js.map +1 -1
  73. package/package.json +2 -1
  74. package/src/action/index.tsx +102 -0
  75. package/src/action/intent.ts +48 -0
  76. package/src/action/keyword.ts +28 -0
  77. package/src/action/tracking.ts +12 -0
  78. package/src/action/user-input.ts +40 -0
  79. package/src/api.ts +6 -14
  80. package/src/content-fields/content-fields-base.ts +8 -0
  81. package/src/content-fields/flow-handoff.tsx +106 -0
  82. package/src/content-fields/index.ts +3 -0
  83. package/src/functions/conditional-queue-status.ts +19 -16
  84. package/src/helpers.ts +0 -9
  85. package/src/index.ts +28 -20
  86. package/lib/cjs/action.js +0 -52
  87. package/lib/cjs/action.js.map +0 -1
  88. package/lib/cjs/handoff.d.ts +0 -3
  89. package/lib/cjs/handoff.js +0 -53
  90. package/lib/cjs/handoff.js.map +0 -1
  91. package/lib/esm/action.js +0 -46
  92. package/lib/esm/action.js.map +0 -1
  93. package/lib/esm/handoff.d.ts +0 -3
  94. package/lib/esm/handoff.js +0 -49
  95. package/lib/esm/handoff.js.map +0 -1
  96. package/src/.DS_Store +0 -0
  97. package/src/action.tsx +0 -77
  98. package/src/content-fields/.DS_Store +0 -0
  99. package/src/handoff.ts +0 -76
package/src/index.ts CHANGED
@@ -1,15 +1,11 @@
1
- import {
2
- Plugin,
3
- PluginPostRequest,
4
- PluginPreRequest,
5
- Session,
6
- } from '@botonic/core'
1
+ import { Plugin, PluginPreRequest, Session } from '@botonic/core'
7
2
  import { ActionRequest } from '@botonic/react'
8
3
 
9
4
  import { FlowBuilderApi } from './api'
10
5
  import {
11
6
  FlowCarousel,
12
7
  FlowContent,
8
+ FlowHandoff,
13
9
  FlowImage,
14
10
  FlowText,
15
11
  FlowVideo,
@@ -18,13 +14,11 @@ import {
18
14
  import {
19
15
  HtFlowBuilderData,
20
16
  HtFunctionNode,
21
- HtHandoffNode,
22
17
  HtNodeComponent,
23
18
  HtNodeWithContent,
24
19
  HtNodeWithContentType,
25
20
  } from './content-fields/hubtype-fields'
26
21
  import { DEFAULT_FUNCTIONS } from './functions'
27
- import { isHandoffNode } from './helpers'
28
22
  import { BotonicPluginFlowBuilderOptions } from './types'
29
23
  import { resolveGetAccessToken } from './utils'
30
24
 
@@ -61,33 +55,45 @@ export default class BotonicPluginFlowBuilder implements Plugin {
61
55
  })
62
56
  }
63
57
 
64
- async post(_request: PluginPostRequest): Promise<void> {}
58
+ getContentsByCode(
59
+ code: string,
60
+ locale: string,
61
+ prevContents?: FlowContent[]
62
+ ): Promise<FlowContent[]> {
63
+ const node = this.cmsApi.getNodeByCode(code) as HtNodeWithContent
64
+ return this.getContentsByNode(node, locale, prevContents)
65
+ }
65
66
 
66
- async getContents(
67
- nodeOrId: HtNodeWithContent | string,
67
+ async getContentsById(
68
+ id: string,
68
69
  locale: string,
69
70
  prevContents?: FlowContent[]
70
- ): Promise<{ contents: FlowContent[]; handoffNode?: HtHandoffNode }> {
71
+ ): Promise<FlowContent[]> {
72
+ const node = this.cmsApi.getNodeById(id) as HtNodeWithContent
73
+ return this.getContentsByNode(node, locale, prevContents)
74
+ }
75
+
76
+ async getContentsByNode(
77
+ node: HtNodeWithContent,
78
+ locale: string,
79
+ prevContents?: FlowContent[]
80
+ ): Promise<FlowContent[]> {
71
81
  const contents = prevContents || []
72
- let node = nodeOrId as HtNodeWithContent
73
- if (typeof nodeOrId === 'string') {
74
- node = this.cmsApi.getNodeById(nodeOrId) as HtNodeWithContent
75
- }
76
82
 
77
- const content = await this.getFlowContent(node, locale)
83
+ const content = this.getFlowContent(node, locale)
78
84
 
79
85
  if (node.type === HtNodeWithContentType.FUNCTION) {
80
86
  const targetId = await this.callFunction(node, locale)
81
- return this.getContents(targetId, locale, contents)
87
+ return this.getContentsById(targetId, locale, contents)
82
88
  } else {
83
89
  if (content) contents.push(content)
84
90
  // TODO: prevent infinite recursive calls
85
91
 
86
92
  if (node.follow_up)
87
- return this.getContents(node.follow_up.id, locale, contents)
93
+ return this.getContentsById(node.follow_up.id, locale, contents)
88
94
  }
89
95
 
90
- return { contents, handoffNode: isHandoffNode(node) ? node : undefined }
96
+ return contents
91
97
  }
92
98
 
93
99
  private getFlowContent(
@@ -105,6 +111,8 @@ export default class BotonicPluginFlowBuilder implements Plugin {
105
111
  return FlowVideo.fromHubtypeCMS(hubtypeContent, locale)
106
112
  case HtNodeWithContentType.WHATSAPP_BUTTON_LIST:
107
113
  return FlowWhatsappButtonList.fromHubtypeCMS(hubtypeContent, locale)
114
+ case HtNodeWithContentType.HANDOFF:
115
+ return FlowHandoff.fromHubtypeCMS(hubtypeContent, locale, this.cmsApi)
108
116
  default:
109
117
  return undefined
110
118
  }
package/lib/cjs/action.js DELETED
@@ -1,52 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FlowBuilderMultichannelAction = exports.FlowBuilderAction = void 0;
4
- const tslib_1 = require("tslib");
5
- const react_1 = require("@botonic/react");
6
- const react_2 = tslib_1.__importDefault(require("react"));
7
- const handoff_1 = require("./handoff");
8
- const helpers_1 = require("./helpers");
9
- let alternateFallbackMessage = false;
10
- class FlowBuilderAction extends react_2.default.Component {
11
- static async botonicInit(request) {
12
- var _a;
13
- const flowBuilderPlugin = (0, helpers_1.getFlowBuilderPlugin)(request.plugins);
14
- const locale = flowBuilderPlugin.getLocale(request.session);
15
- const payload = request.input.payload;
16
- let targetNode = payload;
17
- if (!payload && request.session.is_first_interaction) {
18
- targetNode = flowBuilderPlugin.cmsApi.getStartNode();
19
- }
20
- if (!payload && request.input.data) {
21
- const intentNode = flowBuilderPlugin.cmsApi.getNodeByIntent(request.input, locale);
22
- const keywordNode = flowBuilderPlugin.cmsApi.getNodeByKeyword(request.input.data, locale);
23
- targetNode = (_a = intentNode !== null && intentNode !== void 0 ? intentNode : keywordNode) !== null && _a !== void 0 ? _a : targetNode;
24
- }
25
- if (!targetNode) {
26
- targetNode = flowBuilderPlugin.cmsApi.getFallbackNode(alternateFallbackMessage);
27
- alternateFallbackMessage = !alternateFallbackMessage;
28
- }
29
- const { contents, handoffNode } = await flowBuilderPlugin.getContents(targetNode, locale);
30
- if (flowBuilderPlugin.trackEvent) {
31
- // TODO: track all targets nodes?
32
- await flowBuilderPlugin.trackEvent(request, contents[0].code);
33
- }
34
- if (handoffNode)
35
- await (0, handoff_1.doHandoff)(request, locale, handoffNode);
36
- return { contents, handoffNode };
37
- }
38
- render() {
39
- const { contents } = this.props;
40
- return contents.map(content => content.toBotonic(content.id));
41
- }
42
- }
43
- exports.FlowBuilderAction = FlowBuilderAction;
44
- FlowBuilderAction.contextType = react_1.RequestContext;
45
- class FlowBuilderMultichannelAction extends FlowBuilderAction {
46
- render() {
47
- const { contents } = this.props;
48
- return (react_2.default.createElement(react_1.Multichannel, { text: { buttonsAsText: false } }, contents.map(content => content.toBotonic(content.id))));
49
- }
50
- }
51
- exports.FlowBuilderMultichannelAction = FlowBuilderMultichannelAction;
52
- //# sourceMappingURL=action.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"action.js","sourceRoot":"","sources":["../../src/action.tsx"],"names":[],"mappings":";;;;AAAA,0CAA4E;AAC5E,0DAAyB;AAIzB,uCAAqC;AACrC,uCAAgD;AAOhD,IAAI,wBAAwB,GAAG,KAAK,CAAA;AACpC,MAAa,iBAAkB,SAAQ,eAAK,CAAC,SAAiC;IAG5E,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,OAAsB;;QAC7C,MAAM,iBAAiB,GAAG,IAAA,8BAAoB,EAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QAC/D,MAAM,MAAM,GAAG,iBAAiB,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QAC3D,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO,CAAA;QACrC,IAAI,UAAU,GAA2C,OAAO,CAAA;QAEhE,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,oBAAoB,EAAE;YACpD,UAAU,GAAG,iBAAiB,CAAC,MAAM,CAAC,YAAY,EAAE,CAAA;SACrD;QAED,IAAI,CAAC,OAAO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M;QACJ,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,KAAK,CAAA;QAC/B,OAAO,CACL,8BAAC,oBAAY,IAAC,IAAI,EAAE,EAAE,aAAa,EAAE,KAAK,EAAE,IACzC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAC1C,CAChB,CAAA;IACH,CAAC;CACF;AATD,sEASC"}
@@ -1,3 +0,0 @@
1
- import { ActionRequest } from '@botonic/react';
2
- import { HtHandoffNode } from './content-fields/hubtype-fields';
3
- export declare function doHandoff(request: ActionRequest, locale: string, handoffNode: HtHandoffNode): Promise<void>;
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.doHandoff = void 0;
4
- const core_1 = require("@botonic/core");
5
- const helpers_1 = require("./helpers");
6
- async function doHandoff(request, locale, handoffNode) {
7
- const flowBuilderPlugin = (0, helpers_1.getFlowBuilderPlugin)(request.plugins);
8
- // @ts-ignore
9
- const handOffBuilder = new core_1.HandOffBuilder(request.session);
10
- const handoffQueues = handoffNode.content.queue;
11
- const queueFound = handoffQueues.find(q => q.locale === locale);
12
- if (queueFound)
13
- handOffBuilder.withQueue(queueFound.id);
14
- const onFinishPayload = await getOnFinishPayload(flowBuilderPlugin, handoffNode, locale);
15
- if (onFinishPayload)
16
- handOffBuilder.withOnFinishPayload(onFinishPayload);
17
- if (handoffNode.content.has_auto_assign) {
18
- handOffBuilder.withAutoAssignOnWaiting(true);
19
- }
20
- // TODO: Retrieve params from FlowBuilder
21
- // const handoffParams = {
22
- // agentEmail: 'test@gmail.com',
23
- // note: 'This is a note that will be attached to the case as a reminder',
24
- // }
25
- // if (handoffParams.note) {
26
- // handOffBuilder.withNote(handoffParams.note)
27
- // }
28
- // if (handoffParams.agentEmail) {
29
- // handOffBuilder.withAgentEmail(handoffParams.agentEmail)
30
- // }
31
- await handOffBuilder.handOff();
32
- if (flowBuilderPlugin.trackEvent) {
33
- await flowBuilderPlugin.trackEvent(request, 'HANDOFF_SUCCESSFULL', {
34
- queue_id: queueFound === null || queueFound === void 0 ? void 0 : queueFound.id,
35
- queue_name: queueFound === null || queueFound === void 0 ? void 0 : queueFound.name,
36
- });
37
- }
38
- }
39
- exports.doHandoff = doHandoff;
40
- async function getOnFinishPayload(flowBuilderPlugin, handoffNode, locale) {
41
- var _a, _b, _c;
42
- if ((_a = handoffNode.target) === null || _a === void 0 ? void 0 : _a.id) {
43
- const handoffTargetNode = flowBuilderPlugin.cmsApi.getNodeById((_b = handoffNode.target) === null || _b === void 0 ? void 0 : _b.id);
44
- if (handoffTargetNode === null || handoffTargetNode === void 0 ? void 0 : handoffTargetNode.id)
45
- return handoffTargetNode === null || handoffTargetNode === void 0 ? void 0 : handoffTargetNode.id;
46
- }
47
- const payloadId = (_c = handoffNode.content.payload.find(payload => payload.locale === locale)) === null || _c === void 0 ? void 0 : _c.id;
48
- if (!payloadId)
49
- return undefined;
50
- const actionPayload = flowBuilderPlugin.cmsApi.getNodeById(payloadId);
51
- return actionPayload.content.payload;
52
- }
53
- //# sourceMappingURL=handoff.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"handoff.js","sourceRoot":"","sources":["../../src/handoff.ts"],"names":[],"mappings":";;;AAAA,wCAA8C;AAI9C,uCAAgD;AAGzC,KAAK,UAAU,SAAS,CAC7B,OAAsB,EACtB,MAAc,EACd,WAA0B;IAE1B,MAAM,iBAAiB,GAAG,IAAA,8BAAoB,EAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IAC/D,aAAa;IACb,MAAM,cAAc,GAAG,IAAI,qBAAc,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IAC1D,MAAM,aAAa,GAAG,WAAW,CAAC,OAAO,CAAC,KAAK,CAAA;IAC/C,MAAM,UAAU,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MA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AED,MAAM,SAAS,GAAG,MAAA,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAChD,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,MAAM,KAAK,MAAM,CACrC,0CAAE,EAAE,CAAA;IAEL,IAAI,CAAC,SAAS;QAAE,OAAO,SAAS,CAAA;IAEhC,MAAM,aAAa,GAAG,iBAAiB,CAAC,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,CAAA;IAErE,OAAQ,aAA+B,CAAC,OAAO,CAAC,OAAO,CAAA;AACzD,CAAC"}
package/lib/esm/action.js DELETED
@@ -1,46 +0,0 @@
1
- import { Multichannel, RequestContext } from '@botonic/react';
2
- import React from 'react';
3
- import { doHandoff } from './handoff';
4
- import { getFlowBuilderPlugin } from './helpers';
5
- let alternateFallbackMessage = false;
6
- export class FlowBuilderAction extends React.Component {
7
- static async botonicInit(request) {
8
- var _a;
9
- const flowBuilderPlugin = getFlowBuilderPlugin(request.plugins);
10
- const locale = flowBuilderPlugin.getLocale(request.session);
11
- const payload = request.input.payload;
12
- let targetNode = payload;
13
- if (!payload && request.session.is_first_interaction) {
14
- targetNode = flowBuilderPlugin.cmsApi.getStartNode();
15
- }
16
- if (!payload && request.input.data) {
17
- const intentNode = flowBuilderPlugin.cmsApi.getNodeByIntent(request.input, locale);
18
- const keywordNode = flowBuilderPlugin.cmsApi.getNodeByKeyword(request.input.data, locale);
19
- targetNode = (_a = intentNode !== null && intentNode !== void 0 ? intentNode : keywordNode) !== null && _a !== void 0 ? _a : targetNode;
20
- }
21
- if (!targetNode) {
22
- targetNode = flowBuilderPlugin.cmsApi.getFallbackNode(alternateFallbackMessage);
23
- alternateFallbackMessage = !alternateFallbackMessage;
24
- }
25
- const { contents, handoffNode } = await flowBuilderPlugin.getContents(targetNode, locale);
26
- if (flowBuilderPlugin.trackEvent) {
27
- // TODO: track all targets nodes?
28
- await flowBuilderPlugin.trackEvent(request, contents[0].code);
29
- }
30
- if (handoffNode)
31
- await doHandoff(request, locale, handoffNode);
32
- return { contents, handoffNode };
33
- }
34
- render() {
35
- const { contents } = this.props;
36
- return contents.map(content => content.toBotonic(content.id));
37
- }
38
- }
39
- FlowBuilderAction.contextType = RequestContext;
40
- export class FlowBuilderMultichannelAction extends FlowBuilderAction {
41
- render() {
42
- const { contents } = this.props;
43
- return (React.createElement(Multichannel, { text: { buttonsAsText: false } }, contents.map(content => content.toBotonic(content.id))));
44
- }
45
- }
46
- //# sourceMappingURL=action.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"action.js","sourceRoot":"","sources":["../../src/action.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAiB,YAAY,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAC5E,OAAO,KAAK,MAAM,OAAO,CAAA;AAIzB,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AACrC,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAOhD,IAAI,wBAAwB,GAAG,KAAK,CAAA;AACpC,MAAM,OAAO,iBAAkB,SAAQ,KAAK,CAAC,SAAiC;IAG5E,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,OAAsB;;QAC7C,MAAM,iBAAiB,GAAG,oBAAoB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QAC/D,MAAM,MAAM,GAAG,iBAAiB,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QAC3D,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO,CAAA;QACrC,IAAI,UAAU,GAA2C,OAAO,CAAA;QAEhE,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,oBAAoB,EAAE;YACpD,UAAU,GAAG,iBAAiB,CAAC,MAAM,CAAC,YAAY,EAAE,CAAA;SACrD;QAED,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE;YAClC,MAAM,UAAU,GAAG,iBAAiB,CAAC,MAAM,CAAC,e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AAE,aAAa,EAAE,KAAK,EAAE,IACzC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAC1C,CAChB,CAAA;IACH,CAAC;CACF"}
@@ -1,3 +0,0 @@
1
- import { ActionRequest } from '@botonic/react';
2
- import { HtHandoffNode } from './content-fields/hubtype-fields';
3
- export declare function doHandoff(request: ActionRequest, locale: string, handoffNode: HtHandoffNode): Promise<void>;
@@ -1,49 +0,0 @@
1
- import { HandOffBuilder } from '@botonic/core';
2
- import { getFlowBuilderPlugin } from './helpers';
3
- export async function doHandoff(request, locale, handoffNode) {
4
- const flowBuilderPlugin = getFlowBuilderPlugin(request.plugins);
5
- // @ts-ignore
6
- const handOffBuilder = new HandOffBuilder(request.session);
7
- const handoffQueues = handoffNode.content.queue;
8
- const queueFound = handoffQueues.find(q => q.locale === locale);
9
- if (queueFound)
10
- handOffBuilder.withQueue(queueFound.id);
11
- const onFinishPayload = await getOnFinishPayload(flowBuilderPlugin, handoffNode, locale);
12
- if (onFinishPayload)
13
- handOffBuilder.withOnFinishPayload(onFinishPayload);
14
- if (handoffNode.content.has_auto_assign) {
15
- handOffBuilder.withAutoAssignOnWaiting(true);
16
- }
17
- // TODO: Retrieve params from FlowBuilder
18
- // const handoffParams = {
19
- // agentEmail: 'test@gmail.com',
20
- // note: 'This is a note that will be attached to the case as a reminder',
21
- // }
22
- // if (handoffParams.note) {
23
- // handOffBuilder.withNote(handoffParams.note)
24
- // }
25
- // if (handoffParams.agentEmail) {
26
- // handOffBuilder.withAgentEmail(handoffParams.agentEmail)
27
- // }
28
- await handOffBuilder.handOff();
29
- if (flowBuilderPlugin.trackEvent) {
30
- await flowBuilderPlugin.trackEvent(request, 'HANDOFF_SUCCESSFULL', {
31
- queue_id: queueFound === null || queueFound === void 0 ? void 0 : queueFound.id,
32
- queue_name: queueFound === null || queueFound === void 0 ? void 0 : queueFound.name,
33
- });
34
- }
35
- }
36
- async function getOnFinishPayload(flowBuilderPlugin, handoffNode, locale) {
37
- var _a, _b, _c;
38
- if ((_a = handoffNode.target) === null || _a === void 0 ? void 0 : _a.id) {
39
- const handoffTargetNode = flowBuilderPlugin.cmsApi.getNodeById((_b = handoffNode.target) === null || _b === void 0 ? void 0 : _b.id);
40
- if (handoffTargetNode === null || handoffTargetNode === void 0 ? void 0 : handoffTargetNode.id)
41
- return handoffTargetNode === null || handoffTargetNode === void 0 ? void 0 : handoffTargetNode.id;
42
- }
43
- const payloadId = (_c = handoffNode.content.payload.find(payload => payload.locale === locale)) === null || _c === void 0 ? void 0 : _c.id;
44
- if (!payloadId)
45
- return undefined;
46
- const actionPayload = flowBuilderPlugin.cmsApi.getNodeById(payloadId);
47
- return actionPayload.content.payload;
48
- }
49
- //# sourceMappingURL=handoff.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"handoff.js","sourceRoot":"","sources":["../../src/handoff.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAI9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAGhD,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,OAAsB,EACtB,MAAc,EACd,WAA0B;IAE1B,MAAM,iBAAiB,GAAG,oBAAoB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IAC/D,aAAa;IACb,MAAM,cAAc,GAAG,IAAI,cAAc,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IAC1D,MAAM,aAAa,GAAG,WAAW,CAAC,OAAO,CAAC,KAAK,CAAA;IAC/C,MAAM,UAAU,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,CAAA;IAC/D,IAAI,UAAU;QAAE,cAAc,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC,CAAA;IAEvD,MAAM,eAAe,GAAG,MAAM,kBAA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L,IAAI,CAAC,SAAS;QAAE,OAAO,SAAS,CAAA;IAEhC,MAAM,aAAa,GAAG,iBAAiB,CAAC,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,CAAA;IAErE,OAAQ,aAA+B,CAAC,OAAO,CAAC,OAAO,CAAA;AACzD,CAAC"}
package/src/.DS_Store DELETED
Binary file
package/src/action.tsx DELETED
@@ -1,77 +0,0 @@
1
- import { ActionRequest, Multichannel, RequestContext } from '@botonic/react'
2
- import React from 'react'
3
-
4
- import { FlowContent } from './content-fields'
5
- import { HtNodeWithContent } from './content-fields/hubtype-fields'
6
- import { doHandoff } from './handoff'
7
- import { getFlowBuilderPlugin } from './helpers'
8
-
9
- type FlowBuilderActionProps = {
10
- contents: FlowContent[]
11
- isHandoff?: boolean
12
- }
13
-
14
- let alternateFallbackMessage = false
15
- export class FlowBuilderAction extends React.Component<FlowBuilderActionProps> {
16
- static contextType = RequestContext
17
-
18
- static async botonicInit(request: ActionRequest): Promise<any> {
19
- const flowBuilderPlugin = getFlowBuilderPlugin(request.plugins)
20
- const locale = flowBuilderPlugin.getLocale(request.session)
21
- const payload = request.input.payload
22
- let targetNode: HtNodeWithContent | string | undefined = payload
23
-
24
- if (!payload && request.session.is_first_interaction) {
25
- targetNode = flowBuilderPlugin.cmsApi.getStartNode()
26
- }
27
-
28
- if (!payload && request.input.data) {
29
- const intentNode = flowBuilderPlugin.cmsApi.getNodeByIntent(
30
- request.input,
31
- locale
32
- )
33
- const keywordNode = flowBuilderPlugin.cmsApi.getNodeByKeyword(
34
- request.input.data,
35
- locale
36
- )
37
- targetNode = intentNode ?? keywordNode ?? targetNode
38
- }
39
-
40
- if (!targetNode) {
41
- targetNode = flowBuilderPlugin.cmsApi.getFallbackNode(
42
- alternateFallbackMessage
43
- )
44
- alternateFallbackMessage = !alternateFallbackMessage
45
- }
46
-
47
- const { contents, handoffNode } = await flowBuilderPlugin.getContents(
48
- targetNode,
49
- locale
50
- )
51
-
52
- if (flowBuilderPlugin.trackEvent) {
53
- // TODO: track all targets nodes?
54
- await flowBuilderPlugin.trackEvent(request, contents[0].code)
55
- }
56
-
57
- if (handoffNode) await doHandoff(request, locale, handoffNode)
58
-
59
- return { contents, handoffNode }
60
- }
61
-
62
- render(): JSX.Element | JSX.Element[] {
63
- const { contents } = this.props
64
- return contents.map(content => content.toBotonic(content.id))
65
- }
66
- }
67
-
68
- export class FlowBuilderMultichannelAction extends FlowBuilderAction {
69
- render(): JSX.Element | JSX.Element[] {
70
- const { contents } = this.props
71
- return (
72
- <Multichannel text={{ buttonsAsText: false }}>
73
- {contents.map(content => content.toBotonic(content.id))}
74
- </Multichannel>
75
- )
76
- }
77
- }
Binary file
package/src/handoff.ts DELETED
@@ -1,76 +0,0 @@
1
- import { HandOffBuilder } from '@botonic/core'
2
- import { ActionRequest } from '@botonic/react'
3
-
4
- import { HtHandoffNode, HtPayloadNode } from './content-fields/hubtype-fields'
5
- import { getFlowBuilderPlugin } from './helpers'
6
- import BotonicPluginFlowBuilder from './index'
7
-
8
- export async function doHandoff(
9
- request: ActionRequest,
10
- locale: string,
11
- handoffNode: HtHandoffNode
12
- ): Promise<void> {
13
- const flowBuilderPlugin = getFlowBuilderPlugin(request.plugins)
14
- // @ts-ignore
15
- const handOffBuilder = new HandOffBuilder(request.session)
16
- const handoffQueues = handoffNode.content.queue
17
- const queueFound = handoffQueues.find(q => q.locale === locale)
18
- if (queueFound) handOffBuilder.withQueue(queueFound.id)
19
-
20
- const onFinishPayload = await getOnFinishPayload(
21
- flowBuilderPlugin,
22
- handoffNode,
23
- locale
24
- )
25
- if (onFinishPayload) handOffBuilder.withOnFinishPayload(onFinishPayload)
26
- if (handoffNode.content.has_auto_assign) {
27
- handOffBuilder.withAutoAssignOnWaiting(true)
28
- }
29
-
30
- // TODO: Retrieve params from FlowBuilder
31
- // const handoffParams = {
32
- // agentEmail: 'test@gmail.com',
33
- // note: 'This is a note that will be attached to the case as a reminder',
34
- // }
35
-
36
- // if (handoffParams.note) {
37
- // handOffBuilder.withNote(handoffParams.note)
38
- // }
39
-
40
- // if (handoffParams.agentEmail) {
41
- // handOffBuilder.withAgentEmail(handoffParams.agentEmail)
42
- // }
43
-
44
- await handOffBuilder.handOff()
45
-
46
- if (flowBuilderPlugin.trackEvent) {
47
- await flowBuilderPlugin.trackEvent(request, 'HANDOFF_SUCCESSFULL', {
48
- queue_id: queueFound?.id,
49
- queue_name: queueFound?.name,
50
- })
51
- }
52
- }
53
-
54
- async function getOnFinishPayload(
55
- flowBuilderPlugin: BotonicPluginFlowBuilder,
56
- handoffNode: HtHandoffNode,
57
- locale: string
58
- ): Promise<string | undefined> {
59
- if (handoffNode.target?.id) {
60
- const handoffTargetNode =
61
- flowBuilderPlugin.cmsApi.getNodeById<HtHandoffNode>(
62
- handoffNode.target?.id
63
- )
64
- if (handoffTargetNode?.id) return handoffTargetNode?.id
65
- }
66
-
67
- const payloadId = handoffNode.content.payload.find(
68
- payload => payload.locale === locale
69
- )?.id
70
-
71
- if (!payloadId) return undefined
72
-
73
- const actionPayload = flowBuilderPlugin.cmsApi.getNodeById(payloadId)
74
-
75
- return (actionPayload as HtPayloadNode).content.payload
76
- }