@botonic/plugin-flow-builder 0.21.0-alpha.5 → 0.21.0-alpha.7
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 -4
- package/lib/cjs/action.js +15 -10
- 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} +12 -6
- 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 +15 -13
- package/lib/cjs/index.js +44 -27
- 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 -4
- package/lib/esm/action.js +14 -10
- 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} +11 -5
- 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 +15 -13
- package/lib/esm/index.js +39 -24
- 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 +17 -16
- package/src/content-fields/content-fields-base.ts +15 -0
- package/src/content-fields/{button.tsx → flow-button.tsx} +13 -6
- 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 +79 -61
- 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 -160
- 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 -160
- 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 -200
|
@@ -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,11 +1,12 @@
|
|
|
1
1
|
import { Input, Plugin, PluginPostRequest, PluginPreRequest, Session } from '@botonic/core';
|
|
2
|
-
import { FlowContent } from './content-fields
|
|
3
|
-
import {
|
|
4
|
-
declare type BotonicPluginFlowBuilderOptions = {
|
|
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
8
|
getLocale: (session: Session) => string;
|
|
9
|
+
getAccessToken: () => string;
|
|
9
10
|
};
|
|
10
11
|
export default class BotonicPluginFlowBuilder implements Plugin {
|
|
11
12
|
readonly options: BotonicPluginFlowBuilderOptions;
|
|
@@ -13,21 +14,22 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
13
14
|
private flow;
|
|
14
15
|
private functions;
|
|
15
16
|
private currentRequest;
|
|
17
|
+
private getAccessToken;
|
|
16
18
|
getLocale: (session: Session) => string;
|
|
17
19
|
constructor(options: BotonicPluginFlowBuilderOptions);
|
|
18
|
-
readFlowContent(): Promise<
|
|
20
|
+
readFlowContent(): Promise<FlowBuilderData>;
|
|
19
21
|
pre(request: PluginPreRequest): Promise<void>;
|
|
20
22
|
post(_request: PluginPostRequest): Promise<void>;
|
|
21
|
-
getContent(id: string): Promise<
|
|
22
|
-
getHandoffContent(): Promise<
|
|
23
|
-
getFlowContent(hubtypeContent:
|
|
23
|
+
getContent(id: string): Promise<NodeComponent>;
|
|
24
|
+
getHandoffContent(): Promise<HandoffNode>;
|
|
25
|
+
getFlowContent(hubtypeContent: NodeComponent, locale: string): FlowContent | undefined;
|
|
24
26
|
getStartId(): Promise<string>;
|
|
25
27
|
getContents(id: string, locale: string, prevContents?: FlowContent[]): Promise<FlowContent[]>;
|
|
26
28
|
getPayloadByInput(input: Input, locale: string): Promise<string | undefined>;
|
|
27
|
-
hasIntent(node:
|
|
29
|
+
hasIntent(node: IntentNode, intent: string, locale: string): boolean;
|
|
28
30
|
getPayloadByKeyword(input: Input, locale: string): Promise<string | undefined>;
|
|
29
|
-
matchKeywords(node:
|
|
31
|
+
matchKeywords(node: KeywordNode, input: string, locale: string): boolean;
|
|
30
32
|
containsAnyKeywords(input: string, keywords: string[]): boolean;
|
|
31
|
-
callFunction(functionNode:
|
|
33
|
+
callFunction(functionNode: FunctionNode, locale: string): Promise<string>;
|
|
32
34
|
}
|
|
33
|
-
export {};
|
|
35
|
+
export { FlowBuilderAction } from './action';
|
package/lib/cjs/index.js
CHANGED
|
@@ -1,26 +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
|
-
this.getLocale = options.getLocale;
|
|
18
18
|
}
|
|
19
19
|
async readFlowContent() {
|
|
20
|
-
const response = await axios_1.default.get(this.flowUrl
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return
|
|
20
|
+
const response = await axios_1.default.get(this.flowUrl, {
|
|
21
|
+
headers: { Authorization: `Bearer ${this.getAccessToken()}` },
|
|
22
|
+
});
|
|
23
|
+
return response.data;
|
|
24
24
|
}
|
|
25
25
|
async pre(request) {
|
|
26
26
|
this.currentRequest = request;
|
|
@@ -29,33 +29,33 @@ class BotonicPluginFlowBuilder {
|
|
|
29
29
|
async post(_request) { }
|
|
30
30
|
async getContent(id) {
|
|
31
31
|
const flow = await this.flow;
|
|
32
|
-
const content = flow.nodes.find(
|
|
32
|
+
const content = flow.nodes.find(node => node.id === id);
|
|
33
33
|
if (!content)
|
|
34
|
-
throw Error(`
|
|
34
|
+
throw Error(`Node with id: '${id}' not found`);
|
|
35
35
|
return content;
|
|
36
36
|
}
|
|
37
37
|
async getHandoffContent() {
|
|
38
38
|
const flow = await this.flow;
|
|
39
|
-
const content = flow.nodes.find(
|
|
39
|
+
const content = flow.nodes.find(node => node.type === flow_builder_models_1.NodeType.HANDOFF);
|
|
40
40
|
if (!content)
|
|
41
41
|
throw Error(`Handoff node not found`);
|
|
42
42
|
return content;
|
|
43
43
|
}
|
|
44
44
|
getFlowContent(hubtypeContent, locale) {
|
|
45
45
|
switch (hubtypeContent.type) {
|
|
46
|
-
case
|
|
47
|
-
return
|
|
48
|
-
case
|
|
49
|
-
return
|
|
50
|
-
case
|
|
51
|
-
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);
|
|
52
52
|
default:
|
|
53
53
|
return undefined;
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
async getStartId() {
|
|
57
57
|
const flow = await this.flow;
|
|
58
|
-
const startNode = flow.nodes.find(
|
|
58
|
+
const startNode = flow.nodes.find(node => node.type === flow_builder_models_1.NodeType.START_UP);
|
|
59
59
|
if (!startNode) {
|
|
60
60
|
throw new Error('start-up id must be defined');
|
|
61
61
|
}
|
|
@@ -64,8 +64,18 @@ class BotonicPluginFlowBuilder {
|
|
|
64
64
|
async getContents(id, locale, prevContents) {
|
|
65
65
|
const contents = prevContents || [];
|
|
66
66
|
const hubtypeContent = await this.getContent(id);
|
|
67
|
+
if (hubtypeContent.content.buttons) {
|
|
68
|
+
for (const i in hubtypeContent.content.buttons) {
|
|
69
|
+
const button = hubtypeContent.content.buttons[i];
|
|
70
|
+
if (button.url) {
|
|
71
|
+
for (const j in button.url) {
|
|
72
|
+
button.url[j] = Object.assign(Object.assign({}, button.url[j]), (await this.getContent(button.url[j].id)));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
67
77
|
const content = await this.getFlowContent(hubtypeContent, locale);
|
|
68
|
-
if (hubtypeContent.type ===
|
|
78
|
+
if (hubtypeContent.type === flow_builder_models_1.NodeType.FUNCTION) {
|
|
69
79
|
const targetId = await this.callFunction(hubtypeContent, locale);
|
|
70
80
|
return this.getContents(targetId, locale, contents);
|
|
71
81
|
}
|
|
@@ -84,7 +94,7 @@ class BotonicPluginFlowBuilder {
|
|
|
84
94
|
var _a;
|
|
85
95
|
try {
|
|
86
96
|
const flow = await this.flow;
|
|
87
|
-
const intents = flow.nodes.filter(node => node.type
|
|
97
|
+
const intents = flow.nodes.filter(node => node.type === flow_builder_models_1.NodeType.INTENT);
|
|
88
98
|
if (input.intent) {
|
|
89
99
|
const matchedIntents = intents.filter(node =>
|
|
90
100
|
//@ts-ignore
|
|
@@ -107,7 +117,7 @@ class BotonicPluginFlowBuilder {
|
|
|
107
117
|
var _a;
|
|
108
118
|
try {
|
|
109
119
|
const flow = await this.flow;
|
|
110
|
-
const keywordNodes = flow.nodes.filter(node => node.type ==
|
|
120
|
+
const keywordNodes = flow.nodes.filter(node => node.type == flow_builder_models_1.NodeType.KEYWORD);
|
|
111
121
|
const matchedKeywordNodes = keywordNodes.filter(node =>
|
|
112
122
|
//@ts-ignore
|
|
113
123
|
this.matchKeywords(node, input.data, locale));
|
|
@@ -133,11 +143,13 @@ class BotonicPluginFlowBuilder {
|
|
|
133
143
|
return false;
|
|
134
144
|
}
|
|
135
145
|
async callFunction(functionNode, locale) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const nameValues = functionNode.content.arguments
|
|
139
|
-
.find(arg => arg.locale === locale)
|
|
140
|
-
|
|
146
|
+
var _a;
|
|
147
|
+
const functionNodeId = functionNode.id;
|
|
148
|
+
const nameValues = (_a = functionNode.content.arguments
|
|
149
|
+
.find(arg => arg.locale === locale)) === null || _a === void 0 ? void 0 : _a.values.map(value => ({ [value.name]: value.value }));
|
|
150
|
+
if (!nameValues) {
|
|
151
|
+
throw new Error(`No arguments found for node with id ${functionNodeId}`);
|
|
152
|
+
}
|
|
141
153
|
const args = Object.assign({
|
|
142
154
|
session: this.currentRequest.session,
|
|
143
155
|
results: [functionNode.content.result_mapping.map(r => r.result)],
|
|
@@ -145,8 +157,13 @@ class BotonicPluginFlowBuilder {
|
|
|
145
157
|
const functionResult = await this.functions[functionNode.content.action](args);
|
|
146
158
|
// TODO define result_mapping per locale??
|
|
147
159
|
const result = functionNode.content.result_mapping.find(r => r.result === functionResult);
|
|
160
|
+
if (!result) {
|
|
161
|
+
throw new Error(`No result found for result_mapping for node with id: ${functionNodeId}`);
|
|
162
|
+
}
|
|
148
163
|
return result.target.id;
|
|
149
164
|
}
|
|
150
165
|
}
|
|
151
166
|
exports.default = BotonicPluginFlowBuilder;
|
|
167
|
+
var action_1 = require("./action");
|
|
168
|
+
Object.defineProperty(exports, "FlowBuilderAction", { enumerable: true, get: function () { return action_1.FlowBuilderAction; } });
|
|
152
169
|
//# 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,YAAq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E,CAAC,GAAG,CAAC,MAAM,KAAK,MAAM,CAAC,0CACjC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;QACxD,IAAI,CAAC,UAAU,EAAE;YACf,MAAM,IAAI,KAAK,CAAC,uCAAuC,cAAc,EAAE,CAAC,CAAA;SACzE;QACD,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CACxB;YACE,OAAO,EAAE,IAAI,CAAC,cAAc,CAAC,OAAO;YACpC,OAAO,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,cAAc,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;AAnND,2CAmNC;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,12 +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';
|
|
3
|
+
import { FlowContent } from './content-fields';
|
|
5
4
|
declare type FlowBuilderActionProps = {
|
|
6
5
|
content?: FlowContent[];
|
|
7
|
-
|
|
6
|
+
isHandoff?: boolean;
|
|
8
7
|
};
|
|
9
|
-
export
|
|
8
|
+
export declare class FlowBuilderAction extends React.Component<FlowBuilderActionProps> {
|
|
10
9
|
static contextType: React.Context<import("@botonic/react").RequestContextInterface>;
|
|
11
10
|
static botonicInit(request: ActionRequest): Promise<any>;
|
|
12
11
|
render(): JSX.Element | JSX.Element[];
|
package/lib/esm/action.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { RequestContext, Text } from '@botonic/react';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { doHandoff } from './handoff';
|
|
4
|
-
export
|
|
4
|
+
export class FlowBuilderAction extends React.Component {
|
|
5
5
|
static async botonicInit(request) {
|
|
6
|
-
console.log(request);
|
|
7
6
|
const flowBuilderPlugin = request.plugins
|
|
8
|
-
.
|
|
7
|
+
.hubtypeFlowBuilder;
|
|
9
8
|
const locale = flowBuilderPlugin.getLocale(request.session);
|
|
10
9
|
let payload = request.input.payload
|
|
11
10
|
? request.input.payload
|
|
@@ -22,18 +21,23 @@ export default class FlowBuilderAction extends React.Component {
|
|
|
22
21
|
}
|
|
23
22
|
// We use only Spanish because they are the backend examples
|
|
24
23
|
const content = await flowBuilderPlugin.getContents(payload, locale);
|
|
25
|
-
if (content.length
|
|
26
|
-
const
|
|
27
|
-
|
|
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 };
|
|
28
33
|
}
|
|
29
34
|
return { content };
|
|
30
35
|
}
|
|
31
36
|
render() {
|
|
32
37
|
// @ts-ignore
|
|
33
|
-
const { content: contents,
|
|
34
|
-
if (
|
|
35
|
-
|
|
36
|
-
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!");
|
|
37
41
|
}
|
|
38
42
|
else {
|
|
39
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,KAAK,MAAM,OAAO,CAAA;AAGzB,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;
|
|
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;AAQrC,MAAM,OAAO,iBAAkB,SAAQ,KAAK,CAAC,SAAiC;IAG5E,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,OAAsB;QAC7C,MAAM,iBAAiB,GAAG,OAAO,CAAC,OAAO;aACtC,kBAA8C,CAAA;QACjD,MAAM,MAAM,GAAG,iBAAiB,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QAC3D,IAAI,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO;YACjC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO;YACvB,CAAC,CAAC,MAAM,iBAAiB,CAAC,UAAU,EAAE,CAAA;QAExC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE;YAC1B,MAAM,aAAa,GAAG,MAAM,iBAAiB,CAAC,iBAAiB,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 {
|
|
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);
|
|
@@ -12,15 +12,21 @@ export class FlowButton extends ContentFieldsBase {
|
|
|
12
12
|
const newButton = new FlowButton(component.id);
|
|
13
13
|
newButton.text = FlowButton.getTextByLocale(locale, component.text);
|
|
14
14
|
newButton.payload = (_a = component.target) === null || _a === void 0 ? void 0 : _a.id;
|
|
15
|
+
if (component.url) {
|
|
16
|
+
newButton.url = component.url.find(url => url.locale === locale).content.url;
|
|
17
|
+
}
|
|
15
18
|
return newButton;
|
|
16
19
|
}
|
|
17
20
|
renderButton(index, buttonStyle) {
|
|
18
|
-
if (buttonStyle
|
|
21
|
+
if (buttonStyle === ButtonStyle.QUICK_REPLY) {
|
|
19
22
|
return (React.createElement(Reply, { payload: this.payload, key: index }, this.text));
|
|
20
23
|
}
|
|
24
|
+
let props = {};
|
|
25
|
+
if (this.url)
|
|
26
|
+
props = { url: this.url };
|
|
21
27
|
return (
|
|
22
28
|
// @ts-ignore
|
|
23
|
-
React.createElement(Button, { payload: this.payload, key: index }, this.text));
|
|
29
|
+
React.createElement(Button, Object.assign({ payload: this.payload, key: index }, props), this.text));
|
|
24
30
|
}
|
|
25
31
|
}
|
|
26
|
-
//# sourceMappingURL=button.js.map
|
|
32
|
+
//# 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;IAiClB,CAAC;IA7BC,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,IAAI,SAAS,CAAC,GAAG,EAAE;YACjB,SAAS,CAAC,GAAG,GAAI,SAAS,CAAC,GAAW,CAAC,IAAI,CACzC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,KAAK,MAAM,CAC7B,CAAC,OAAO,CAAC,GAAG,CAAA;SACd;QACD,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,IAAI,KAAK,GAAG,EAAE,CAAA;QACd,IAAI,IAAI,CAAC,GAAG;YAAE,KAAK,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,CAAA;QACvC,OAAO;QACL,aAAa;QACb,oBAAC,MAAM,kBAAC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,KAAK,IAAM,KAAK,GACjD,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","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,MAAM,OAAO,CAAA;AAGzB,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE5C,MA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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
|
+
}
|