@botonic/plugin-flow-builder 0.25.0-beta.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/action/index.js +1 -1
- package/lib/cjs/action/index.js.map +1 -1
- package/lib/cjs/action/knowledge-bases.js +2 -1
- package/lib/cjs/action/knowledge-bases.js.map +1 -1
- package/lib/cjs/api.d.ts +4 -1
- package/lib/cjs/api.js +20 -4
- package/lib/cjs/api.js.map +1 -1
- 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/content-fields/flow-handoff.js +1 -1
- package/lib/cjs/content-fields/flow-handoff.js.map +1 -1
- package/lib/cjs/content-fields/hubtype-fields/common.d.ts +1 -0
- package/lib/cjs/content-fields/hubtype-fields/index.d.ts +1 -0
- package/lib/cjs/content-fields/hubtype-fields/index.js +1 -0
- package/lib/cjs/content-fields/hubtype-fields/index.js.map +1 -1
- package/lib/cjs/content-fields/hubtype-fields/node-types.d.ts +1 -0
- package/lib/cjs/content-fields/hubtype-fields/node-types.js +1 -0
- package/lib/cjs/content-fields/hubtype-fields/node-types.js.map +1 -1
- package/lib/cjs/content-fields/hubtype-fields/nodes.d.ts +2 -1
- package/lib/cjs/content-fields/hubtype-fields/smart-intent.d.ts +11 -0
- package/lib/cjs/content-fields/hubtype-fields/smart-intent.js +3 -0
- package/lib/cjs/content-fields/hubtype-fields/smart-intent.js.map +1 -0
- package/lib/cjs/index.d.ts +5 -3
- package/lib/cjs/index.js +15 -4
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/{action/tracking.js → tracking.js} +1 -1
- package/lib/cjs/tracking.js.map +1 -0
- package/lib/cjs/types.d.ts +7 -2
- package/lib/cjs/types.js +6 -1
- package/lib/cjs/types.js.map +1 -1
- package/lib/cjs/user-input/index.d.ts +4 -0
- package/lib/cjs/{action/user-input.js → user-input/index.js} +8 -4
- package/lib/cjs/user-input/index.js.map +1 -0
- package/lib/cjs/{action → user-input}/intent.js +1 -1
- package/lib/cjs/user-input/intent.js.map +1 -0
- package/lib/cjs/{action → user-input}/keyword.js +1 -1
- package/lib/cjs/user-input/keyword.js.map +1 -0
- package/lib/cjs/user-input/smart-intent.d.ts +4 -0
- package/lib/cjs/user-input/smart-intent.js +40 -0
- package/lib/cjs/user-input/smart-intent.js.map +1 -0
- 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/action/index.js +1 -1
- package/lib/esm/action/index.js.map +1 -1
- package/lib/esm/action/knowledge-bases.js +2 -1
- package/lib/esm/action/knowledge-bases.js.map +1 -1
- package/lib/esm/api.d.ts +4 -1
- package/lib/esm/api.js +20 -4
- package/lib/esm/api.js.map +1 -1
- 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/content-fields/flow-handoff.js +1 -1
- package/lib/esm/content-fields/flow-handoff.js.map +1 -1
- package/lib/esm/content-fields/hubtype-fields/common.d.ts +1 -0
- package/lib/esm/content-fields/hubtype-fields/index.d.ts +1 -0
- package/lib/esm/content-fields/hubtype-fields/index.js +1 -0
- package/lib/esm/content-fields/hubtype-fields/index.js.map +1 -1
- package/lib/esm/content-fields/hubtype-fields/node-types.d.ts +1 -0
- package/lib/esm/content-fields/hubtype-fields/node-types.js +1 -0
- package/lib/esm/content-fields/hubtype-fields/node-types.js.map +1 -1
- package/lib/esm/content-fields/hubtype-fields/nodes.d.ts +2 -1
- package/lib/esm/content-fields/hubtype-fields/smart-intent.d.ts +11 -0
- package/lib/esm/content-fields/hubtype-fields/smart-intent.js +2 -0
- package/lib/esm/content-fields/hubtype-fields/smart-intent.js.map +1 -0
- package/lib/esm/index.d.ts +5 -3
- package/lib/esm/index.js +14 -5
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/{action/tracking.js → tracking.js} +1 -1
- package/lib/esm/tracking.js.map +1 -0
- package/lib/esm/types.d.ts +7 -2
- package/lib/esm/types.js +5 -0
- package/lib/esm/types.js.map +1 -1
- package/lib/esm/user-input/index.d.ts +4 -0
- package/lib/esm/{action/user-input.js → user-input/index.js} +8 -4
- package/lib/esm/user-input/index.js.map +1 -0
- package/lib/esm/{action → user-input}/intent.js +1 -1
- package/lib/esm/user-input/intent.js.map +1 -0
- package/lib/esm/{action → user-input}/keyword.js +1 -1
- package/lib/esm/user-input/keyword.js.map +1 -0
- package/lib/esm/user-input/smart-intent.d.ts +4 -0
- package/lib/esm/user-input/smart-intent.js +36 -0
- package/lib/esm/user-input/smart-intent.js.map +1 -0
- 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/action/index.tsx +1 -1
- package/src/action/knowledge-bases.ts +2 -1
- package/src/api.ts +30 -4
- package/src/constants.ts +2 -0
- package/src/content-fields/flow-handoff.tsx +1 -1
- package/src/content-fields/hubtype-fields/common.ts +1 -0
- package/src/content-fields/hubtype-fields/index.ts +1 -0
- package/src/content-fields/hubtype-fields/node-types.ts +1 -0
- package/src/content-fields/hubtype-fields/nodes.ts +2 -0
- package/src/content-fields/hubtype-fields/smart-intent.ts +12 -0
- package/src/index.ts +25 -8
- package/src/{action/tracking.ts → tracking.ts} +1 -1
- package/src/types.ts +8 -2
- package/src/{action/user-input.ts → user-input/index.ts} +13 -5
- package/src/{action → user-input}/intent.ts +1 -1
- package/src/{action → user-input}/keyword.ts +1 -1
- package/src/user-input/smart-intent.ts +42 -0
- 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
- package/lib/cjs/action/intent.js.map +0 -1
- package/lib/cjs/action/keyword.js.map +0 -1
- package/lib/cjs/action/tracking.js.map +0 -1
- package/lib/cjs/action/user-input.d.ts +0 -4
- package/lib/cjs/action/user-input.js.map +0 -1
- package/lib/esm/action/intent.js.map +0 -1
- package/lib/esm/action/keyword.js.map +0 -1
- package/lib/esm/action/tracking.js.map +0 -1
- package/lib/esm/action/user-input.d.ts +0 -4
- package/lib/esm/action/user-input.js.map +0 -1
- /package/lib/cjs/{action/tracking.d.ts → tracking.d.ts} +0 -0
- /package/lib/cjs/{action → user-input}/intent.d.ts +0 -0
- /package/lib/cjs/{action → user-input}/keyword.d.ts +0 -0
- /package/lib/esm/{action/tracking.d.ts → tracking.d.ts} +0 -0
- /package/lib/esm/{action → user-input}/intent.d.ts +0 -0
- /package/lib/esm/{action → user-input}/keyword.d.ts +0 -0
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;
|
|
@@ -29,5 +34,5 @@ export interface KnowledgeBaseResponse {
|
|
|
29
34
|
}[];
|
|
30
35
|
}
|
|
31
36
|
export interface PayloadParamsBase {
|
|
32
|
-
|
|
37
|
+
followUpContentID?: string;
|
|
33
38
|
}
|
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,4 @@
|
|
|
1
|
+
import { ActionRequest } from '@botonic/react';
|
|
2
|
+
import { FlowBuilderApi } from '../api';
|
|
3
|
+
import { HtIntentNode, HtKeywordNode, HtSmartIntentNode } from '../content-fields/hubtype-fields';
|
|
4
|
+
export declare function getNodeByUserInput(cmsApi: FlowBuilderApi, locale: string, request: ActionRequest): Promise<HtSmartIntentNode | HtIntentNode | HtKeywordNode | undefined>;
|
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
2
|
import { getIntentNodeByInput } from './intent';
|
|
3
3
|
import { getKeywordNodeByInput } from './keyword';
|
|
4
|
+
import { getSmartIntentNodeByInput } from './smart-intent';
|
|
4
5
|
export function getNodeByUserInput(cmsApi, locale, request) {
|
|
5
6
|
return __awaiter(this, void 0, void 0, function* () {
|
|
6
7
|
if (request.input.data) {
|
|
7
|
-
const intentNode = yield getIntentNodeByInput(cmsApi, locale, request);
|
|
8
|
-
if (intentNode)
|
|
9
|
-
return intentNode;
|
|
10
8
|
const keywordNode = yield getKeywordNodeByInput(cmsApi, locale, request, request.input.data);
|
|
11
9
|
if (keywordNode)
|
|
12
10
|
return keywordNode;
|
|
11
|
+
const smartIntentNode = yield getSmartIntentNodeByInput(cmsApi, request);
|
|
12
|
+
if (smartIntentNode)
|
|
13
|
+
return smartIntentNode;
|
|
14
|
+
const intentNode = yield getIntentNodeByInput(cmsApi, locale, request);
|
|
15
|
+
if (intentNode)
|
|
16
|
+
return intentNode;
|
|
13
17
|
}
|
|
14
18
|
return undefined;
|
|
15
19
|
});
|
|
16
20
|
}
|
|
17
|
-
//# sourceMappingURL=
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/user-input/index.ts"],"names":[],"mappings":";AAQA,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAC/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAA;AACjD,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAA;AAE1D,MAAM,UAAgB,kBAAkB,CACtC,MAAsB,EACtB,MAAc,EACd,OAAsB;;QAEtB,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE;YACtB,MAAM,WAAW,GAAG,MAAM,qBAAqB,CAC7C,MAAM,EACN,MAAM,EACN,OAAO,EACP,OAAO,CAAC,KAAK,CAAC,IAAI,CACnB,CAAA;YACD,IAAI,WAAW;gBAAE,OAAO,WAAW,CAAA;YAEnC,MAAM,eAAe,GAAG,MAAM,yBAAyB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;YACxE,IAAI,eAAe;gBAAE,OAAO,eAAe,CAAA;YAE3C,MAAM,UAAU,GAAG,MAAM,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAA;YACtE,IAAI,UAAU;gBAAE,OAAO,UAAU,CAAA;SAClC;QACD,OAAO,SAAS,CAAA;IAClB,CAAC;CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
|
-
import { EventName, trackEvent } from '
|
|
2
|
+
import { EventName, trackEvent } from '../tracking';
|
|
3
3
|
export function getIntentNodeByInput(cmsApi, locale, request) {
|
|
4
4
|
return __awaiter(this, void 0, void 0, function* () {
|
|
5
5
|
const intentNode = cmsApi.getIntentNode(request.input, locale);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intent.js","sourceRoot":"","sources":["../../../src/user-input/intent.ts"],"names":[],"mappings":";AAIA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAEnD,MAAM,UAAgB,oBAAoB,CACxC,MAAsB,EACtB,MAAc,EACd,OAAsB;;QAEtB,MAAM,UAAU,GAAG,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;QAC9D,MAAM,SAAS,GAAG;YAChB,MAAM,EAAE,OAAO,CAAC,KAAK,CAAC,MAAgB;YACtC,UAAU,EAAE,OAAO,CAAC,KAAK,CAAC,UAAoB;YAC9C,qBAAqB,EAAE,IAAI;SAC5B,CAAA;QACD,IAAI,OAAO,CAAC,KAAK,CAAC,UAAU,IAAI,OAAO,CAAC,KAAK,CAAC,MAAM,IAAI,UAAU,EAAE;YAClE,IAAI,aAAa,CAAC,UAAU,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE;gBAC9C,MAAM,UAAU,CAAC,OAAO,EAAE,SAAS,CAAC,UAAU,EAAE,SAAS,CAAC,CAAA;gBAC1D,OAAO,UAAU,CAAA;aAClB;YAED,SAAS,CAAC,qBAAqB,GAAG,KAAK,CAAA;YACvC,MAAM,UAAU,CAAC,OAAO,EAAE,SAAS,CAAC,UAAU,EAAE,SAAS,CAAC,CAAA;SAC3D;QAED,OAAO,SAAS,CAAA;IAClB,CAAC;CAAA;AAED,SAAS,aAAa,CACpB,UAAwB,EACxB,OAAsB,EACtB,MAAsB;IAEtB,OAAO,CACL,OAAO,CAAC,KAAK,CAAC,UAAU;QACxB,MAAM,CAAC,yBAAyB,CAAC,UAAU,EAAE,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CACvE,CAAA;AACH,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
|
-
import { EventName, trackEvent } from '
|
|
2
|
+
import { EventName, trackEvent } from '../tracking';
|
|
3
3
|
export function getKeywordNodeByInput(cmsApi, locale, request, userInput) {
|
|
4
4
|
return __awaiter(this, void 0, void 0, function* () {
|
|
5
5
|
const keywordNode = cmsApi.getNodeByKeyword(userInput, locale);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyword.js","sourceRoot":"","sources":["../../../src/user-input/keyword.ts"],"names":[],"mappings":";AAIA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAEnD,MAAM,UAAgB,qBAAqB,CACzC,MAAsB,EACtB,MAAc,EACd,OAAsB,EACtB,SAAiB;;QAEjB,MAAM,WAAW,GAAG,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;QAC9D,IAAI,CAAC,WAAW,EAAE;YAChB,OAAO,SAAS,CAAA;SACjB;QACD,MAAM,SAAS,GAAG;YAChB,qBAAqB,EAAE,IAAI;SAC5B,CAAA;QACD,MAAM,UAAU,CAAC,OAAO,EAAE,SAAS,CAAC,gBAAgB,EAAE,SAAS,CAAC,CAAA;QAChE,OAAO,WAAW,CAAA;IACpB,CAAC;CAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ActionRequest } from '@botonic/react';
|
|
2
|
+
import { FlowBuilderApi } from '../api';
|
|
3
|
+
import { HtSmartIntentNode } from '../content-fields/hubtype-fields/smart-intent';
|
|
4
|
+
export declare function getSmartIntentNodeByInput(cmsApi: FlowBuilderApi, request: ActionRequest): Promise<HtSmartIntentNode | undefined>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
export function getSmartIntentNodeByInput(cmsApi, request) {
|
|
4
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
5
|
+
const smartIntentNodes = cmsApi.getSmartIntentNodes();
|
|
6
|
+
const intentsInferenceParams = smartIntentNodes.map(smartIntentNode => {
|
|
7
|
+
return {
|
|
8
|
+
name: smartIntentNode.content.title,
|
|
9
|
+
definition: smartIntentNode.content.description,
|
|
10
|
+
};
|
|
11
|
+
});
|
|
12
|
+
intentsInferenceParams.push({
|
|
13
|
+
name: 'Other',
|
|
14
|
+
definition: 'The text does not belong to any other intent.',
|
|
15
|
+
});
|
|
16
|
+
try {
|
|
17
|
+
const response = yield axios({
|
|
18
|
+
method: 'POST',
|
|
19
|
+
url: `${process.env.HUBTYPE_API_URL}/external/v1/ai/smart_intents/inference/`,
|
|
20
|
+
headers: {
|
|
21
|
+
Authorization: `Bearer ${request.session._access_token}`,
|
|
22
|
+
'Content-Type': 'application/json',
|
|
23
|
+
},
|
|
24
|
+
data: { text: request.input.data, intents: intentsInferenceParams },
|
|
25
|
+
timeout: 10000,
|
|
26
|
+
});
|
|
27
|
+
console.log({ response });
|
|
28
|
+
return smartIntentNodes.find(smartIntentNode => smartIntentNode.content.title === response.data.intent_name);
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
console.error(e);
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=smart-intent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"smart-intent.js","sourceRoot":"","sources":["../../../src/user-input/smart-intent.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,MAAM,OAAO,CAAA;AAKzB,MAAM,UAAgB,yBAAyB,CAC7C,MAAsB,EACtB,OAAsB;;QAEtB,MAAM,gBAAgB,GAAG,MAAM,CAAC,mBAAmB,EAAE,CAAA;QACrD,MAAM,sBAAsB,GAAG,gBAAgB,CAAC,GAAG,CAAC,eAAe,CAAC,EAAE;YACpE,OAAO;gBACL,IAAI,EAAE,eAAe,CAAC,OAAO,CAAC,KAAK;gBACnC,UAAU,EAAE,eAAe,CAAC,OAAO,CAAC,WAAW;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 +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,CAAA;AACxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAA;AACjD,OA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onic/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/action/index.tsx
CHANGED
|
@@ -6,7 +6,7 @@ import { FlowContent, FlowHandoff } from '../content-fields'
|
|
|
6
6
|
import { HtNodeWithContent } from '../content-fields/hubtype-fields'
|
|
7
7
|
import { getFlowBuilderPlugin } from '../helpers'
|
|
8
8
|
import { createNodeFromKnowledgeBase } from './knowledge-bases'
|
|
9
|
-
import { EventName, trackEvent } from '
|
|
9
|
+
import { EventName, trackEvent } from '../tracking'
|
|
10
10
|
|
|
11
11
|
export type FlowBuilderActionProps = {
|
|
12
12
|
contents: FlowContent[]
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
HtTextNode,
|
|
10
10
|
} from '../content-fields/hubtype-fields'
|
|
11
11
|
import { getFlowBuilderPlugin } from '../helpers'
|
|
12
|
-
import { EventName, trackEvent } from '
|
|
12
|
+
import { EventName, trackEvent } from '../tracking'
|
|
13
13
|
|
|
14
14
|
export async function createNodeFromKnowledgeBase(
|
|
15
15
|
cmsApi: FlowBuilderApi,
|
|
@@ -47,6 +47,7 @@ export async function createNodeFromKnowledgeBase(
|
|
|
47
47
|
buttons_style: undefined,
|
|
48
48
|
buttons: [],
|
|
49
49
|
},
|
|
50
|
+
flow_id: 'randomUUID', // TODO: Add flow_id consequentially with HtBaseNode changes
|
|
50
51
|
id: uuid(),
|
|
51
52
|
code: 'knowledge-response',
|
|
52
53
|
meta: {
|
package/src/api.ts
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
HtBotActionNode,
|
|
7
7
|
HtFallbackNode,
|
|
8
8
|
HtFlowBuilderData,
|
|
9
|
+
HtGoToFlow,
|
|
9
10
|
HtIntentNode,
|
|
10
11
|
HtKeywordNode,
|
|
11
12
|
HtNodeComponent,
|
|
@@ -15,6 +16,7 @@ import {
|
|
|
15
16
|
HtNodeWithoutContentType,
|
|
16
17
|
HtPayloadNode,
|
|
17
18
|
} from './content-fields/hubtype-fields'
|
|
19
|
+
import { HtSmartIntentNode } from './content-fields/hubtype-fields/smart-intent'
|
|
18
20
|
import { FlowBuilderApiOptions } from './types'
|
|
19
21
|
|
|
20
22
|
export class FlowBuilderApi {
|
|
@@ -56,11 +58,11 @@ export class FlowBuilderApi {
|
|
|
56
58
|
return node as T
|
|
57
59
|
}
|
|
58
60
|
|
|
59
|
-
|
|
61
|
+
getNodeByContentID(contentID: string): HtNodeComponent {
|
|
60
62
|
const content = this.flow.nodes.find(node =>
|
|
61
|
-
'code' in node ? node.code ===
|
|
63
|
+
'code' in node ? node.code === contentID : false
|
|
62
64
|
)
|
|
63
|
-
if (!content) throw Error(`Node with
|
|
65
|
+
if (!content) throw Error(`Node with contentID: '${contentID}' not found`)
|
|
64
66
|
return content
|
|
65
67
|
}
|
|
66
68
|
|
|
@@ -124,6 +126,12 @@ export class FlowBuilderApi {
|
|
|
124
126
|
return undefined
|
|
125
127
|
}
|
|
126
128
|
|
|
129
|
+
getSmartIntentNodes(): HtSmartIntentNode[] {
|
|
130
|
+
return this.flow.nodes.filter(
|
|
131
|
+
node => node.type === HtNodeWithContentType.SMART_INTENT
|
|
132
|
+
) as HtSmartIntentNode[]
|
|
133
|
+
}
|
|
134
|
+
|
|
127
135
|
private nodeContainsIntent(
|
|
128
136
|
node: HtIntentNode,
|
|
129
137
|
intent: string,
|
|
@@ -214,13 +222,31 @@ export class FlowBuilderApi {
|
|
|
214
222
|
const customParams = JSON.parse(
|
|
215
223
|
botActionNode.content.payload_params || '{}'
|
|
216
224
|
)
|
|
225
|
+
|
|
226
|
+
const followUpContentID = this.getFollowUpContentID(
|
|
227
|
+
botActionNode.follow_up?.id
|
|
228
|
+
)
|
|
229
|
+
|
|
217
230
|
const payloadJson = JSON.stringify({
|
|
218
231
|
...customParams,
|
|
219
|
-
|
|
232
|
+
followUpContentID,
|
|
220
233
|
})
|
|
221
234
|
return `${payloadNode.content.payload}${SEPARATOR}${payloadJson}`
|
|
222
235
|
}
|
|
223
236
|
|
|
237
|
+
private getFollowUpContentID(id?: string): string | undefined {
|
|
238
|
+
const followUpNode = id
|
|
239
|
+
? this.getNodeById<HtNodeWithContent | HtGoToFlow>(id)
|
|
240
|
+
: undefined
|
|
241
|
+
|
|
242
|
+
if (followUpNode?.type === HtNodeWithoutContentType.GO_TO_FLOW) {
|
|
243
|
+
return this.getNodeById<HtNodeWithContent>(followUpNode?.content.flow_id)
|
|
244
|
+
.code
|
|
245
|
+
} else {
|
|
246
|
+
return followUpNode?.code
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
224
250
|
getResolvedLocale(locale: string): string {
|
|
225
251
|
if (this.flow.locales.find(flowLocale => flowLocale === locale)) {
|
|
226
252
|
return locale
|
package/src/constants.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { HandOffBuilder } from '@botonic/core'
|
|
|
2
2
|
import { ActionRequest, WebchatSettings } from '@botonic/react'
|
|
3
3
|
import React from 'react'
|
|
4
4
|
|
|
5
|
-
import { EventName, trackEvent } from '../
|
|
5
|
+
import { EventName, trackEvent } from '../tracking'
|
|
6
6
|
import { FlowBuilderApi } from '../api'
|
|
7
7
|
import { getQueueAvailability } from '../functions/conditional-queue-status'
|
|
8
8
|
import { ContentFieldsBase } from './content-fields-base'
|
|
@@ -8,6 +8,7 @@ import { HtImageNode } from './image'
|
|
|
8
8
|
import { HtIntentNode } from './intent'
|
|
9
9
|
import { HtKeywordNode } from './keyword'
|
|
10
10
|
import { HtPayloadNode } from './payload'
|
|
11
|
+
import { HtSmartIntentNode } from './smart-intent'
|
|
11
12
|
import { HtTextNode } from './text'
|
|
12
13
|
import { HtUrlNode } from './url'
|
|
13
14
|
import { HtVideoNode } from './video'
|
|
@@ -24,6 +25,7 @@ export type HtNodeWithContent =
|
|
|
24
25
|
| HtFunctionNode
|
|
25
26
|
| HtFallbackNode
|
|
26
27
|
| HtWhatsappButtonListNode
|
|
28
|
+
| HtSmartIntentNode
|
|
27
29
|
|
|
28
30
|
export type HtNodeWithoutContent =
|
|
29
31
|
| HtUrlNode
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { HtBaseNode } from './common'
|
|
2
|
+
import { HtNodeWithContentType } from './node-types'
|
|
3
|
+
|
|
4
|
+
interface SmartIntent {
|
|
5
|
+
title: string
|
|
6
|
+
description: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface HtSmartIntentNode extends HtBaseNode {
|
|
10
|
+
type: HtNodeWithContentType.SMART_INTENT
|
|
11
|
+
content: SmartIntent
|
|
12
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { Plugin, PluginPreRequest, Session } from '@botonic/core'
|
|
2
2
|
import { ActionRequest } from '@botonic/react'
|
|
3
3
|
|
|
4
|
-
import { getNodeByUserInput } from './action/user-input'
|
|
5
4
|
import { FlowBuilderApi } from './api'
|
|
6
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
FLOW_BUILDER_API_URL_PROD,
|
|
7
|
+
SEPARATOR,
|
|
8
|
+
SOURCE_INFO_SEPARATOR,
|
|
9
|
+
} from './constants'
|
|
7
10
|
import {
|
|
8
11
|
FlowCarousel,
|
|
9
12
|
FlowContent,
|
|
@@ -25,9 +28,11 @@ import {
|
|
|
25
28
|
import { DEFAULT_FUNCTIONS } from './functions'
|
|
26
29
|
import {
|
|
27
30
|
BotonicPluginFlowBuilderOptions,
|
|
31
|
+
FlowBuilderJSONVersion,
|
|
28
32
|
KnowledgeBaseResponse,
|
|
29
33
|
PayloadParamsBase,
|
|
30
34
|
} from './types'
|
|
35
|
+
import { getNodeByUserInput } from './user-input'
|
|
31
36
|
import { resolveGetAccessToken } from './utils'
|
|
32
37
|
|
|
33
38
|
export default class BotonicPluginFlowBuilder implements Plugin {
|
|
@@ -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)
|
|
@@ -90,16 +97,21 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
90
97
|
}
|
|
91
98
|
}
|
|
92
99
|
|
|
93
|
-
async
|
|
94
|
-
|
|
100
|
+
async getContentsByContentID(
|
|
101
|
+
contentID: string,
|
|
95
102
|
locale: string,
|
|
96
103
|
prevContents?: FlowContent[]
|
|
97
104
|
): Promise<FlowContent[]> {
|
|
98
|
-
const node = this.cmsApi.
|
|
105
|
+
const node = this.cmsApi.getNodeByContentID(contentID) as HtNodeWithContent
|
|
99
106
|
return await this.getContentsByNode(node, locale, prevContents)
|
|
100
107
|
}
|
|
101
108
|
|
|
102
|
-
|
|
109
|
+
getUUIDByContentID(contentID: string): string {
|
|
110
|
+
const node = this.cmsApi.getNodeByContentID(contentID)
|
|
111
|
+
return node.id
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
private async getContentsById(
|
|
103
115
|
id: string,
|
|
104
116
|
locale: string,
|
|
105
117
|
prevContents?: FlowContent[]
|
|
@@ -224,4 +236,9 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
224
236
|
|
|
225
237
|
export * from './action'
|
|
226
238
|
export * from './content-fields'
|
|
227
|
-
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
|
|
@@ -41,5 +47,5 @@ export interface KnowledgeBaseResponse {
|
|
|
41
47
|
}
|
|
42
48
|
|
|
43
49
|
export interface PayloadParamsBase {
|
|
44
|
-
|
|
50
|
+
followUpContentID?: string
|
|
45
51
|
}
|