@botonic/plugin-flow-builder 0.25.0 → 0.26.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/action/index.d.ts +3 -8
- package/lib/cjs/constants.d.ts +1 -0
- package/lib/cjs/constants.js +2 -1
- package/lib/cjs/constants.js.map +1 -1
- package/lib/cjs/index.d.ts +2 -1
- package/lib/cjs/index.js +8 -1
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/types.d.ts +6 -1
- package/lib/cjs/types.js +6 -1
- package/lib/cjs/types.js.map +1 -1
- package/lib/cjs/webview/contents-context.d.ts +3 -0
- package/lib/cjs/webview/contents-context.js +10 -0
- package/lib/cjs/webview/contents-context.js.map +1 -0
- package/lib/cjs/webview/index.d.ts +3 -0
- package/lib/cjs/webview/index.js +10 -0
- package/lib/cjs/webview/index.js.map +1 -0
- package/lib/cjs/webview/types.d.ts +46 -0
- package/lib/cjs/webview/types.js +9 -0
- package/lib/cjs/webview/types.js.map +1 -0
- package/lib/cjs/webview/use-webview-contents.d.ts +2 -0
- package/lib/cjs/webview/use-webview-contents.js +58 -0
- package/lib/cjs/webview/use-webview-contents.js.map +1 -0
- package/lib/esm/action/index.d.ts +3 -8
- package/lib/esm/constants.d.ts +1 -0
- package/lib/esm/constants.js +1 -0
- package/lib/esm/constants.js.map +1 -1
- package/lib/esm/index.d.ts +2 -1
- package/lib/esm/index.js +7 -2
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/types.d.ts +6 -1
- package/lib/esm/types.js +5 -0
- package/lib/esm/types.js.map +1 -1
- package/lib/esm/webview/contents-context.d.ts +3 -0
- package/lib/esm/webview/contents-context.js +7 -0
- package/lib/esm/webview/contents-context.js.map +1 -0
- package/lib/esm/webview/index.d.ts +3 -0
- package/lib/esm/webview/index.js +4 -0
- package/lib/esm/webview/index.js.map +1 -0
- package/lib/esm/webview/types.d.ts +46 -0
- package/lib/esm/webview/types.js +6 -0
- package/lib/esm/webview/types.js.map +1 -0
- package/lib/esm/webview/use-webview-contents.d.ts +2 -0
- package/lib/esm/webview/use-webview-contents.js +54 -0
- package/lib/esm/webview/use-webview-contents.js.map +1 -0
- package/package.json +2 -2
- package/src/constants.ts +2 -0
- package/src/index.ts +15 -3
- package/src/types.ts +7 -1
- package/src/webview/contents-context.ts +11 -0
- package/src/webview/index.ts +3 -0
- package/src/webview/types.ts +47 -0
- package/src/webview/use-webview-contents.ts +78 -0
|
@@ -5,14 +5,9 @@ export type FlowBuilderActionProps = {
|
|
|
5
5
|
contents: FlowContent[];
|
|
6
6
|
};
|
|
7
7
|
export declare class FlowBuilderAction extends React.Component<FlowBuilderActionProps> {
|
|
8
|
-
static contextType: React.Context<{
|
|
9
|
-
getString: () =>
|
|
10
|
-
setLocale: () =>
|
|
11
|
-
session: {};
|
|
12
|
-
params: {};
|
|
13
|
-
input: {};
|
|
14
|
-
defaultDelay: number;
|
|
15
|
-
defaultTyping: number;
|
|
8
|
+
static contextType: React.Context<Partial<ActionRequest> & {
|
|
9
|
+
getString: () => string;
|
|
10
|
+
setLocale: () => void;
|
|
16
11
|
}>;
|
|
17
12
|
static botonicInit(request: ActionRequest): Promise<FlowBuilderActionProps>;
|
|
18
13
|
render(): JSX.Element | JSX.Element[];
|
package/lib/cjs/constants.d.ts
CHANGED
package/lib/cjs/constants.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.REG_EXP_PATTERN = exports.ACCESS_TOKEN_VARIABLE_KEY = exports.VARIABLE_PATTERN = exports.SOURCE_INFO_SEPARATOR = exports.SEPARATOR = void 0;
|
|
3
|
+
exports.REG_EXP_PATTERN = exports.ACCESS_TOKEN_VARIABLE_KEY = exports.VARIABLE_PATTERN = exports.SOURCE_INFO_SEPARATOR = exports.SEPARATOR = exports.FLOW_BUILDER_API_URL_PROD = void 0;
|
|
4
|
+
exports.FLOW_BUILDER_API_URL_PROD = 'https://api.ent0.flowbuilder.prod.hubtype.com';
|
|
4
5
|
exports.SEPARATOR = '|';
|
|
5
6
|
exports.SOURCE_INFO_SEPARATOR = `${exports.SEPARATOR}source_`;
|
|
6
7
|
exports.VARIABLE_PATTERN = /{([^}]+)}/g;
|
package/lib/cjs/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,SAAS,GAAG,GAAG,CAAA;AACf,QAAA,qBAAqB,GAAG,GAAG,iBAAS,SAAS,CAAA;AAC7C,QAAA,gBAAgB,GAAG,YAAY,CAAA;AAC/B,QAAA,yBAAyB,GAAG,eAAe,CAAA;AAC3C,QAAA,eAAe,GAAG,uBAAuB,CAAA"}
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,yBAAyB,GACpC,+CAA+C,CAAA;AACpC,QAAA,SAAS,GAAG,GAAG,CAAA;AACf,QAAA,qBAAqB,GAAG,GAAG,iBAAS,SAAS,CAAA;AAC7C,QAAA,gBAAgB,GAAG,YAAY,CAAA;AAC/B,QAAA,yBAAyB,GAAG,eAAe,CAAA;AAC3C,QAAA,eAAe,GAAG,uBAAuB,CAAA"}
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -29,4 +29,5 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
29
29
|
}
|
|
30
30
|
export * from './action';
|
|
31
31
|
export * from './content-fields';
|
|
32
|
-
export { BotonicPluginFlowBuilderOptions, PayloadParamsBase } from './types';
|
|
32
|
+
export { BotonicPluginFlowBuilderOptions, FlowBuilderJSONVersion, PayloadParamsBase, } from './types';
|
|
33
|
+
export * from './webview';
|
package/lib/cjs/index.js
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FlowBuilderJSONVersion = void 0;
|
|
3
4
|
const tslib_1 = require("tslib");
|
|
4
5
|
const api_1 = require("./api");
|
|
5
6
|
const constants_1 = require("./constants");
|
|
6
7
|
const content_fields_1 = require("./content-fields");
|
|
7
8
|
const hubtype_fields_1 = require("./content-fields/hubtype-fields");
|
|
8
9
|
const functions_1 = require("./functions");
|
|
10
|
+
const types_1 = require("./types");
|
|
9
11
|
const user_input_1 = require("./user-input");
|
|
10
12
|
const utils_1 = require("./utils");
|
|
11
13
|
class BotonicPluginFlowBuilder {
|
|
12
14
|
constructor(options) {
|
|
13
15
|
this.options = options;
|
|
14
|
-
|
|
16
|
+
const apiUrl = options.apiUrl || constants_1.FLOW_BUILDER_API_URL_PROD;
|
|
17
|
+
const jsonVersion = options.jsonVersion || types_1.FlowBuilderJSONVersion.LATEST;
|
|
18
|
+
this.flowUrl = `${apiUrl}/flow/${jsonVersion}`;
|
|
15
19
|
this.flow = options.flow;
|
|
16
20
|
this.getLocale = options.getLocale;
|
|
17
21
|
this.getAccessToken = (0, utils_1.resolveGetAccessToken)(options);
|
|
@@ -143,4 +147,7 @@ class BotonicPluginFlowBuilder {
|
|
|
143
147
|
exports.default = BotonicPluginFlowBuilder;
|
|
144
148
|
tslib_1.__exportStar(require("./action"), exports);
|
|
145
149
|
tslib_1.__exportStar(require("./content-fields"), exports);
|
|
150
|
+
var types_2 = require("./types");
|
|
151
|
+
Object.defineProperty(exports, "FlowBuilderJSONVersion", { enumerable: true, get: function () { return types_2.FlowBuilderJSONVersion; } });
|
|
152
|
+
tslib_1.__exportStar(require("./webview"), exports);
|
|
146
153
|
//# 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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,sBAAsB,OAAA;AAGxB,oDAAyB"}
|
package/lib/cjs/types.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ import { PluginPreRequest, Session } from '@botonic/core';
|
|
|
2
2
|
import { ActionRequest } from '@botonic/react';
|
|
3
3
|
import { HtFlowBuilderData } from './content-fields/hubtype-fields';
|
|
4
4
|
export interface BotonicPluginFlowBuilderOptions {
|
|
5
|
-
|
|
5
|
+
apiUrl?: string;
|
|
6
|
+
jsonVersion?: FlowBuilderJSONVersion;
|
|
6
7
|
flow?: HtFlowBuilderData;
|
|
7
8
|
customFunctions?: Record<any, any>;
|
|
8
9
|
getLocale: (session: Session) => string;
|
|
@@ -20,6 +21,10 @@ export declare enum ProcessEnvNodeEnvs {
|
|
|
20
21
|
PRODUCTION = "production",
|
|
21
22
|
DEVELOPMENT = "development"
|
|
22
23
|
}
|
|
24
|
+
export declare enum FlowBuilderJSONVersion {
|
|
25
|
+
DRAFT = "draft",
|
|
26
|
+
LATEST = "latest"
|
|
27
|
+
}
|
|
23
28
|
export interface KnowledgeBaseResponse {
|
|
24
29
|
answer: string;
|
|
25
30
|
hasKnowledge: boolean;
|
package/lib/cjs/types.js
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ProcessEnvNodeEnvs = void 0;
|
|
3
|
+
exports.FlowBuilderJSONVersion = exports.ProcessEnvNodeEnvs = void 0;
|
|
4
4
|
var ProcessEnvNodeEnvs;
|
|
5
5
|
(function (ProcessEnvNodeEnvs) {
|
|
6
6
|
ProcessEnvNodeEnvs["PRODUCTION"] = "production";
|
|
7
7
|
ProcessEnvNodeEnvs["DEVELOPMENT"] = "development";
|
|
8
8
|
})(ProcessEnvNodeEnvs = exports.ProcessEnvNodeEnvs || (exports.ProcessEnvNodeEnvs = {}));
|
|
9
|
+
var FlowBuilderJSONVersion;
|
|
10
|
+
(function (FlowBuilderJSONVersion) {
|
|
11
|
+
FlowBuilderJSONVersion["DRAFT"] = "draft";
|
|
12
|
+
FlowBuilderJSONVersion["LATEST"] = "latest";
|
|
13
|
+
})(FlowBuilderJSONVersion = exports.FlowBuilderJSONVersion || (exports.FlowBuilderJSONVersion = {}));
|
|
9
14
|
//# sourceMappingURL=types.js.map
|
package/lib/cjs/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";;;AA6BA,IAAY,kBAGX;AAHD,WAAY,kBAAkB;IAC5B,+CAAyB,CAAA;IACzB,iDAA2B,CAAA;AAC7B,CAAC,EAHW,kBAAkB,GAAlB,0BAAkB,KAAlB,0BAAkB,QAG7B;AAED,IAAY,sBAGX;AAHD,WAAY,sBAAsB;IAChC,yCAAe,CAAA;IACf,2CAAiB,CAAA;AACnB,CAAC,EAHW,sBAAsB,GAAtB,8BAAsB,KAAtB,8BAAsB,QAGjC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WebviewContentsContext = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
exports.WebviewContentsContext = (0, react_1.createContext)({
|
|
6
|
+
getTextContent: () => undefined,
|
|
7
|
+
getImageSrc: () => undefined,
|
|
8
|
+
setCurrentLocale: () => undefined,
|
|
9
|
+
});
|
|
10
|
+
//# sourceMappingURL=contents-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contents-context.js","sourceRoot":"","sources":["../../../src/webview/contents-context.ts"],"names":[],"mappings":";;;AAAA,iCAAqC;AAIxB,QAAA,sBAAsB,GAAG,IAAA,qBAAa,EACjD;IACE,cAAc,EAAE,GAAG,EAAE,CAAC,SAAS;IAC/B,WAAW,EAAE,GAAG,EAAE,CAAC,SAAS;IAC5B,gBAAgB,EAAE,GAAG,EAAE,CAAC,SAAS;CAClC,CACF,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useWebviewContents = exports.WebviewContentsContext = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
var contents_context_1 = require("./contents-context");
|
|
6
|
+
Object.defineProperty(exports, "WebviewContentsContext", { enumerable: true, get: function () { return contents_context_1.WebviewContentsContext; } });
|
|
7
|
+
tslib_1.__exportStar(require("./types"), exports);
|
|
8
|
+
var use_webview_contents_1 = require("./use-webview-contents");
|
|
9
|
+
Object.defineProperty(exports, "useWebviewContents", { enumerable: true, get: function () { return use_webview_contents_1.useWebviewContents; } });
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/webview/index.ts"],"names":[],"mappings":";;;;AAAA,uDAA2D;AAAlD,0HAAA,sBAAsB,OAAA;AAC/B,kDAAuB;AACvB,+DAA2D;AAAlD,0HAAA,kBAAkB,OAAA"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { FlowBuilderJSONVersion } from '../types';
|
|
2
|
+
export declare enum WebviewContentType {
|
|
3
|
+
TEXT = "webview-text",
|
|
4
|
+
IMAGE = "webview-image"
|
|
5
|
+
}
|
|
6
|
+
export interface WebviewContentsResponse {
|
|
7
|
+
webview_contents: (WebviewTextContent | WebviewImageContent)[];
|
|
8
|
+
}
|
|
9
|
+
export interface WebviewTextContent {
|
|
10
|
+
code: string;
|
|
11
|
+
type: WebviewContentType.TEXT;
|
|
12
|
+
content: {
|
|
13
|
+
text: {
|
|
14
|
+
message: string;
|
|
15
|
+
locale: string;
|
|
16
|
+
}[];
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export interface WebviewImageContent {
|
|
20
|
+
code: string;
|
|
21
|
+
type: WebviewContentType.IMAGE;
|
|
22
|
+
content: {
|
|
23
|
+
image: {
|
|
24
|
+
file: string;
|
|
25
|
+
locale: string;
|
|
26
|
+
}[];
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export interface UseWebviewContentsProps {
|
|
30
|
+
apiUrl?: string;
|
|
31
|
+
version?: FlowBuilderJSONVersion;
|
|
32
|
+
orgId: string;
|
|
33
|
+
botId: string;
|
|
34
|
+
webviewId: string;
|
|
35
|
+
locale: string;
|
|
36
|
+
}
|
|
37
|
+
export interface UseWebviewContents {
|
|
38
|
+
isLoading: boolean;
|
|
39
|
+
error: boolean;
|
|
40
|
+
webviewContentsContext: WebviewContentsContextType;
|
|
41
|
+
}
|
|
42
|
+
export interface WebviewContentsContextType {
|
|
43
|
+
getTextContent: (code: string) => string | undefined;
|
|
44
|
+
getImageSrc: (code: string) => string | undefined;
|
|
45
|
+
setCurrentLocale: (locale: string) => void;
|
|
46
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WebviewContentType = void 0;
|
|
4
|
+
var WebviewContentType;
|
|
5
|
+
(function (WebviewContentType) {
|
|
6
|
+
WebviewContentType["TEXT"] = "webview-text";
|
|
7
|
+
WebviewContentType["IMAGE"] = "webview-image";
|
|
8
|
+
})(WebviewContentType = exports.WebviewContentType || (exports.WebviewContentType = {}));
|
|
9
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/webview/types.ts"],"names":[],"mappings":";;;AAEA,IAAY,kBAGX;AAHD,WAAY,kBAAkB;IAC5B,2CAAqB,CAAA;IACrB,6CAAuB,CAAA;AACzB,CAAC,EAHW,kBAAkB,GAAlB,0BAAkB,KAAlB,0BAAkB,QAG7B"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useWebviewContents = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const axios_1 = tslib_1.__importDefault(require("axios"));
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const constants_1 = require("../constants");
|
|
8
|
+
const types_1 = require("../types");
|
|
9
|
+
const types_2 = require("./types");
|
|
10
|
+
function useWebviewContents({ apiUrl = constants_1.FLOW_BUILDER_API_URL_PROD, version = types_1.FlowBuilderJSONVersion.LATEST, orgId, botId, webviewId, locale, }) {
|
|
11
|
+
const [textContents, setTextContents] = (0, react_1.useState)();
|
|
12
|
+
const [imageContents, setImageContents] = (0, react_1.useState)();
|
|
13
|
+
const [currentLocale, setCurrentLocale] = (0, react_1.useState)(locale);
|
|
14
|
+
const [isLoading, setLoading] = (0, react_1.useState)(false);
|
|
15
|
+
const [error, setError] = (0, react_1.useState)(false);
|
|
16
|
+
(0, react_1.useEffect)(() => {
|
|
17
|
+
const getResponseContents = () => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
setLoading(true);
|
|
19
|
+
const url = `${apiUrl}/webview/${version}`;
|
|
20
|
+
try {
|
|
21
|
+
const response = yield axios_1.default.get(url, {
|
|
22
|
+
params: { org: orgId, bot: botId, webview: webviewId },
|
|
23
|
+
});
|
|
24
|
+
const textResponseContents = response.data.webview_contents.filter(webviewContent => webviewContent.type === types_2.WebviewContentType.TEXT);
|
|
25
|
+
setTextContents(textResponseContents);
|
|
26
|
+
const imageResponseContents = response.data.webview_contents.filter(webviewContent => webviewContent.type === types_2.WebviewContentType.IMAGE);
|
|
27
|
+
setImageContents(imageResponseContents);
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
console.error('Error fetching webview contents:', error);
|
|
31
|
+
setError(true);
|
|
32
|
+
}
|
|
33
|
+
finally {
|
|
34
|
+
setLoading(false);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
getResponseContents();
|
|
38
|
+
}, []);
|
|
39
|
+
const getTextContent = (contentID) => {
|
|
40
|
+
var _a, _b;
|
|
41
|
+
return (_b = (_a = textContents === null || textContents === void 0 ? void 0 : textContents.find(textContent => textContent.code === contentID)) === null || _a === void 0 ? void 0 : _a.content.text.find(text => text.locale === currentLocale)) === null || _b === void 0 ? void 0 : _b.message;
|
|
42
|
+
};
|
|
43
|
+
const getImageSrc = (contentID) => {
|
|
44
|
+
var _a, _b;
|
|
45
|
+
return (_b = (_a = imageContents === null || imageContents === void 0 ? void 0 : imageContents.find(imageContent => imageContent.code === contentID)) === null || _a === void 0 ? void 0 : _a.content.image.find(image => image.locale === currentLocale)) === null || _b === void 0 ? void 0 : _b.file;
|
|
46
|
+
};
|
|
47
|
+
return {
|
|
48
|
+
isLoading,
|
|
49
|
+
error,
|
|
50
|
+
webviewContentsContext: {
|
|
51
|
+
getTextContent,
|
|
52
|
+
getImageSrc,
|
|
53
|
+
setCurrentLocale,
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
exports.useWebviewContents = useWebviewContents;
|
|
58
|
+
//# sourceMappingURL=use-webview-contents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-webview-contents.js","sourceRoot":"","sources":["../../../src/webview/use-webview-contents.ts"],"names":[],"mappings":";;;;AAAA,0DAAyB;AACzB,iCAA2C;AAE3C,4CAAwD;AACxD,oCAAiD;AACjD,mCAOgB;AAEhB,SAAgB,kBAAkB,CAAC,EACjC,MAAM,GAAG,qCAAyB,EAClC,OAAO,GAAG,8BAAsB,CAAC,MAAM,EACvC,KAAK,EACL,KAAK,EACL,SAAS,EACT,MAAM,GACkB;IACxB,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,IAAA,gBAAQ,GAAwB,CAAA;IACxE,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,IAA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AK,CAAC,CAAA;aAClB;QACH,CAAC,CAAA,CAAA;QACD,mBAAmB,EAAE,CAAA;IACvB,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,MAAM,cAAc,GAAG,CAAC,SAAiB,EAAsB,EAAE;;QAC/D,OAAO,MAAA,MAAA,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CACf,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,WAAW,CAAC,IAAI,KAAK,SAAS,CAAC,0CACnD,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,KAAK,aAAa,CAAC,0CAAE,OAAO,CAAA;IACvE,CAAC,CAAA;IAED,MAAM,WAAW,GAAG,CAAC,SAAiB,EAAsB,EAAE;;QAC5D,OAAO,MAAA,MAAA,aAAa,aAAb,aAAa,uBAAb,aAAa,CAChB,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,KAAK,SAAS,CAAC,0CACrD,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,KAAK,aAAa,CAAC,0CAAE,IAAI,CAAA;IACvE,CAAC,CAAA;IAED,OAAO;QACL,SAAS;QACT,KAAK;QACL,sBAAsB,EAAE;YACtB,cAAc;YACd,WAAW;YACX,gBAAgB;SACjB;KACF,CAAA;AACH,CAAC;AA/DD,gDA+DC"}
|
|
@@ -5,14 +5,9 @@ export type FlowBuilderActionProps = {
|
|
|
5
5
|
contents: FlowContent[];
|
|
6
6
|
};
|
|
7
7
|
export declare class FlowBuilderAction extends React.Component<FlowBuilderActionProps> {
|
|
8
|
-
static contextType: React.Context<{
|
|
9
|
-
getString: () =>
|
|
10
|
-
setLocale: () =>
|
|
11
|
-
session: {};
|
|
12
|
-
params: {};
|
|
13
|
-
input: {};
|
|
14
|
-
defaultDelay: number;
|
|
15
|
-
defaultTyping: number;
|
|
8
|
+
static contextType: React.Context<Partial<ActionRequest> & {
|
|
9
|
+
getString: () => string;
|
|
10
|
+
setLocale: () => void;
|
|
16
11
|
}>;
|
|
17
12
|
static botonicInit(request: ActionRequest): Promise<FlowBuilderActionProps>;
|
|
18
13
|
render(): JSX.Element | JSX.Element[];
|
package/lib/esm/constants.d.ts
CHANGED
package/lib/esm/constants.js
CHANGED
package/lib/esm/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,CAAA;AAC5B,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,SAAS,SAAS,CAAA;AAC1D,MAAM,CAAC,MAAM,gBAAgB,GAAG,YAAY,CAAA;AAC5C,MAAM,CAAC,MAAM,yBAAyB,GAAG,eAAe,CAAA;AACxD,MAAM,CAAC,MAAM,eAAe,GAAG,uBAAuB,CAAA"}
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,yBAAyB,GACpC,+CAA+C,CAAA;AACjD,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,CAAA;AAC5B,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,SAAS,SAAS,CAAA;AAC1D,MAAM,CAAC,MAAM,gBAAgB,GAAG,YAAY,CAAA;AAC5C,MAAM,CAAC,MAAM,yBAAyB,GAAG,eAAe,CAAA;AACxD,MAAM,CAAC,MAAM,eAAe,GAAG,uBAAuB,CAAA"}
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -29,4 +29,5 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
29
29
|
}
|
|
30
30
|
export * from './action';
|
|
31
31
|
export * from './content-fields';
|
|
32
|
-
export { BotonicPluginFlowBuilderOptions, PayloadParamsBase } from './types';
|
|
32
|
+
export { BotonicPluginFlowBuilderOptions, FlowBuilderJSONVersion, PayloadParamsBase, } from './types';
|
|
33
|
+
export * from './webview';
|
package/lib/esm/index.js
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
2
|
import { FlowBuilderApi } from './api';
|
|
3
|
-
import { SEPARATOR, SOURCE_INFO_SEPARATOR } from './constants';
|
|
3
|
+
import { FLOW_BUILDER_API_URL_PROD, SEPARATOR, SOURCE_INFO_SEPARATOR, } from './constants';
|
|
4
4
|
import { FlowCarousel, FlowHandoff, FlowImage, FlowText, FlowVideo, FlowWhatsappButtonList, } from './content-fields';
|
|
5
5
|
import { HtNodeWithContentType, } from './content-fields/hubtype-fields';
|
|
6
6
|
import { DEFAULT_FUNCTIONS } from './functions';
|
|
7
|
+
import { FlowBuilderJSONVersion, } from './types';
|
|
7
8
|
import { getNodeByUserInput } from './user-input';
|
|
8
9
|
import { resolveGetAccessToken } from './utils';
|
|
9
10
|
export default class BotonicPluginFlowBuilder {
|
|
10
11
|
constructor(options) {
|
|
11
12
|
this.options = options;
|
|
12
|
-
|
|
13
|
+
const apiUrl = options.apiUrl || FLOW_BUILDER_API_URL_PROD;
|
|
14
|
+
const jsonVersion = options.jsonVersion || FlowBuilderJSONVersion.LATEST;
|
|
15
|
+
this.flowUrl = `${apiUrl}/flow/${jsonVersion}`;
|
|
13
16
|
this.flow = options.flow;
|
|
14
17
|
this.getLocale = options.getLocale;
|
|
15
18
|
this.getAccessToken = resolveGetAccessToken(options);
|
|
@@ -140,4 +143,6 @@ export default class BotonicPluginFlowBuilder {
|
|
|
140
143
|
}
|
|
141
144
|
export * from './action';
|
|
142
145
|
export * from './content-fields';
|
|
146
|
+
export { FlowBuilderJSONVersion, } from './types';
|
|
147
|
+
export * from './webview';
|
|
143
148
|
//# sourceMappingURL=index.js.map
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":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E;gBAC5C,eAAe,GAAG,CAAC,GAAG,eAAe,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,CAAA;aACtD;YACD,IAAI,MAAM,IAAI,GAAG,EAAE;gBACjB,eAAe,GAAG,CAAC,GAAG,eAAe,EAAE,GAAG,CAAC,CAAA;aAC5C;SACF;QAED,OAAO,eAAe,CAAA;IACxB,CAAC;IAED,gBAAgB,CAA8B,OAAe;QAC3D,MAAM,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAA;QACrE,OAAO,aAAa,CAAA;IACtB,CAAC;CACF;AAED,cAAc,UAAU,CAAA;AACxB,cAAc,kBAAkB,CAAA;AAChC,OAAO,EAEL,sBAAsB,GAEvB,MAAM,SAAS,CAAA;AAChB,cAAc,WAAW,CAAA"}
|
package/lib/esm/types.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ import { PluginPreRequest, Session } from '@botonic/core';
|
|
|
2
2
|
import { ActionRequest } from '@botonic/react';
|
|
3
3
|
import { HtFlowBuilderData } from './content-fields/hubtype-fields';
|
|
4
4
|
export interface BotonicPluginFlowBuilderOptions {
|
|
5
|
-
|
|
5
|
+
apiUrl?: string;
|
|
6
|
+
jsonVersion?: FlowBuilderJSONVersion;
|
|
6
7
|
flow?: HtFlowBuilderData;
|
|
7
8
|
customFunctions?: Record<any, any>;
|
|
8
9
|
getLocale: (session: Session) => string;
|
|
@@ -20,6 +21,10 @@ export declare enum ProcessEnvNodeEnvs {
|
|
|
20
21
|
PRODUCTION = "production",
|
|
21
22
|
DEVELOPMENT = "development"
|
|
22
23
|
}
|
|
24
|
+
export declare enum FlowBuilderJSONVersion {
|
|
25
|
+
DRAFT = "draft",
|
|
26
|
+
LATEST = "latest"
|
|
27
|
+
}
|
|
23
28
|
export interface KnowledgeBaseResponse {
|
|
24
29
|
answer: string;
|
|
25
30
|
hasKnowledge: boolean;
|
package/lib/esm/types.js
CHANGED
|
@@ -3,4 +3,9 @@ export var ProcessEnvNodeEnvs;
|
|
|
3
3
|
ProcessEnvNodeEnvs["PRODUCTION"] = "production";
|
|
4
4
|
ProcessEnvNodeEnvs["DEVELOPMENT"] = "development";
|
|
5
5
|
})(ProcessEnvNodeEnvs || (ProcessEnvNodeEnvs = {}));
|
|
6
|
+
export var FlowBuilderJSONVersion;
|
|
7
|
+
(function (FlowBuilderJSONVersion) {
|
|
8
|
+
FlowBuilderJSONVersion["DRAFT"] = "draft";
|
|
9
|
+
FlowBuilderJSONVersion["LATEST"] = "latest";
|
|
10
|
+
})(FlowBuilderJSONVersion || (FlowBuilderJSONVersion = {}));
|
|
6
11
|
//# sourceMappingURL=types.js.map
|
package/lib/esm/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AA6BA,MAAM,CAAN,IAAY,kBAGX;AAHD,WAAY,kBAAkB;IAC5B,+CAAyB,CAAA;IACzB,iDAA2B,CAAA;AAC7B,CAAC,EAHW,kBAAkB,KAAlB,kBAAkB,QAG7B;AAED,MAAM,CAAN,IAAY,sBAGX;AAHD,WAAY,sBAAsB;IAChC,yCAAe,CAAA;IACf,2CAAiB,CAAA;AACnB,CAAC,EAHW,sBAAsB,KAAtB,sBAAsB,QAGjC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contents-context.js","sourceRoot":"","sources":["../../../src/webview/contents-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAIrC,MAAM,CAAC,MAAM,sBAAsB,GAAG,aAAa,CACjD;IACE,cAAc,EAAE,GAAG,EAAE,CAAC,SAAS;IAC/B,WAAW,EAAE,GAAG,EAAE,CAAC,SAAS;IAC5B,gBAAgB,EAAE,GAAG,EAAE,CAAC,SAAS;CAClC,CACF,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/webview/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAA;AAC3D,cAAc,SAAS,CAAA;AACvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { FlowBuilderJSONVersion } from '../types';
|
|
2
|
+
export declare enum WebviewContentType {
|
|
3
|
+
TEXT = "webview-text",
|
|
4
|
+
IMAGE = "webview-image"
|
|
5
|
+
}
|
|
6
|
+
export interface WebviewContentsResponse {
|
|
7
|
+
webview_contents: (WebviewTextContent | WebviewImageContent)[];
|
|
8
|
+
}
|
|
9
|
+
export interface WebviewTextContent {
|
|
10
|
+
code: string;
|
|
11
|
+
type: WebviewContentType.TEXT;
|
|
12
|
+
content: {
|
|
13
|
+
text: {
|
|
14
|
+
message: string;
|
|
15
|
+
locale: string;
|
|
16
|
+
}[];
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export interface WebviewImageContent {
|
|
20
|
+
code: string;
|
|
21
|
+
type: WebviewContentType.IMAGE;
|
|
22
|
+
content: {
|
|
23
|
+
image: {
|
|
24
|
+
file: string;
|
|
25
|
+
locale: string;
|
|
26
|
+
}[];
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export interface UseWebviewContentsProps {
|
|
30
|
+
apiUrl?: string;
|
|
31
|
+
version?: FlowBuilderJSONVersion;
|
|
32
|
+
orgId: string;
|
|
33
|
+
botId: string;
|
|
34
|
+
webviewId: string;
|
|
35
|
+
locale: string;
|
|
36
|
+
}
|
|
37
|
+
export interface UseWebviewContents {
|
|
38
|
+
isLoading: boolean;
|
|
39
|
+
error: boolean;
|
|
40
|
+
webviewContentsContext: WebviewContentsContextType;
|
|
41
|
+
}
|
|
42
|
+
export interface WebviewContentsContextType {
|
|
43
|
+
getTextContent: (code: string) => string | undefined;
|
|
44
|
+
getImageSrc: (code: string) => string | undefined;
|
|
45
|
+
setCurrentLocale: (locale: string) => void;
|
|
46
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/webview/types.ts"],"names":[],"mappings":"AAEA,MAAM,CAAN,IAAY,kBAGX;AAHD,WAAY,kBAAkB;IAC5B,2CAAqB,CAAA;IACrB,6CAAuB,CAAA;AACzB,CAAC,EAHW,kBAAkB,KAAlB,kBAAkB,QAG7B"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
import { useEffect, useState } from 'react';
|
|
4
|
+
import { FLOW_BUILDER_API_URL_PROD } from '../constants';
|
|
5
|
+
import { FlowBuilderJSONVersion } from '../types';
|
|
6
|
+
import { WebviewContentType, } from './types';
|
|
7
|
+
export function useWebviewContents({ apiUrl = FLOW_BUILDER_API_URL_PROD, version = FlowBuilderJSONVersion.LATEST, orgId, botId, webviewId, locale, }) {
|
|
8
|
+
const [textContents, setTextContents] = useState();
|
|
9
|
+
const [imageContents, setImageContents] = useState();
|
|
10
|
+
const [currentLocale, setCurrentLocale] = useState(locale);
|
|
11
|
+
const [isLoading, setLoading] = useState(false);
|
|
12
|
+
const [error, setError] = useState(false);
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
const getResponseContents = () => __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
setLoading(true);
|
|
16
|
+
const url = `${apiUrl}/webview/${version}`;
|
|
17
|
+
try {
|
|
18
|
+
const response = yield axios.get(url, {
|
|
19
|
+
params: { org: orgId, bot: botId, webview: webviewId },
|
|
20
|
+
});
|
|
21
|
+
const textResponseContents = response.data.webview_contents.filter(webviewContent => webviewContent.type === WebviewContentType.TEXT);
|
|
22
|
+
setTextContents(textResponseContents);
|
|
23
|
+
const imageResponseContents = response.data.webview_contents.filter(webviewContent => webviewContent.type === WebviewContentType.IMAGE);
|
|
24
|
+
setImageContents(imageResponseContents);
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
console.error('Error fetching webview contents:', error);
|
|
28
|
+
setError(true);
|
|
29
|
+
}
|
|
30
|
+
finally {
|
|
31
|
+
setLoading(false);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
getResponseContents();
|
|
35
|
+
}, []);
|
|
36
|
+
const getTextContent = (contentID) => {
|
|
37
|
+
var _a, _b;
|
|
38
|
+
return (_b = (_a = textContents === null || textContents === void 0 ? void 0 : textContents.find(textContent => textContent.code === contentID)) === null || _a === void 0 ? void 0 : _a.content.text.find(text => text.locale === currentLocale)) === null || _b === void 0 ? void 0 : _b.message;
|
|
39
|
+
};
|
|
40
|
+
const getImageSrc = (contentID) => {
|
|
41
|
+
var _a, _b;
|
|
42
|
+
return (_b = (_a = imageContents === null || imageContents === void 0 ? void 0 : imageContents.find(imageContent => imageContent.code === contentID)) === null || _a === void 0 ? void 0 : _a.content.image.find(image => image.locale === currentLocale)) === null || _b === void 0 ? void 0 : _b.file;
|
|
43
|
+
};
|
|
44
|
+
return {
|
|
45
|
+
isLoading,
|
|
46
|
+
error,
|
|
47
|
+
webviewContentsContext: {
|
|
48
|
+
getTextContent,
|
|
49
|
+
getImageSrc,
|
|
50
|
+
setCurrentLocale,
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=use-webview-contents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-webview-contents.js","sourceRoot":"","sources":["../../../src/webview/use-webview-contents.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAE3C,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botonic/plugin-flow-builder",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.0-alpha.0",
|
|
4
4
|
"main": "./lib/cjs/index.js",
|
|
5
5
|
"module": "./lib/esm/index.js",
|
|
6
6
|
"description": "Use Flow Builder to show your contents",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"lint_core": "../../node_modules/.bin/eslint_d --cache --quiet 'src/**/*.ts*'"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@botonic/react": "^0.
|
|
17
|
+
"@botonic/react": "^0.26.0-alpha.0",
|
|
18
18
|
"axios": "^1.6.8",
|
|
19
19
|
"uuid": "^9.0.1"
|
|
20
20
|
},
|
package/src/constants.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -2,7 +2,11 @@ import { Plugin, PluginPreRequest, Session } from '@botonic/core'
|
|
|
2
2
|
import { ActionRequest } from '@botonic/react'
|
|
3
3
|
|
|
4
4
|
import { FlowBuilderApi } from './api'
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
FLOW_BUILDER_API_URL_PROD,
|
|
7
|
+
SEPARATOR,
|
|
8
|
+
SOURCE_INFO_SEPARATOR,
|
|
9
|
+
} from './constants'
|
|
6
10
|
import {
|
|
7
11
|
FlowCarousel,
|
|
8
12
|
FlowContent,
|
|
@@ -24,6 +28,7 @@ import {
|
|
|
24
28
|
import { DEFAULT_FUNCTIONS } from './functions'
|
|
25
29
|
import {
|
|
26
30
|
BotonicPluginFlowBuilderOptions,
|
|
31
|
+
FlowBuilderJSONVersion,
|
|
27
32
|
KnowledgeBaseResponse,
|
|
28
33
|
PayloadParamsBase,
|
|
29
34
|
} from './types'
|
|
@@ -48,7 +53,9 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
48
53
|
) => Promise<KnowledgeBaseResponse>
|
|
49
54
|
|
|
50
55
|
constructor(readonly options: BotonicPluginFlowBuilderOptions) {
|
|
51
|
-
|
|
56
|
+
const apiUrl = options.apiUrl || FLOW_BUILDER_API_URL_PROD
|
|
57
|
+
const jsonVersion = options.jsonVersion || FlowBuilderJSONVersion.LATEST
|
|
58
|
+
this.flowUrl = `${apiUrl}/flow/${jsonVersion}`
|
|
52
59
|
this.flow = options.flow
|
|
53
60
|
this.getLocale = options.getLocale
|
|
54
61
|
this.getAccessToken = resolveGetAccessToken(options)
|
|
@@ -229,4 +236,9 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
229
236
|
|
|
230
237
|
export * from './action'
|
|
231
238
|
export * from './content-fields'
|
|
232
|
-
export {
|
|
239
|
+
export {
|
|
240
|
+
BotonicPluginFlowBuilderOptions,
|
|
241
|
+
FlowBuilderJSONVersion,
|
|
242
|
+
PayloadParamsBase,
|
|
243
|
+
} from './types'
|
|
244
|
+
export * from './webview'
|
package/src/types.ts
CHANGED
|
@@ -4,7 +4,8 @@ import { ActionRequest } from '@botonic/react'
|
|
|
4
4
|
import { HtFlowBuilderData } from './content-fields/hubtype-fields'
|
|
5
5
|
|
|
6
6
|
export interface BotonicPluginFlowBuilderOptions {
|
|
7
|
-
|
|
7
|
+
apiUrl?: string
|
|
8
|
+
jsonVersion?: FlowBuilderJSONVersion
|
|
8
9
|
flow?: HtFlowBuilderData
|
|
9
10
|
customFunctions?: Record<any, any>
|
|
10
11
|
getLocale: (session: Session) => string
|
|
@@ -31,6 +32,11 @@ export enum ProcessEnvNodeEnvs {
|
|
|
31
32
|
DEVELOPMENT = 'development',
|
|
32
33
|
}
|
|
33
34
|
|
|
35
|
+
export enum FlowBuilderJSONVersion {
|
|
36
|
+
DRAFT = 'draft',
|
|
37
|
+
LATEST = 'latest',
|
|
38
|
+
}
|
|
39
|
+
|
|
34
40
|
export interface KnowledgeBaseResponse {
|
|
35
41
|
answer: string
|
|
36
42
|
hasKnowledge: boolean
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createContext } from 'react'
|
|
2
|
+
|
|
3
|
+
import { WebviewContentsContextType } from './types'
|
|
4
|
+
|
|
5
|
+
export const WebviewContentsContext = createContext<WebviewContentsContextType>(
|
|
6
|
+
{
|
|
7
|
+
getTextContent: () => undefined,
|
|
8
|
+
getImageSrc: () => undefined,
|
|
9
|
+
setCurrentLocale: () => undefined,
|
|
10
|
+
}
|
|
11
|
+
)
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { FlowBuilderJSONVersion } from '../types'
|
|
2
|
+
|
|
3
|
+
export enum WebviewContentType {
|
|
4
|
+
TEXT = 'webview-text',
|
|
5
|
+
IMAGE = 'webview-image',
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface WebviewContentsResponse {
|
|
9
|
+
webview_contents: (WebviewTextContent | WebviewImageContent)[]
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface WebviewTextContent {
|
|
13
|
+
code: string
|
|
14
|
+
type: WebviewContentType.TEXT
|
|
15
|
+
content: {
|
|
16
|
+
text: { message: string; locale: string }[]
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface WebviewImageContent {
|
|
21
|
+
code: string
|
|
22
|
+
type: WebviewContentType.IMAGE
|
|
23
|
+
content: {
|
|
24
|
+
image: { file: string; locale: string }[]
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface UseWebviewContentsProps {
|
|
29
|
+
apiUrl?: string
|
|
30
|
+
version?: FlowBuilderJSONVersion
|
|
31
|
+
orgId: string
|
|
32
|
+
botId: string
|
|
33
|
+
webviewId: string
|
|
34
|
+
locale: string
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface UseWebviewContents {
|
|
38
|
+
isLoading: boolean
|
|
39
|
+
error: boolean
|
|
40
|
+
webviewContentsContext: WebviewContentsContextType
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface WebviewContentsContextType {
|
|
44
|
+
getTextContent: (code: string) => string | undefined
|
|
45
|
+
getImageSrc: (code: string) => string | undefined
|
|
46
|
+
setCurrentLocale: (locale: string) => void
|
|
47
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import axios from 'axios'
|
|
2
|
+
import { useEffect, useState } from 'react'
|
|
3
|
+
|
|
4
|
+
import { FLOW_BUILDER_API_URL_PROD } from '../constants'
|
|
5
|
+
import { FlowBuilderJSONVersion } from '../types'
|
|
6
|
+
import {
|
|
7
|
+
UseWebviewContents,
|
|
8
|
+
UseWebviewContentsProps,
|
|
9
|
+
WebviewContentsResponse,
|
|
10
|
+
WebviewContentType,
|
|
11
|
+
WebviewImageContent,
|
|
12
|
+
WebviewTextContent,
|
|
13
|
+
} from './types'
|
|
14
|
+
|
|
15
|
+
export function useWebviewContents({
|
|
16
|
+
apiUrl = FLOW_BUILDER_API_URL_PROD,
|
|
17
|
+
version = FlowBuilderJSONVersion.LATEST,
|
|
18
|
+
orgId,
|
|
19
|
+
botId,
|
|
20
|
+
webviewId,
|
|
21
|
+
locale,
|
|
22
|
+
}: UseWebviewContentsProps): UseWebviewContents {
|
|
23
|
+
const [textContents, setTextContents] = useState<WebviewTextContent[]>()
|
|
24
|
+
const [imageContents, setImageContents] = useState<WebviewImageContent[]>()
|
|
25
|
+
const [currentLocale, setCurrentLocale] = useState(locale)
|
|
26
|
+
const [isLoading, setLoading] = useState(false)
|
|
27
|
+
const [error, setError] = useState(false)
|
|
28
|
+
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
const getResponseContents = async () => {
|
|
31
|
+
setLoading(true)
|
|
32
|
+
const url = `${apiUrl}/webview/${version}`
|
|
33
|
+
try {
|
|
34
|
+
const response = await axios.get<WebviewContentsResponse>(url, {
|
|
35
|
+
params: { org: orgId, bot: botId, webview: webviewId },
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
const textResponseContents = response.data.webview_contents.filter(
|
|
39
|
+
webviewContent => webviewContent.type === WebviewContentType.TEXT
|
|
40
|
+
) as WebviewTextContent[]
|
|
41
|
+
setTextContents(textResponseContents)
|
|
42
|
+
|
|
43
|
+
const imageResponseContents = response.data.webview_contents.filter(
|
|
44
|
+
webviewContent => webviewContent.type === WebviewContentType.IMAGE
|
|
45
|
+
) as WebviewImageContent[]
|
|
46
|
+
setImageContents(imageResponseContents)
|
|
47
|
+
} catch (error) {
|
|
48
|
+
console.error('Error fetching webview contents:', error)
|
|
49
|
+
setError(true)
|
|
50
|
+
} finally {
|
|
51
|
+
setLoading(false)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
getResponseContents()
|
|
55
|
+
}, [])
|
|
56
|
+
|
|
57
|
+
const getTextContent = (contentID: string): string | undefined => {
|
|
58
|
+
return textContents
|
|
59
|
+
?.find(textContent => textContent.code === contentID)
|
|
60
|
+
?.content.text.find(text => text.locale === currentLocale)?.message
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const getImageSrc = (contentID: string): string | undefined => {
|
|
64
|
+
return imageContents
|
|
65
|
+
?.find(imageContent => imageContent.code === contentID)
|
|
66
|
+
?.content.image.find(image => image.locale === currentLocale)?.file
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
isLoading,
|
|
71
|
+
error,
|
|
72
|
+
webviewContentsContext: {
|
|
73
|
+
getTextContent,
|
|
74
|
+
getImageSrc,
|
|
75
|
+
setCurrentLocale,
|
|
76
|
+
},
|
|
77
|
+
}
|
|
78
|
+
}
|