@botonic/plugin-flow-builder 0.21.0-alpha.4 → 0.21.0-alpha.6

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 (138) hide show
  1. package/lib/cjs/action.d.ts +3 -5
  2. package/lib/cjs/action.js +23 -16
  3. package/lib/cjs/action.js.map +1 -1
  4. package/lib/cjs/content-fields/content-fields-base.d.ts +7 -0
  5. package/lib/cjs/content-fields/{content-base.js → content-fields-base.js} +7 -2
  6. package/lib/cjs/content-fields/content-fields-base.js.map +1 -0
  7. package/lib/cjs/content-fields/{button.d.ts → flow-button.d.ts} +3 -3
  8. package/lib/cjs/content-fields/{button.js → flow-button.js} +5 -5
  9. package/lib/cjs/content-fields/flow-button.js.map +1 -0
  10. package/lib/cjs/content-fields/flow-carousel.d.ts +10 -0
  11. package/lib/cjs/content-fields/{carousel.js → flow-carousel.js} +10 -10
  12. package/lib/cjs/content-fields/flow-carousel.js.map +1 -0
  13. package/lib/cjs/content-fields/flow-element.d.ts +11 -0
  14. package/lib/cjs/content-fields/{element.js → flow-element.js} +6 -7
  15. package/lib/cjs/content-fields/flow-element.js.map +1 -0
  16. package/lib/cjs/content-fields/flow-image.d.ts +9 -0
  17. package/lib/cjs/content-fields/{image.js → flow-image.js} +4 -5
  18. package/lib/cjs/content-fields/flow-image.js.map +1 -0
  19. package/lib/cjs/content-fields/flow-text.d.ts +12 -0
  20. package/lib/cjs/content-fields/{text.js → flow-text.js} +8 -8
  21. package/lib/cjs/content-fields/flow-text.js.map +1 -0
  22. package/lib/cjs/content-fields/index.d.ts +7 -0
  23. package/lib/cjs/content-fields/index.js +16 -0
  24. package/lib/cjs/content-fields/index.js.map +1 -0
  25. package/lib/cjs/content-fields/types.d.ts +4 -0
  26. package/lib/cjs/content-fields/types.js +3 -0
  27. package/lib/cjs/content-fields/types.js.map +1 -0
  28. package/lib/cjs/flow-builder-models.d.ts +174 -0
  29. package/lib/cjs/flow-builder-models.js +22 -0
  30. package/lib/cjs/flow-builder-models.js.map +1 -0
  31. package/lib/cjs/functions/conditional-queue-status.d.ts +2 -2
  32. package/lib/cjs/functions/conditional-queue-status.js +15 -2
  33. package/lib/cjs/functions/conditional-queue-status.js.map +1 -1
  34. package/lib/cjs/functions/index.d.ts +1 -1
  35. package/lib/cjs/functions/index.js +3 -1
  36. package/lib/cjs/functions/index.js.map +1 -1
  37. package/lib/cjs/handoff.d.ts +1 -1
  38. package/lib/cjs/handoff.js +11 -15
  39. package/lib/cjs/handoff.js.map +1 -1
  40. package/lib/cjs/index.d.ts +19 -14
  41. package/lib/cjs/index.js +40 -24
  42. package/lib/cjs/index.js.map +1 -1
  43. package/lib/cjs/utils.d.ts +1 -2
  44. package/lib/cjs/utils.js +6 -6
  45. package/lib/cjs/utils.js.map +1 -1
  46. package/lib/esm/action.d.ts +3 -5
  47. package/lib/esm/action.js +22 -15
  48. package/lib/esm/action.js.map +1 -1
  49. package/lib/esm/content-fields/content-fields-base.d.ts +7 -0
  50. package/lib/esm/content-fields/content-fields-base.js +16 -0
  51. package/lib/esm/content-fields/content-fields-base.js.map +1 -0
  52. package/lib/esm/content-fields/{button.d.ts → flow-button.d.ts} +3 -3
  53. package/lib/esm/content-fields/{button.js → flow-button.js} +4 -4
  54. package/lib/esm/content-fields/flow-button.js.map +1 -0
  55. package/lib/esm/content-fields/flow-carousel.d.ts +10 -0
  56. package/lib/esm/content-fields/{carousel.js → flow-carousel.js} +9 -9
  57. package/lib/esm/content-fields/flow-carousel.js.map +1 -0
  58. package/lib/esm/content-fields/flow-element.d.ts +11 -0
  59. package/lib/esm/content-fields/{element.js → flow-element.js} +4 -5
  60. package/lib/esm/content-fields/flow-element.js.map +1 -0
  61. package/lib/esm/content-fields/flow-image.d.ts +9 -0
  62. package/lib/esm/content-fields/{image.js → flow-image.js} +3 -4
  63. package/lib/esm/content-fields/flow-image.js.map +1 -0
  64. package/lib/esm/content-fields/flow-text.d.ts +12 -0
  65. package/lib/esm/content-fields/{text.js → flow-text.js} +4 -4
  66. package/lib/esm/content-fields/flow-text.js.map +1 -0
  67. package/lib/esm/content-fields/index.d.ts +7 -0
  68. package/lib/esm/content-fields/index.js +7 -0
  69. package/lib/esm/content-fields/index.js.map +1 -0
  70. package/lib/esm/content-fields/types.d.ts +4 -0
  71. package/lib/esm/content-fields/types.js +2 -0
  72. package/lib/esm/content-fields/types.js.map +1 -0
  73. package/lib/esm/flow-builder-models.d.ts +174 -0
  74. package/lib/esm/flow-builder-models.js +19 -0
  75. package/lib/esm/flow-builder-models.js.map +1 -0
  76. package/lib/esm/functions/conditional-queue-status.d.ts +2 -2
  77. package/lib/esm/functions/conditional-queue-status.js +15 -2
  78. package/lib/esm/functions/conditional-queue-status.js.map +1 -1
  79. package/lib/esm/functions/index.d.ts +1 -1
  80. package/lib/esm/functions/index.js +3 -1
  81. package/lib/esm/functions/index.js.map +1 -1
  82. package/lib/esm/handoff.d.ts +1 -1
  83. package/lib/esm/handoff.js +12 -16
  84. package/lib/esm/handoff.js.map +1 -1
  85. package/lib/esm/index.d.ts +19 -14
  86. package/lib/esm/index.js +35 -21
  87. package/lib/esm/index.js.map +1 -1
  88. package/lib/esm/utils.d.ts +1 -2
  89. package/lib/esm/utils.js +4 -4
  90. package/lib/esm/utils.js.map +1 -1
  91. package/package.json +1 -1
  92. package/src/action.tsx +26 -20
  93. package/src/content-fields/content-fields-base.ts +15 -0
  94. package/src/content-fields/{button.tsx → flow-button.tsx} +5 -5
  95. package/src/content-fields/flow-carousel.tsx +39 -0
  96. package/src/content-fields/{element.tsx → flow-element.tsx} +8 -6
  97. package/src/content-fields/{image.tsx → flow-image.tsx} +5 -6
  98. package/src/content-fields/{text.tsx → flow-text.tsx} +5 -5
  99. package/src/content-fields/index.ts +7 -0
  100. package/src/content-fields/types.ts +5 -0
  101. package/src/flow-builder-models.ts +220 -0
  102. package/src/functions/conditional-queue-status.ts +24 -2
  103. package/src/functions/index.ts +3 -1
  104. package/src/handoff.ts +18 -17
  105. package/src/index.ts +75 -50
  106. package/src/utils.ts +10 -5
  107. package/lib/cjs/content-fields/button.js.map +0 -1
  108. package/lib/cjs/content-fields/carousel.d.ts +0 -10
  109. package/lib/cjs/content-fields/carousel.js.map +0 -1
  110. package/lib/cjs/content-fields/content-base.d.ts +0 -10
  111. package/lib/cjs/content-fields/content-base.js.map +0 -1
  112. package/lib/cjs/content-fields/element.d.ts +0 -11
  113. package/lib/cjs/content-fields/element.js.map +0 -1
  114. package/lib/cjs/content-fields/image.d.ts +0 -9
  115. package/lib/cjs/content-fields/image.js.map +0 -1
  116. package/lib/cjs/content-fields/text.d.ts +0 -12
  117. package/lib/cjs/content-fields/text.js.map +0 -1
  118. package/lib/cjs/hubtype-models.d.ts +0 -152
  119. package/lib/cjs/hubtype-models.js +0 -50
  120. package/lib/cjs/hubtype-models.js.map +0 -1
  121. package/lib/esm/content-fields/button.js.map +0 -1
  122. package/lib/esm/content-fields/carousel.d.ts +0 -10
  123. package/lib/esm/content-fields/carousel.js.map +0 -1
  124. package/lib/esm/content-fields/content-base.d.ts +0 -10
  125. package/lib/esm/content-fields/content-base.js +0 -11
  126. package/lib/esm/content-fields/content-base.js.map +0 -1
  127. package/lib/esm/content-fields/element.d.ts +0 -11
  128. package/lib/esm/content-fields/element.js.map +0 -1
  129. package/lib/esm/content-fields/image.d.ts +0 -9
  130. package/lib/esm/content-fields/image.js.map +0 -1
  131. package/lib/esm/content-fields/text.d.ts +0 -12
  132. package/lib/esm/content-fields/text.js.map +0 -1
  133. package/lib/esm/hubtype-models.d.ts +0 -152
  134. package/lib/esm/hubtype-models.js +0 -47
  135. package/lib/esm/hubtype-models.js.map +0 -1
  136. package/src/content-fields/carousel.tsx +0 -39
  137. package/src/content-fields/content-base.ts +0 -15
  138. package/src/hubtype-models.ts +0 -190
@@ -2,9 +2,22 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.conditionalQueueStatus = void 0;
4
4
  const tslib_1 = require("tslib");
5
+ /* eslint-disable @typescript-eslint/naming-convention */
5
6
  const axios_1 = tslib_1.__importDefault(require("axios"));
6
- async function conditionalQueueStatus({ queue_id }) {
7
- const response = await axios_1.default.get(`https://api.hubtype.com/v1/queues/${queue_id}/availability/`);
7
+ const utils_1 = require("../utils");
8
+ const _HUBTYPE_API_URL_ = utils_1.getWebpackEnvVar(
9
+ // @ts-ignore
10
+ typeof HUBTYPE_API_URL !== 'undefined' && HUBTYPE_API_URL, 'HUBTYPE_API_URL', 'https://api.hubtype.com');
11
+ async function conditionalQueueStatus({ queue_id, }) {
12
+ const response = await axios_1.default.get(`${_HUBTYPE_API_URL_}/v1/queues/${queue_id}/availability/`,
13
+ // TODO: Make it configurable in the future
14
+ {
15
+ params: {
16
+ check_queue_schedule: true,
17
+ check_waiting_cases: false,
18
+ check_available_agents: false,
19
+ },
20
+ });
8
21
  const isAvailable = response.data.available;
9
22
  return isAvailable ? 'open' : 'closed';
10
23
  }
@@ -1 +1 @@
1
- {"version":3,"file":"conditional-queue-status.js","sourceRoot":"","sources":["../../../src/functions/conditional-queue-status.ts"],"names":[],"mappings":";;;;AAAA,0DAAyB;AAElB,KAAK,UAAU,sBAAsB,CAAC,EAAE,QAAQ,EAAE;IACvD,MAAM,QAAQ,GAAG,MAAM,eAAK,CAAC,GAAG,CAC9B,qCAAqC,QAAQ,gBAAgB,CAC9D,CAAA;IACD,MAAM,WAAW,GAAG,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAA;IAC3C,OAAO,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAA;AACxC,CAAC;AAND,wDAMC"}
1
+ {"version":3,"file":"conditional-queue-status.js","sourceRoot":"","sources":["../../../src/functions/conditional-queue-status.ts"],"names":[],"mappings":";;;;AAAA,yDAAyD;AACzD,0DAAyB;AAEzB,oCAA2C;AAE3C,MAAM,iBAAiB,GAAG,wBAAgB;AACxC,aAAa;AACb,OAAO,eAAe,KAAK,WAAW,IAAI,eAAe,EACzD,iBAAiB,EACjB,yBAAyB,CAC1B,CAAA;AAEM,KAAK,UAAU,sBAAsB,CAAC,EAC3C,QAAQ,GAGT;IACC,MAAM,QAAQ,GAAG,MAAM,eAAK,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;IAC3C,OAAO,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAA;AACxC,CAAC;AAlBD,wDAkBC"}
@@ -1,6 +1,6 @@
1
1
  import { conditionalProvider } from './conditional-provider';
2
2
  import { conditionalQueueStatus } from './conditional-queue-status';
3
3
  export declare const DEFAULT_FUNCTIONS: {
4
- 'conditional-queue-status': typeof conditionalQueueStatus;
4
+ 'check-queue-status': typeof conditionalQueueStatus;
5
5
  'conditional-provider': typeof conditionalProvider;
6
6
  };
@@ -4,7 +4,9 @@ exports.DEFAULT_FUNCTIONS = void 0;
4
4
  const conditional_provider_1 = require("./conditional-provider");
5
5
  const conditional_queue_status_1 = require("./conditional-queue-status");
6
6
  exports.DEFAULT_FUNCTIONS = {
7
- 'conditional-queue-status': conditional_queue_status_1.conditionalQueueStatus,
7
+ // TODO: Rename api action name
8
+ // 'conditional-queue-status': conditionalQueueStatus,
9
+ 'check-queue-status': conditional_queue_status_1.conditionalQueueStatus,
8
10
  'conditional-provider': conditional_provider_1.conditionalProvider,
9
11
  };
10
12
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/functions/index.ts"],"names":[],"mappings":";;;AAAA,iEAA4D;AAC5D,yEAAmE;AAEtD,QAAA,iBAAiB,GAAG;IAC/B,0BAA0B,EAAE,iDAAsB;IAClD,sBAAsB,EAAE,0CAAmB;CAC5C,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/functions/index.ts"],"names":[],"mappings":";;;AAAA,iEAA4D;AAC5D,yEAAmE;AAEtD,QAAA,iBAAiB,GAAG;IAC/B,+BAA+B;IAC/B,sDAAsD;IACtD,oBAAoB,EAAE,iDAAsB;IAC5C,sBAAsB,EAAE,0CAAmB;CAC5C,CAAA"}
@@ -1,2 +1,2 @@
1
1
  import { ActionRequest } from '@botonic/react';
2
- export declare function doHandoff(request: ActionRequest): Promise<any>;
2
+ export declare function doHandoff(request: ActionRequest, queue: string, note?: string, agentEmail?: string): Promise<void>;
@@ -2,27 +2,23 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.doHandoff = void 0;
4
4
  const core_1 = require("@botonic/core");
5
- // TODO: Remove all "getOpenQueues" logic and open/closed messages.
6
- // This function should just do a basic handoff
7
- // TODO: add missing options: withNote, withAgent
8
- async function doHandoff(request) {
5
+ async function doHandoff(request, queue, note, agentEmail) {
9
6
  var _a;
10
7
  // @ts-ignore
11
8
  const flowBuilderPlugin = request.plugins.hubtypeFlowBuilder;
12
9
  const handoffContent = await flowBuilderPlugin.getHandoffContent();
13
- console.log(handoffContent);
14
10
  // @ts-ignore
15
- let openQueues = await core_1.getOpenQueues(request.session);
16
- const queueName = 'Test';
17
- if (openQueues.queues.indexOf(queueName) !== -1) {
18
- // @ts-ignore
19
- const handOffBuilder = new core_1.HandOffBuilder(request.session);
20
- handOffBuilder.withQueue('Test');
21
- handOffBuilder.withOnFinishPayload((_a = handoffContent.target) === null || _a === void 0 ? void 0 : _a.id);
22
- await handOffBuilder.handOff();
23
- return handoffContent.content.message[0].message;
11
+ const handOffBuilder = new core_1.HandOffBuilder(request.session);
12
+ handOffBuilder.withQueue(queue);
13
+ if (note) {
14
+ handOffBuilder.withNote(note);
24
15
  }
25
- return handoffContent.content.failMessage[0].message;
16
+ if (agentEmail) {
17
+ handOffBuilder.withAgentEmail(agentEmail);
18
+ }
19
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
20
+ handOffBuilder.withOnFinishPayload((_a = handoffContent.target) === null || _a === void 0 ? void 0 : _a.id);
21
+ await handOffBuilder.handOff();
26
22
  }
27
23
  exports.doHandoff = doHandoff;
28
24
  //# sourceMappingURL=handoff.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"handoff.js","sourceRoot":"","sources":["../../src/handoff.ts"],"names":[],"mappings":";;;AAAA,wCAA6D;AAG7D,mEAAmE;AACnE,+CAA+C;AAC/C,iDAAiD;AAE1C,KAAK,UAAU,SAAS,CAAC,OAAsB;;IACpD,aAAa;IACb,MAAM,iBAAiB,GAAG,OAAO,CAAC,OAAO,CAAC,kBAAyB,CAAA;IACnE,MAAM,cAAc,GAAG,MAAM,iBAAiB,CAAC,iBAAiB,EAAE,CAAA;IAClE,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAA;IAC3B,aAAa;IACb,IAAI,UAAU,GAAG,MAAM,oBAAa,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IACrD,MAAM,SAAS,GAAG,MAAM,CAAA;IACxB,IAAI,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE;QAC/C,aAAa;QACb,MAAM,cAAc,GAAG,IAAI,qBAAc,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QAC1D,cAAc,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;QAChC,cAAc,CAAC,mBAAmB,CAAC,MAAA,cAAc,CAAC,MAAM,0CAAE,EAAG,CAAC,CAAA;QAC9D,MAAM,cAAc,CAAC,OAAO,EAAE,CAAA;QAE9B,OAAO,cAAc,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAA;KACjD;IAED,OAAO,cAAc,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,OAAO,CAAA;AACtD,CAAC;AAnBD,8BAmBC"}
1
+ {"version":3,"file":"handoff.js","sourceRoot":"","sources":["../../src/handoff.ts"],"names":[],"mappings":";;;AAAA,wCAA8C;AAGvC,KAAK,UAAU,SAAS,CAC7B,OAAsB,EACtB,KAAa,EACb,IAAa,EACb,UAAmB;;IAEnB,aAAa;IACb,MAAM,iBAAiB,GAAG,OAAO,CAAC,OAAO,CAAC,kBAAyB,CAAA;IACnE,MAAM,cAAc,GAAG,MAAM,iBAAiB,CAAC,iBAAiB,EAAE,CAAA;IAElE,aAAa;IACb,MAAM,cAAc,GAAG,IAAI,qBAAc,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IAC1D,cAAc,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;IAE/B,IAAI,IAAI,EAAE;QACR,cAAc,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;KAC9B;IAED,IAAI,UAAU,EAAE;QACd,cAAc,CAAC,cAAc,CAAC,UAAU,CAAC,CAAA;KAC1C;IACD,oEAAoE;IACpE,cAAc,CAAC,mBAAmB,CAAC,MAAA,cAAc,CAAC,MAAM,0CAAE,EAAG,CAAC,CAAA;IAC9D,MAAM,cAAc,CAAC,OAAO,EAAE,CAAA;AAChC,CAAC;AAxBD,8BAwBC"}
@@ -1,10 +1,12 @@
1
- import { Input, Plugin, PluginPostRequest, PluginPreRequest } from '@botonic/core';
2
- import { FlowContent } from './content-fields/content-base';
3
- import { HtFlowBuilderData, HtFunctionNode, HtHandoffNode, HtIntentNode, HtKeywordNode, HtNodeComponent } from './hubtype-models';
4
- declare type BotonicPluginFlowBuilderOptions = {
1
+ import { Input, Plugin, PluginPostRequest, PluginPreRequest, Session } from '@botonic/core';
2
+ import { FlowContent } from './content-fields';
3
+ import { FlowBuilderData, FunctionNode, HandoffNode, IntentNode, KeywordNode, NodeComponent } from './flow-builder-models';
4
+ export declare type BotonicPluginFlowBuilderOptions = {
5
5
  flowUrl: string;
6
- flow: any;
7
- customFunctions: Record<any, any>;
6
+ flow?: FlowBuilderData;
7
+ customFunctions?: Record<any, any>;
8
+ getLocale: (session: Session) => string;
9
+ getAccessToken: () => string;
8
10
  };
9
11
  export default class BotonicPluginFlowBuilder implements Plugin {
10
12
  readonly options: BotonicPluginFlowBuilderOptions;
@@ -12,19 +14,22 @@ export default class BotonicPluginFlowBuilder implements Plugin {
12
14
  private flow;
13
15
  private functions;
14
16
  private currentRequest;
17
+ private getAccessToken;
18
+ getLocale: (session: Session) => string;
15
19
  constructor(options: BotonicPluginFlowBuilderOptions);
16
- readFlowContent(): Promise<HtFlowBuilderData>;
20
+ readFlowContent(): Promise<FlowBuilderData>;
17
21
  pre(request: PluginPreRequest): Promise<void>;
18
22
  post(_request: PluginPostRequest): Promise<void>;
19
- getContent(id: string): Promise<HtNodeComponent>;
20
- getHandoffContent(): Promise<HtHandoffNode>;
21
- getFlowContent(hubtypeContent: HtNodeComponent, locale: string): FlowContent | undefined;
23
+ getContent(id: string): Promise<NodeComponent>;
24
+ getHandoffContent(): Promise<HandoffNode>;
25
+ getFlowContent(hubtypeContent: NodeComponent, locale: string): FlowContent | undefined;
26
+ getStartId(): Promise<string>;
22
27
  getContents(id: string, locale: string, prevContents?: FlowContent[]): Promise<FlowContent[]>;
23
28
  getPayloadByInput(input: Input, locale: string): Promise<string | undefined>;
24
- hasIntent(node: HtIntentNode, intent: string, locale: string): boolean;
29
+ hasIntent(node: IntentNode, intent: string, locale: string): boolean;
25
30
  getPayloadByKeyword(input: Input, locale: string): Promise<string | undefined>;
26
- matchKeywords(node: HtKeywordNode, input: string, locale: string): boolean;
31
+ matchKeywords(node: KeywordNode, input: string, locale: string): boolean;
27
32
  containsAnyKeywords(input: string, keywords: string[]): boolean;
28
- callFunction(functionNode: HtFunctionNode, locale: string): Promise<string>;
33
+ callFunction(functionNode: FunctionNode, locale: string): Promise<string>;
29
34
  }
30
- export {};
35
+ export { FlowBuilderAction } from './action';
package/lib/cjs/index.js CHANGED
@@ -1,25 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FlowBuilderAction = void 0;
3
4
  const tslib_1 = require("tslib");
4
5
  const axios_1 = tslib_1.__importDefault(require("axios"));
5
- const carousel_1 = require("./content-fields/carousel");
6
- const image_1 = require("./content-fields/image");
7
- const text_1 = require("./content-fields/text");
6
+ const content_fields_1 = require("./content-fields");
7
+ const flow_builder_models_1 = require("./flow-builder-models");
8
8
  const functions_1 = require("./functions");
9
- const hubtype_models_1 = require("./hubtype-models");
10
9
  class BotonicPluginFlowBuilder {
11
10
  constructor(options) {
12
11
  this.options = options;
12
+ this.getLocale = options.getLocale;
13
+ this.getAccessToken = options.getAccessToken;
13
14
  this.flowUrl = options.flowUrl;
14
15
  this.flow = options.flow || this.readFlowContent();
15
16
  const customFunctions = options.customFunctions || {};
16
17
  this.functions = Object.assign(Object.assign({}, functions_1.DEFAULT_FUNCTIONS), customFunctions);
17
18
  }
18
19
  async readFlowContent() {
19
- const response = await axios_1.default.get(this.flowUrl);
20
- const data = await response.data;
21
- //@ts-ignore
22
- return Promise.resolve(data);
20
+ const response = await axios_1.default.get(this.flowUrl, {
21
+ headers: { Authorization: `Bearer ${this.getAccessToken()}` },
22
+ });
23
+ return response.data;
23
24
  }
24
25
  async pre(request) {
25
26
  this.currentRequest = request;
@@ -28,35 +29,43 @@ class BotonicPluginFlowBuilder {
28
29
  async post(_request) { }
29
30
  async getContent(id) {
30
31
  const flow = await this.flow;
31
- const content = flow.nodes.find((c) => c.id === id);
32
+ const content = flow.nodes.find(node => node.id === id);
32
33
  if (!content)
33
34
  throw Error(`text with id: '${id}' not found`);
34
35
  return content;
35
36
  }
36
37
  async getHandoffContent() {
37
38
  const flow = await this.flow;
38
- const content = flow.nodes.find((c) => c.type === 'handoff');
39
+ const content = flow.nodes.find(node => node.type === flow_builder_models_1.NodeType.HANDOFF);
39
40
  if (!content)
40
41
  throw Error(`Handoff node not found`);
41
42
  return content;
42
43
  }
43
44
  getFlowContent(hubtypeContent, locale) {
44
45
  switch (hubtypeContent.type) {
45
- case hubtype_models_1.MessageContentType.TEXT:
46
- return text_1.FlowText.fromHubtypeCMS(hubtypeContent, locale);
47
- case hubtype_models_1.MessageContentType.IMAGE:
48
- return image_1.FlowImage.fromHubtypeCMS(hubtypeContent, locale);
49
- case hubtype_models_1.MessageContentType.CAROUSEL:
50
- return carousel_1.FlowCarousel.fromHubtypeCMS(hubtypeContent, locale);
46
+ case flow_builder_models_1.NodeType.TEXT:
47
+ return content_fields_1.FlowText.fromHubtypeCMS(hubtypeContent, locale);
48
+ case flow_builder_models_1.NodeType.IMAGE:
49
+ return content_fields_1.FlowImage.fromHubtypeCMS(hubtypeContent, locale);
50
+ case flow_builder_models_1.NodeType.CAROUSEL:
51
+ return content_fields_1.FlowCarousel.fromHubtypeCMS(hubtypeContent, locale);
51
52
  default:
52
53
  return undefined;
53
54
  }
54
55
  }
56
+ async getStartId() {
57
+ const flow = await this.flow;
58
+ const startNode = flow.nodes.find(node => node.type === flow_builder_models_1.NodeType.START_UP);
59
+ if (!startNode) {
60
+ throw new Error('start-up id must be defined');
61
+ }
62
+ return startNode.target.id;
63
+ }
55
64
  async getContents(id, locale, prevContents) {
56
65
  const contents = prevContents || [];
57
66
  const hubtypeContent = await this.getContent(id);
58
67
  const content = await this.getFlowContent(hubtypeContent, locale);
59
- if (hubtypeContent.type === hubtype_models_1.MessageContentType.FUNCTION) {
68
+ if (hubtypeContent.type === flow_builder_models_1.NodeType.FUNCTION) {
60
69
  const targetId = await this.callFunction(hubtypeContent, locale);
61
70
  return this.getContents(targetId, locale, contents);
62
71
  }
@@ -75,7 +84,7 @@ class BotonicPluginFlowBuilder {
75
84
  var _a;
76
85
  try {
77
86
  const flow = await this.flow;
78
- const intents = flow.nodes.filter(node => node.type == hubtype_models_1.MessageContentType.INTENT);
87
+ const intents = flow.nodes.filter(node => node.type === flow_builder_models_1.NodeType.INTENT);
79
88
  if (input.intent) {
80
89
  const matchedIntents = intents.filter(node =>
81
90
  //@ts-ignore
@@ -98,7 +107,7 @@ class BotonicPluginFlowBuilder {
98
107
  var _a;
99
108
  try {
100
109
  const flow = await this.flow;
101
- const keywordNodes = flow.nodes.filter(node => node.type == hubtype_models_1.MessageContentType.KEYWORD);
110
+ const keywordNodes = flow.nodes.filter(node => node.type == flow_builder_models_1.NodeType.KEYWORD);
102
111
  const matchedKeywordNodes = keywordNodes.filter(node =>
103
112
  //@ts-ignore
104
113
  this.matchKeywords(node, input.data, locale));
@@ -124,11 +133,13 @@ class BotonicPluginFlowBuilder {
124
133
  return false;
125
134
  }
126
135
  async callFunction(functionNode, locale) {
127
- // Check if target is missing or missing arguments
128
- // TODO: get arguments by locale
129
- const nameValues = functionNode.content.arguments
130
- .find(arg => arg.locale === locale)
131
- .values.map(value => ({ [value.name]: value.value }));
136
+ var _a;
137
+ const functionNodeId = functionNode.id;
138
+ const nameValues = (_a = functionNode.content.arguments
139
+ .find(arg => arg.locale === locale)) === null || _a === void 0 ? void 0 : _a.values.map(value => ({ [value.name]: value.value }));
140
+ if (!nameValues) {
141
+ throw new Error(`No arguments found for node with id ${functionNodeId}`);
142
+ }
132
143
  const args = Object.assign({
133
144
  session: this.currentRequest.session,
134
145
  results: [functionNode.content.result_mapping.map(r => r.result)],
@@ -136,8 +147,13 @@ class BotonicPluginFlowBuilder {
136
147
  const functionResult = await this.functions[functionNode.content.action](args);
137
148
  // TODO define result_mapping per locale??
138
149
  const result = functionNode.content.result_mapping.find(r => r.result === functionResult);
150
+ if (!result) {
151
+ throw new Error(`No result found for result_mapping for node with id: ${functionNodeId}`);
152
+ }
139
153
  return result.target.id;
140
154
  }
141
155
  }
142
156
  exports.default = BotonicPluginFlowBuilder;
157
+ var action_1 = require("./action");
158
+ Object.defineProperty(exports, "FlowBuilderAction", { enumerable: true, get: function () { return action_1.FlowBuilderAction; } });
143
159
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],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c,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;SAClE,EACD,GAAG,UAAU,CACd,CAAA;QACD,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,CACtE,IAAI,CACL,CAAA;QACD,0CAA0C;QAC1C,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,CACrD,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,cAAc,CACjC,CAAA;QACD,IAAI,CAAC,MAAM,EAAE;YACX,MAAM,IAAI,KAAK,CACb,wDAAwD,cAAc,EAAE,CACzE,CAAA;SACF;QACD,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,CAAA;IACzB,CAAC;CACF;AAtMD,2CAsMC;AAED,mCAA4C;AAAnC,2GAAA,iBAAiB,OAAA"}
@@ -1,2 +1 @@
1
- import { HtMediaFileLocale } from './hubtype-models';
2
- export declare function getImageByLocale(locale: string, image: HtMediaFileLocale[]): string;
1
+ export declare function getWebpackEnvVar(webpackEnvVar: string | false, name: string, defaultValue: string): string;
package/lib/cjs/utils.js CHANGED
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getImageByLocale = void 0;
4
- function getImageByLocale(locale, image) {
5
- var _a;
6
- const result = image.find(t => t.locale == locale);
7
- return (_a = result === null || result === void 0 ? void 0 : result.file) !== null && _a !== void 0 ? _a : '';
3
+ exports.getWebpackEnvVar = void 0;
4
+ function getWebpackEnvVar(webpackEnvVar, name, defaultValue) {
5
+ return (webpackEnvVar ||
6
+ (typeof process !== 'undefined' && process.env[name]) ||
7
+ defaultValue);
8
8
  }
9
- exports.getImageByLocale = getImageByLocale;
9
+ exports.getWebpackEnvVar = getWebpackEnvVar;
10
10
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;;AAEA,SAAgB,gBAAgB,CAAC,MAAc,EAAE,KAA0B;;IACzE,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,IAAI,MAAM,CAAC,CAAA;IAClD,OAAO,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,mCAAI,EAAE,CAAA;AAC3B,CAAC;AAHD,4CAGC"}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;;AAAA,SAAgB,gBAAgB,CAC9B,aAA6B,EAC7B,IAAY,EACZ,YAAoB;IAEpB,OAAO,CACL,aAAa;QACb,CAAC,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACrD,YAAY,CACb,CAAA;AACH,CAAC;AAVD,4CAUC"}
@@ -1,13 +1,11 @@
1
1
  import { ActionRequest } from '@botonic/react';
2
2
  import React from 'react';
3
- import { FlowContent } from './content-fields/content-base';
4
- import { HtHandoffNode } from './hubtype-models';
5
- export declare const START = "08c7df06-0c7c-4f06-b8c1-4157582efeb2";
3
+ import { FlowContent } from './content-fields';
6
4
  declare type FlowBuilderActionProps = {
7
5
  content?: FlowContent[];
8
- handoffMsg?: HtHandoffNode;
6
+ isHandoff?: boolean;
9
7
  };
10
- export default class FlowBuilderAction extends React.Component<FlowBuilderActionProps> {
8
+ export declare class FlowBuilderAction extends React.Component<FlowBuilderActionProps> {
11
9
  static contextType: React.Context<import("@botonic/react").RequestContextInterface>;
12
10
  static botonicInit(request: ActionRequest): Promise<any>;
13
11
  render(): JSX.Element | JSX.Element[];
package/lib/esm/action.js CHANGED
@@ -1,36 +1,43 @@
1
1
  import { RequestContext, Text } from '@botonic/react';
2
2
  import React from 'react';
3
3
  import { doHandoff } from './handoff';
4
- // TODO: remove this from here and use the new "start" attribute in the flow
5
- export const START = '08c7df06-0c7c-4f06-b8c1-4157582efeb2';
6
- export default class FlowBuilderAction extends React.Component {
4
+ export class FlowBuilderAction extends React.Component {
7
5
  static async botonicInit(request) {
8
- const flowBuilderPlugin = request.plugins.hubtypeFlowBuilder;
9
- let payload = request.input.payload ? request.input.payload : START;
6
+ const flowBuilderPlugin = request.plugins
7
+ .hubtypeFlowBuilder;
8
+ const locale = flowBuilderPlugin.getLocale(request.session);
9
+ let payload = request.input.payload
10
+ ? request.input.payload
11
+ : await flowBuilderPlugin.getStartId();
10
12
  if (!request.input.payload) {
11
- const intentPayload = await flowBuilderPlugin.getPayloadByInput(request.input, 'es-ES');
13
+ const intentPayload = await flowBuilderPlugin.getPayloadByInput(request.input, locale);
12
14
  if (intentPayload) {
13
15
  payload = intentPayload;
14
16
  }
15
- const keywordPayload = await flowBuilderPlugin.getPayloadByKeyword(request.input, 'es-ES');
17
+ const keywordPayload = await flowBuilderPlugin.getPayloadByKeyword(request.input, locale);
16
18
  if (keywordPayload) {
17
19
  payload = keywordPayload;
18
20
  }
19
21
  }
20
22
  // We use only Spanish because they are the backend examples
21
- const content = await flowBuilderPlugin.getContents(payload, 'es-ES');
22
- if (content.length == 0) {
23
- const handoffMsg = await doHandoff(request);
24
- return { handoffMsg };
23
+ const content = await flowBuilderPlugin.getContents(payload, locale);
24
+ if (content.length === 0) {
25
+ const handoffParams = {
26
+ queue: 'Test',
27
+ agentEmail: 'test@gmail.com',
28
+ note: 'This is a note that will be attached to the case as a reminder',
29
+ };
30
+ await doHandoff(request, handoffParams.queue, handoffParams.note);
31
+ const isHandoff = true;
32
+ return { isHandoff };
25
33
  }
26
34
  return { content };
27
35
  }
28
36
  render() {
29
37
  // @ts-ignore
30
- const { content: contents, handoffMsg } = this.props;
31
- if (handoffMsg) {
32
- // @ts-ignore
33
- return React.createElement(Text, null, handoffMsg);
38
+ const { content: contents, isHandoff } = this.props;
39
+ if (isHandoff) {
40
+ return React.createElement(Text, null, "You are being transferred to an agent!");
34
41
  }
35
42
  else {
36
43
  return contents.map((content, index) => content.toBotonic(index));
@@ -1 +1 @@
1
- {"version":3,"file":"action.js","sourceRoot":"","sources":["../../src/action.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAiB,cAAc,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAA;AACpE,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAGrC,4EAA4E;AAC5E,MAAM,CAAC,MAAM,KAAK,GAAG,sCAAsC,CAAA;AAO3D,MAAM,CAAC,OAAO,OAAO,iBAAkB,SAAQ,KAAK,CAAC,SAAiC;IAGpF,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,OAAsB;QAC7C,MAAM,iBAAiB,GAAG,OAAO,CAAC,OAAO,CAAC,kBAAyB,CAAA;QAEnE,IAAI,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAA;QACnE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE;YAC1B,MAAM,aAAa,GAAG,MAAM,iBAAiB,CAAC,iBAAiB,CAC7D,OAAO,CAAC,KAAK,EACb,OAAO,CACR,CAAA;YACD,IAAI,aAAa,EAAE;gBACjB,OAAO,GAAG,aAAa,CAAA;aACxB;YACD,MAAM,cAAc,GAAG,MAAM,iBAAiB,CAAC,mBAAmB,CAChE,OAAO,CAAC,KAAK,EACb,OAAO,CACR,CAAA;YACD,IAAI,cAAc,EAAE;gBAClB,OAAO,GAAG,cAAc,CAAA;aACzB;SACF;QACD,4DAA4D;QAC5D,MAAM,OAAO,GAAG,MAAM,iBAAiB,CAAC,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QAErE,IAAI,OAAO,CAAC,MAAM,IAAI,CAAC,EAAE;YACvB,MAAM,UAAU,GAAG,MAAM,S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,CAC7D,OAAO,CAAC,KAAK,EACb,MAAM,CACP,CAAA;YACD,IAAI,aAAa,EAAE;gBACjB,OAAO,GAAG,aAAa,CAAA;aACxB;YACD,MAAM,cAAc,GAAG,MAAM,iBAAiB,CAAC,mBAAmB,CAChE,OAAO,CAAC,KAAK,EACb,MAAM,CACP,CAAA;YACD,IAAI,cAAc,EAAE;gBAClB,OAAO,GAAG,cAAc,CAAA;aACzB;SACF;QACD,4DAA4D;QAC5D,MAAM,OAAO,GAAG,MAAM,iBAAiB,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;QAEpE,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE;YACxB,MAAM,aAAa,GAAG;gBACpB,KAAK,EAAE,MAAM;gBACb,UAAU,EAAE,gBAAgB;gBAC5B,IAAI,EAAE,gEAAgE;aACvE,CAAA;YACD,MAAM,SAAS,CAAC,OAAO,EAAE,aAAa,CAAC,KAAK,EAAE,aAAa,CAAC,IAAI,CAAC,CAAA;YACjE,MAAM,SAAS,GAAG,IAAI,CAAA;YACtB,OAAO,EAAE,SAAS,EAAE,CAAA;SACrB;QACD,OAAO,EAAE,OAAO,EAAE,CAAA;IACpB,CAAC;IAED,MAAM;QACJ,aAAa;QACb,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,KAAK,CAAA;QACnD,IAAI,SAAS,EAAE;YACb,OAAO,oBAAC,IAAI,iDAA8C,CAAA;SAC3D;aAAM;YACL,OAAO,QAAS,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAA;SACnE;IACH,CAAC;;AAlDM,6BAAW,GAAG,cAAc,CAAA"}
@@ -0,0 +1,7 @@
1
+ import { MediaFileLocale, TextLocale } from '../flow-builder-models';
2
+ export declare abstract class ContentFieldsBase {
3
+ private readonly id;
4
+ constructor(id: string);
5
+ static getTextByLocale(locale: string, text: TextLocale[]): string;
6
+ static getImageByLocale(locale: string, image: MediaFileLocale[]): string;
7
+ }
@@ -0,0 +1,16 @@
1
+ export class ContentFieldsBase {
2
+ constructor(id) {
3
+ this.id = id;
4
+ }
5
+ static getTextByLocale(locale, text) {
6
+ var _a;
7
+ const result = text.find(t => t.locale === locale);
8
+ return (_a = result === null || result === void 0 ? void 0 : result.message) !== null && _a !== void 0 ? _a : '';
9
+ }
10
+ static getImageByLocale(locale, image) {
11
+ var _a;
12
+ const result = image.find(t => t.locale === locale);
13
+ return (_a = result === null || result === void 0 ? void 0 : result.file) !== null && _a !== void 0 ? _a : '';
14
+ }
15
+ }
16
+ //# sourceMappingURL=content-fields-base.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content-fields-base.js","sourceRoot":"","sources":["../../../src/content-fields/content-fields-base.ts"],"names":[],"mappings":"AAEA,MAAM,OAAgB,iBAAiB;IACrC,YAA6B,EAAU;QAAV,OAAE,GAAF,EAAE,CAAQ;IAAG,CAAC;IAE3C,MAAM,CAAC,eAAe,CAAC,MAAc,EAAE,IAAkB;;QACvD,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,CAAA;QAClD,OAAO,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,OAAO,mCAAI,EAAE,CAAA;IAC9B,CAAC;IAED,MAAM,CAAC,gBAAgB,CAAC,MAAc,EAAE,KAAwB;;QAC9D,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,CAAA;QACnD,OAAO,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,mCAAI,EAAE,CAAA;IAC3B,CAAC;CACF"}
@@ -1,10 +1,10 @@
1
1
  /// <reference types="react" />
2
- import { ButtonStyle, HtButton } from '../hubtype-models';
3
- import { ContentFieldsBase } from './content-base';
2
+ import { Button as FbButton, ButtonStyle } from '../flow-builder-models';
3
+ import { ContentFieldsBase } from './content-fields-base';
4
4
  export declare class FlowButton extends ContentFieldsBase {
5
5
  text: string;
6
6
  url?: string;
7
7
  payload?: string;
8
- static fromHubtypeCMS(component: HtButton, locale: string): FlowButton;
8
+ static fromHubtypeCMS(component: FbButton, locale: string): FlowButton;
9
9
  renderButton(index: number, buttonStyle: ButtonStyle): JSX.Element;
10
10
  }
@@ -1,7 +1,7 @@
1
1
  import { Button, Reply } from '@botonic/react';
2
2
  import React from 'react';
3
- import { ButtonStyle } from '../hubtype-models';
4
- import { ContentFieldsBase } from './content-base';
3
+ import { ButtonStyle } from '../flow-builder-models';
4
+ import { ContentFieldsBase } from './content-fields-base';
5
5
  export class FlowButton extends ContentFieldsBase {
6
6
  constructor() {
7
7
  super(...arguments);
@@ -15,7 +15,7 @@ export class FlowButton extends ContentFieldsBase {
15
15
  return newButton;
16
16
  }
17
17
  renderButton(index, buttonStyle) {
18
- if (buttonStyle == ButtonStyle.QUICK_REPLY) {
18
+ if (buttonStyle === ButtonStyle.QUICK_REPLY) {
19
19
  return (React.createElement(Reply, { payload: this.payload, key: index }, this.text));
20
20
  }
21
21
  return (
@@ -23,4 +23,4 @@ export class FlowButton extends ContentFieldsBase {
23
23
  React.createElement(Button, { payload: this.payload, key: index }, this.text));
24
24
  }
25
25
  }
26
- //# sourceMappingURL=button.js.map
26
+ //# sourceMappingURL=flow-button.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flow-button.js","sourceRoot":"","sources":["../../../src/content-fields/flow-button.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EAAsB,WAAW,EAAE,MAAM,wBAAwB,CAAA;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AAEzD,MAAM,OAAO,UAAW,SAAQ,iBAAiB;IAAjD;;QACS,SAAI,GAAG,EAAE,CAAA;IA0BlB,CAAC;IAtBC,MAAM,CAAC,cAAc,CAAC,SAAmB,EAAE,MAAc;;QACvD,MAAM,SAAS,GAAG,IAAI,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC,CAAA;QAC9C,SAAS,CAAC,IAAI,GAAG,UAAU,CAAC,eAAe,CAAC,MAAM,EAAE,SAAS,CAAC,IAAI,CAAC,CAAA;QACnE,SAAS,CAAC,OAAO,GAAG,MAAA,SAAS,CAAC,MAAM,0CAAE,EAAE,CAAA;QACxC,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,YAAY,CAAC,KAAa,EAAE,WAAwB;QAClD,IAAI,WAAW,KAAK,WAAW,CAAC,WAAW,EAAE;YAC3C,OAAO,CACL,oBAAC,KAAK,IAAC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,KAAK,IACrC,IAAI,CAAC,IAAI,CACJ,CACT,CAAA;SACF;QACD,OAAO;QACL,aAAa;QACb,oBAAC,MAAM,IAAC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,KAAK,IACtC,IAAI,CAAC,IAAI,CACH,CACV,CAAA;IACH,CAAC;CACF"}
@@ -0,0 +1,10 @@
1
+ /// <reference types="react" />
2
+ import { CarouselNode } from '../flow-builder-models';
3
+ import { ContentFieldsBase } from './content-fields-base';
4
+ import { FlowElement } from './flow-element';
5
+ export declare class FlowCarousel extends ContentFieldsBase {
6
+ code: string;
7
+ elements: FlowElement[];
8
+ static fromHubtypeCMS(component: CarouselNode, locale: string): FlowCarousel;
9
+ toBotonic(index: number): JSX.Element;
10
+ }
@@ -1,7 +1,7 @@
1
1
  import { Button, Carousel, Element, Pic, Subtitle, Title } from '@botonic/react';
2
2
  import React from 'react';
3
- import { ContentFieldsBase } from './content-base';
4
- import { FlowElement } from './element';
3
+ import { ContentFieldsBase } from './content-fields-base';
4
+ import { FlowElement } from './flow-element';
5
5
  export class FlowCarousel extends ContentFieldsBase {
6
6
  constructor() {
7
7
  super(...arguments);
@@ -11,19 +11,19 @@ export class FlowCarousel extends ContentFieldsBase {
11
11
  static fromHubtypeCMS(component, locale) {
12
12
  const newCarousel = new FlowCarousel(component.id);
13
13
  newCarousel.code = component.code;
14
- newCarousel.elements = component.content.elements.map(ele => FlowElement.fromHubtypeCMS(ele, locale));
14
+ newCarousel.elements = component.content.elements.map(element => FlowElement.fromHubtypeCMS(element, locale));
15
15
  return newCarousel;
16
16
  }
17
17
  toBotonic(index) {
18
- return (React.createElement(Carousel, { key: index }, this.elements.map((e, eIndex) => {
18
+ return (React.createElement(Carousel, { key: index }, this.elements.map((element, eIndex) => {
19
19
  var _a, _b;
20
20
  return (React.createElement(Element, { key: eIndex },
21
- React.createElement(Pic, { src: e.image }),
22
- React.createElement(Title, { style: '' }, e.title),
23
- React.createElement(Subtitle, { style: '' }, e.subtitle),
24
- React.createElement(Button, { payload: (_a = e.buttons) === null || _a === void 0 ? void 0 : _a.payload }, (_b = e.buttons) === null || _b === void 0 ? void 0 : _b.text),
21
+ React.createElement(Pic, { src: element.image }),
22
+ React.createElement(Title, { style: '' }, element.title),
23
+ React.createElement(Subtitle, { style: '' }, element.subtitle),
24
+ React.createElement(Button, { payload: (_a = element.buttons) === null || _a === void 0 ? void 0 : _a.payload }, (_b = element.buttons) === null || _b === void 0 ? void 0 : _b.text),
25
25
  ","));
26
26
  })));
27
27
  }
28
28
  }
29
- //# sourceMappingURL=carousel.js.map
29
+ //# sourceMappingURL=flow-carousel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flow-carousel.js","sourceRoot":"","sources":["../../../src/content-fields/flow-carousel.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAChF,OAAO,KAAK,MA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AC;CACF"}
@@ -0,0 +1,11 @@
1
+ import { CarouselElementNode } from '../flow-builder-models';
2
+ import { ContentFieldsBase } from './content-fields-base';
3
+ import { FlowButton } from './flow-button';
4
+ export declare class FlowElement extends ContentFieldsBase {
5
+ title: string;
6
+ subtitle: string;
7
+ buttons: FlowButton | undefined;
8
+ image: string;
9
+ hidden: boolean;
10
+ static fromHubtypeCMS(component: CarouselElementNode, locale: string): FlowElement;
11
+ }
@@ -1,6 +1,5 @@
1
- import { getImageByLocale } from '../utils';
2
- import { FlowButton } from './button';
3
- import { ContentFieldsBase } from './content-base';
1
+ import { ContentFieldsBase } from './content-fields-base';
2
+ import { FlowButton } from './flow-button';
4
3
  export class FlowElement extends ContentFieldsBase {
5
4
  constructor() {
6
5
  super(...arguments);
@@ -13,9 +12,9 @@ export class FlowElement extends ContentFieldsBase {
13
12
  const newElement = new FlowElement(component.id);
14
13
  newElement.title = FlowElement.getTextByLocale(locale, component.title);
15
14
  newElement.subtitle = FlowElement.getTextByLocale(locale, component.subtitle);
16
- newElement.image = getImageByLocale(locale, component.image);
15
+ newElement.image = FlowElement.getImageByLocale(locale, component.image);
17
16
  newElement.buttons = FlowButton.fromHubtypeCMS(component.button, locale);
18
17
  return newElement;
19
18
  }
20
19
  }
21
- //# sourceMappingURL=element.js.map
20
+ //# sourceMappingURL=flow-element.js.map