@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.
- package/lib/cjs/action.d.ts +3 -5
- package/lib/cjs/action.js +23 -16
- package/lib/cjs/action.js.map +1 -1
- package/lib/cjs/content-fields/content-fields-base.d.ts +7 -0
- package/lib/cjs/content-fields/{content-base.js → content-fields-base.js} +7 -2
- package/lib/cjs/content-fields/content-fields-base.js.map +1 -0
- package/lib/cjs/content-fields/{button.d.ts → flow-button.d.ts} +3 -3
- package/lib/cjs/content-fields/{button.js → flow-button.js} +5 -5
- package/lib/cjs/content-fields/flow-button.js.map +1 -0
- package/lib/cjs/content-fields/flow-carousel.d.ts +10 -0
- package/lib/cjs/content-fields/{carousel.js → flow-carousel.js} +10 -10
- package/lib/cjs/content-fields/flow-carousel.js.map +1 -0
- package/lib/cjs/content-fields/flow-element.d.ts +11 -0
- package/lib/cjs/content-fields/{element.js → flow-element.js} +6 -7
- package/lib/cjs/content-fields/flow-element.js.map +1 -0
- package/lib/cjs/content-fields/flow-image.d.ts +9 -0
- package/lib/cjs/content-fields/{image.js → flow-image.js} +4 -5
- package/lib/cjs/content-fields/flow-image.js.map +1 -0
- package/lib/cjs/content-fields/flow-text.d.ts +12 -0
- package/lib/cjs/content-fields/{text.js → flow-text.js} +8 -8
- package/lib/cjs/content-fields/flow-text.js.map +1 -0
- package/lib/cjs/content-fields/index.d.ts +7 -0
- package/lib/cjs/content-fields/index.js +16 -0
- package/lib/cjs/content-fields/index.js.map +1 -0
- package/lib/cjs/content-fields/types.d.ts +4 -0
- package/lib/cjs/content-fields/types.js +3 -0
- package/lib/cjs/content-fields/types.js.map +1 -0
- package/lib/cjs/flow-builder-models.d.ts +174 -0
- package/lib/cjs/flow-builder-models.js +22 -0
- package/lib/cjs/flow-builder-models.js.map +1 -0
- package/lib/cjs/functions/conditional-queue-status.d.ts +2 -2
- package/lib/cjs/functions/conditional-queue-status.js +15 -2
- package/lib/cjs/functions/conditional-queue-status.js.map +1 -1
- package/lib/cjs/functions/index.d.ts +1 -1
- package/lib/cjs/functions/index.js +3 -1
- package/lib/cjs/functions/index.js.map +1 -1
- package/lib/cjs/handoff.d.ts +1 -1
- package/lib/cjs/handoff.js +11 -15
- package/lib/cjs/handoff.js.map +1 -1
- package/lib/cjs/index.d.ts +19 -14
- package/lib/cjs/index.js +40 -24
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/utils.d.ts +1 -2
- package/lib/cjs/utils.js +6 -6
- package/lib/cjs/utils.js.map +1 -1
- package/lib/esm/action.d.ts +3 -5
- package/lib/esm/action.js +22 -15
- package/lib/esm/action.js.map +1 -1
- package/lib/esm/content-fields/content-fields-base.d.ts +7 -0
- package/lib/esm/content-fields/content-fields-base.js +16 -0
- package/lib/esm/content-fields/content-fields-base.js.map +1 -0
- package/lib/esm/content-fields/{button.d.ts → flow-button.d.ts} +3 -3
- package/lib/esm/content-fields/{button.js → flow-button.js} +4 -4
- package/lib/esm/content-fields/flow-button.js.map +1 -0
- package/lib/esm/content-fields/flow-carousel.d.ts +10 -0
- package/lib/esm/content-fields/{carousel.js → flow-carousel.js} +9 -9
- package/lib/esm/content-fields/flow-carousel.js.map +1 -0
- package/lib/esm/content-fields/flow-element.d.ts +11 -0
- package/lib/esm/content-fields/{element.js → flow-element.js} +4 -5
- package/lib/esm/content-fields/flow-element.js.map +1 -0
- package/lib/esm/content-fields/flow-image.d.ts +9 -0
- package/lib/esm/content-fields/{image.js → flow-image.js} +3 -4
- package/lib/esm/content-fields/flow-image.js.map +1 -0
- package/lib/esm/content-fields/flow-text.d.ts +12 -0
- package/lib/esm/content-fields/{text.js → flow-text.js} +4 -4
- package/lib/esm/content-fields/flow-text.js.map +1 -0
- package/lib/esm/content-fields/index.d.ts +7 -0
- package/lib/esm/content-fields/index.js +7 -0
- package/lib/esm/content-fields/index.js.map +1 -0
- package/lib/esm/content-fields/types.d.ts +4 -0
- package/lib/esm/content-fields/types.js +2 -0
- package/lib/esm/content-fields/types.js.map +1 -0
- package/lib/esm/flow-builder-models.d.ts +174 -0
- package/lib/esm/flow-builder-models.js +19 -0
- package/lib/esm/flow-builder-models.js.map +1 -0
- package/lib/esm/functions/conditional-queue-status.d.ts +2 -2
- package/lib/esm/functions/conditional-queue-status.js +15 -2
- package/lib/esm/functions/conditional-queue-status.js.map +1 -1
- package/lib/esm/functions/index.d.ts +1 -1
- package/lib/esm/functions/index.js +3 -1
- package/lib/esm/functions/index.js.map +1 -1
- package/lib/esm/handoff.d.ts +1 -1
- package/lib/esm/handoff.js +12 -16
- package/lib/esm/handoff.js.map +1 -1
- package/lib/esm/index.d.ts +19 -14
- package/lib/esm/index.js +35 -21
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/utils.d.ts +1 -2
- package/lib/esm/utils.js +4 -4
- package/lib/esm/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/action.tsx +26 -20
- package/src/content-fields/content-fields-base.ts +15 -0
- package/src/content-fields/{button.tsx → flow-button.tsx} +5 -5
- package/src/content-fields/flow-carousel.tsx +39 -0
- package/src/content-fields/{element.tsx → flow-element.tsx} +8 -6
- package/src/content-fields/{image.tsx → flow-image.tsx} +5 -6
- package/src/content-fields/{text.tsx → flow-text.tsx} +5 -5
- package/src/content-fields/index.ts +7 -0
- package/src/content-fields/types.ts +5 -0
- package/src/flow-builder-models.ts +220 -0
- package/src/functions/conditional-queue-status.ts +24 -2
- package/src/functions/index.ts +3 -1
- package/src/handoff.ts +18 -17
- package/src/index.ts +75 -50
- package/src/utils.ts +10 -5
- package/lib/cjs/content-fields/button.js.map +0 -1
- package/lib/cjs/content-fields/carousel.d.ts +0 -10
- package/lib/cjs/content-fields/carousel.js.map +0 -1
- package/lib/cjs/content-fields/content-base.d.ts +0 -10
- package/lib/cjs/content-fields/content-base.js.map +0 -1
- package/lib/cjs/content-fields/element.d.ts +0 -11
- package/lib/cjs/content-fields/element.js.map +0 -1
- package/lib/cjs/content-fields/image.d.ts +0 -9
- package/lib/cjs/content-fields/image.js.map +0 -1
- package/lib/cjs/content-fields/text.d.ts +0 -12
- package/lib/cjs/content-fields/text.js.map +0 -1
- package/lib/cjs/hubtype-models.d.ts +0 -152
- package/lib/cjs/hubtype-models.js +0 -50
- package/lib/cjs/hubtype-models.js.map +0 -1
- package/lib/esm/content-fields/button.js.map +0 -1
- package/lib/esm/content-fields/carousel.d.ts +0 -10
- package/lib/esm/content-fields/carousel.js.map +0 -1
- package/lib/esm/content-fields/content-base.d.ts +0 -10
- package/lib/esm/content-fields/content-base.js +0 -11
- package/lib/esm/content-fields/content-base.js.map +0 -1
- package/lib/esm/content-fields/element.d.ts +0 -11
- package/lib/esm/content-fields/element.js.map +0 -1
- package/lib/esm/content-fields/image.d.ts +0 -9
- package/lib/esm/content-fields/image.js.map +0 -1
- package/lib/esm/content-fields/text.d.ts +0 -12
- package/lib/esm/content-fields/text.js.map +0 -1
- package/lib/esm/hubtype-models.d.ts +0 -152
- package/lib/esm/hubtype-models.js +0 -47
- package/lib/esm/hubtype-models.js.map +0 -1
- package/src/content-fields/carousel.tsx +0 -39
- package/src/content-fields/content-base.ts +0 -15
- 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
|
-
|
|
7
|
-
|
|
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;
|
|
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
|
-
'
|
|
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
|
-
|
|
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,
|
|
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"}
|
package/lib/cjs/handoff.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { ActionRequest } from '@botonic/react';
|
|
2
|
-
export declare function doHandoff(request: ActionRequest): Promise<
|
|
2
|
+
export declare function doHandoff(request: ActionRequest, queue: string, note?: string, agentEmail?: string): Promise<void>;
|
package/lib/cjs/handoff.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
if (
|
|
18
|
-
|
|
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
|
-
|
|
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
|
package/lib/cjs/handoff.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handoff.js","sourceRoot":"","sources":["../../src/handoff.ts"],"names":[],"mappings":";;;AAAA,
|
|
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"}
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { Input, Plugin, PluginPostRequest, PluginPreRequest } from '@botonic/core';
|
|
2
|
-
import { FlowContent } from './content-fields
|
|
3
|
-
import {
|
|
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
|
|
7
|
-
customFunctions
|
|
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<
|
|
20
|
+
readFlowContent(): Promise<FlowBuilderData>;
|
|
17
21
|
pre(request: PluginPreRequest): Promise<void>;
|
|
18
22
|
post(_request: PluginPostRequest): Promise<void>;
|
|
19
|
-
getContent(id: string): Promise<
|
|
20
|
-
getHandoffContent(): Promise<
|
|
21
|
-
getFlowContent(hubtypeContent:
|
|
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:
|
|
29
|
+
hasIntent(node: IntentNode, intent: string, locale: string): boolean;
|
|
25
30
|
getPayloadByKeyword(input: Input, locale: string): Promise<string | undefined>;
|
|
26
|
-
matchKeywords(node:
|
|
31
|
+
matchKeywords(node: KeywordNode, input: string, locale: string): boolean;
|
|
27
32
|
containsAnyKeywords(input: string, keywords: string[]): boolean;
|
|
28
|
-
callFunction(functionNode:
|
|
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
|
|
6
|
-
const
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
return
|
|
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(
|
|
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(
|
|
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
|
|
46
|
-
return
|
|
47
|
-
case
|
|
48
|
-
return
|
|
49
|
-
case
|
|
50
|
-
return
|
|
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 ===
|
|
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
|
|
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 ==
|
|
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
|
-
|
|
128
|
-
|
|
129
|
-
const nameValues = functionNode.content.arguments
|
|
130
|
-
.find(arg => arg.locale === locale)
|
|
131
|
-
|
|
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
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;AAOA,0DAAyB;AAEzB,qDAKyB;AACzB,+DAS8B;AAC9B,2CAA+C;AAU/C,MAAqB,wBAAwB;IAQ3C,YAAqB,OAAwC;QAAxC,YAAO,GAAP,OAAO,CAAiC;QAC3D,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAA;QAClC,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,CAAA;QAC5C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAA;QAC9B,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,IAAI,CAAC,eAAe,EAAE,CAAA;QAClD,MAAM,eAAe,G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AC,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"}
|
package/lib/cjs/utils.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
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.
|
|
4
|
-
function
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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.
|
|
9
|
+
exports.getWebpackEnvVar = getWebpackEnvVar;
|
|
10
10
|
//# sourceMappingURL=utils.js.map
|
package/lib/cjs/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;;
|
|
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"}
|
package/lib/esm/action.d.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { ActionRequest } from '@botonic/react';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import { FlowContent } from './content-fields
|
|
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
|
-
|
|
6
|
+
isHandoff?: boolean;
|
|
9
7
|
};
|
|
10
|
-
export
|
|
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
|
-
|
|
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
|
|
9
|
-
|
|
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,
|
|
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,
|
|
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,
|
|
22
|
-
if (content.length
|
|
23
|
-
const
|
|
24
|
-
|
|
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,
|
|
31
|
-
if (
|
|
32
|
-
|
|
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));
|
package/lib/esm/action.js.map
CHANGED
|
@@ -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,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E;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 {
|
|
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:
|
|
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 '../
|
|
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
|
|
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(
|
|
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((
|
|
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:
|
|
22
|
-
React.createElement(Title, { style: '' },
|
|
23
|
-
React.createElement(Subtitle, { style: '' },
|
|
24
|
-
React.createElement(Button, { payload: (_a =
|
|
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","s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Q,CAAY;gBAEhD,oBAAC,MAAM,IAAC,OAAO,EAAE,MAAA,OAAO,CAAC,OAAO,0CAAE,OAAO,IACtC,MAAA,OAAO,CAAC,OAAO,0CAAE,IAAI,CACf;oBAED,CACX,CAAA;SAAA,CAAC,CACO,CACZ,CAAA;IACH,CAAC;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 {
|
|
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
|