@botonic/plugin-flow-builder 0.26.2-alpha.0 → 0.27.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.js +38 -18
- package/lib/cjs/action/index.js.map +1 -1
- package/lib/cjs/action/knowledge-bases.js +14 -4
- package/lib/cjs/action/knowledge-bases.js.map +1 -1
- package/lib/cjs/api.d.ts +2 -4
- package/lib/cjs/api.js +7 -32
- package/lib/cjs/api.js.map +1 -1
- package/lib/cjs/constants.d.ts +1 -1
- package/lib/cjs/constants.js +2 -2
- package/lib/cjs/constants.js.map +1 -1
- package/lib/cjs/content-fields/flow-handoff.js +7 -19
- package/lib/cjs/content-fields/flow-handoff.js.map +1 -1
- package/lib/cjs/content-fields/index.d.ts +1 -0
- package/lib/cjs/content-fields/index.js +3 -1
- package/lib/cjs/content-fields/index.js.map +1 -1
- package/lib/cjs/functions/conditional-queue-status.d.ts +7 -1
- package/lib/cjs/functions/conditional-queue-status.js +34 -12
- package/lib/cjs/functions/conditional-queue-status.js.map +1 -1
- package/lib/cjs/index.d.ts +6 -3
- package/lib/cjs/index.js +22 -13
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/tracking.d.ts +18 -14
- package/lib/cjs/tracking.js +27 -20
- package/lib/cjs/tracking.js.map +1 -1
- package/lib/cjs/types.d.ts +14 -1
- package/lib/cjs/types.js.map +1 -1
- package/lib/cjs/user-input/index.d.ts +2 -1
- package/lib/cjs/user-input/index.js +9 -3
- package/lib/cjs/user-input/index.js.map +1 -1
- package/lib/cjs/user-input/intent.js +12 -8
- package/lib/cjs/user-input/intent.js.map +1 -1
- package/lib/cjs/user-input/keyword.d.ts +21 -1
- package/lib/cjs/user-input/keyword.js +68 -13
- package/lib/cjs/user-input/keyword.js.map +1 -1
- package/lib/cjs/user-input/smart-intent.d.ts +18 -1
- package/lib/cjs/user-input/smart-intent.js +46 -28
- package/lib/cjs/user-input/smart-intent.js.map +1 -1
- package/lib/esm/action/index.js +39 -19
- package/lib/esm/action/index.js.map +1 -1
- package/lib/esm/action/knowledge-bases.js +15 -5
- package/lib/esm/action/knowledge-bases.js.map +1 -1
- package/lib/esm/api.d.ts +2 -4
- package/lib/esm/api.js +8 -33
- package/lib/esm/api.js.map +1 -1
- package/lib/esm/constants.d.ts +1 -1
- package/lib/esm/constants.js +1 -1
- package/lib/esm/constants.js.map +1 -1
- package/lib/esm/content-fields/flow-handoff.js +7 -19
- package/lib/esm/content-fields/flow-handoff.js.map +1 -1
- package/lib/esm/content-fields/index.d.ts +1 -0
- package/lib/esm/content-fields/index.js +1 -0
- package/lib/esm/content-fields/index.js.map +1 -1
- package/lib/esm/functions/conditional-queue-status.d.ts +7 -1
- package/lib/esm/functions/conditional-queue-status.js +32 -11
- package/lib/esm/functions/conditional-queue-status.js.map +1 -1
- package/lib/esm/index.d.ts +6 -3
- package/lib/esm/index.js +23 -14
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/tracking.d.ts +18 -14
- package/lib/esm/tracking.js +25 -19
- package/lib/esm/tracking.js.map +1 -1
- package/lib/esm/types.d.ts +14 -1
- package/lib/esm/types.js.map +1 -1
- package/lib/esm/user-input/index.d.ts +2 -1
- package/lib/esm/user-input/index.js +11 -5
- package/lib/esm/user-input/index.js.map +1 -1
- package/lib/esm/user-input/intent.js +13 -9
- package/lib/esm/user-input/intent.js.map +1 -1
- package/lib/esm/user-input/keyword.d.ts +21 -1
- package/lib/esm/user-input/keyword.js +67 -12
- package/lib/esm/user-input/keyword.js.map +1 -1
- package/lib/esm/user-input/smart-intent.d.ts +18 -1
- package/lib/esm/user-input/smart-intent.js +44 -26
- package/lib/esm/user-input/smart-intent.js.map +1 -1
- package/package.json +2 -2
- package/src/action/index.tsx +58 -24
- package/src/action/knowledge-bases.ts +16 -5
- package/src/api.ts +11 -57
- package/src/constants.ts +1 -1
- package/src/content-fields/flow-handoff.tsx +8 -28
- package/src/content-fields/index.ts +1 -0
- package/src/functions/conditional-queue-status.ts +36 -13
- package/src/index.ts +39 -19
- package/src/tracking.ts +25 -14
- package/src/types.ts +13 -1
- package/src/user-input/index.ts +13 -7
- package/src/user-input/intent.ts +17 -10
- package/src/user-input/keyword.ts +93 -14
- package/src/user-input/smart-intent.ts +57 -29
package/lib/esm/tracking.js
CHANGED
|
@@ -1,29 +1,35 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
2
|
import { getFlowBuilderPlugin } from './helpers';
|
|
3
|
-
export function trackEvent(request,
|
|
3
|
+
export function trackEvent(request, eventAction, args) {
|
|
4
4
|
return __awaiter(this, void 0, void 0, function* () {
|
|
5
5
|
const flowBuilderPlugin = getFlowBuilderPlugin(request.plugins);
|
|
6
6
|
if (flowBuilderPlugin.trackEvent) {
|
|
7
|
-
yield flowBuilderPlugin.trackEvent(request,
|
|
7
|
+
yield flowBuilderPlugin.trackEvent(request, eventAction, args);
|
|
8
8
|
}
|
|
9
9
|
return;
|
|
10
10
|
});
|
|
11
11
|
}
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
12
|
+
export function getNodeEventArgs(request, node) {
|
|
13
|
+
const flowBuilderPlugin = getFlowBuilderPlugin(request.plugins);
|
|
14
|
+
return {
|
|
15
|
+
flowThreadId: request.session.flow_thread_id,
|
|
16
|
+
flowId: node.flow_id,
|
|
17
|
+
flowName: flowBuilderPlugin.getFlowName(node.flow_id),
|
|
18
|
+
flowNodeId: node.id,
|
|
19
|
+
flowNodeContentId: node.code,
|
|
20
|
+
flowNodeIsMeaningful: undefined, //node?.isMeaningful,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export var EventAction;
|
|
24
|
+
(function (EventAction) {
|
|
25
|
+
EventAction["flowNode"] = "flow_node";
|
|
26
|
+
EventAction["handoffOption"] = "handoff_option";
|
|
27
|
+
EventAction["handoffSuccess"] = "handoff_success";
|
|
28
|
+
EventAction["handoffFail"] = "handoff_fail";
|
|
29
|
+
EventAction["keyword"] = "nlu_keyword";
|
|
30
|
+
EventAction["intent"] = "nlu_intent";
|
|
31
|
+
EventAction["intentSmart"] = "nlu_intent_smart";
|
|
32
|
+
EventAction["knowledgebase"] = "knowledgebase";
|
|
33
|
+
EventAction["fallback"] = "fallback";
|
|
34
|
+
})(EventAction || (EventAction = {}));
|
|
29
35
|
//# sourceMappingURL=tracking.js.map
|
package/lib/esm/tracking.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tracking.js","sourceRoot":"","sources":["../../src/tracking.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"tracking.js","sourceRoot":"","sources":["../../src/tracking.ts"],"names":[],"mappings":";AAGA,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAEhD,MAAM,UAAgB,UAAU,CAC9B,OAAsB,EACtB,WAAwB,EACxB,IAA0B;;QAE1B,MAAM,iBAAiB,GAAG,oBAAoB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QAC/D,IAAI,iBAAiB,CAAC,UAAU,EAAE;YAChC,MAAM,iBAAiB,CAAC,UAAU,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,CAAC,CAAA;SAC/D;QACD,OAAM;IACR,CAAC;CAAA;AAED,MAAM,UAAU,gBAAgB,CAC9B,OAAsB,EACtB,IAAuB;IAEvB,MAAM,iBAAiB,GAAG,oBAAoB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IAC/D,OAAO;QACL,YAAY,EAAE,OAAO,CAAC,OAAO,CAAC,cAAc;QAC5C,MAAM,EAAE,IAAI,CAAC,OAAO;QACpB,QAAQ,EAAE,iBAAiB,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC;QACrD,UAAU,EAAE,IAAI,CAAC,EAAE;QACnB,iBAAiB,EAAE,IAAI,CAAC,IAAI;QAC5B,oBAAoB,EAAE,SAAS,EAAE,qBAAqB;KACvD,CAAA;AACH,CAAC;AAED,MAAM,CAAN,IAAY,WAUX;AAVD,WAAY,WAAW;IACrB,qCAAsB,CAAA;IACtB,+CAAgC,CAAA;IAChC,iDAAkC,CAAA;IAClC,2CAA4B,CAAA;IAC5B,sCAAuB,CAAA;IACvB,oCAAqB,CAAA;IACrB,+CAAgC,CAAA;IAChC,8CAA+B,CAAA;IAC/B,oCAAqB,CAAA;AACvB,CAAC,EAVW,WAAW,KAAX,WAAW,QAUtB"}
|
package/lib/esm/types.d.ts
CHANGED
|
@@ -8,8 +8,11 @@ export interface BotonicPluginFlowBuilderOptions {
|
|
|
8
8
|
customFunctions?: Record<any, any>;
|
|
9
9
|
getLocale: (session: Session) => string;
|
|
10
10
|
getAccessToken: () => string;
|
|
11
|
-
trackEvent?: (request: ActionRequest,
|
|
11
|
+
trackEvent?: (request: ActionRequest, eventAction: string, args?: Record<string, any>) => Promise<void>;
|
|
12
12
|
getKnowledgeBaseResponse?: (request: ActionRequest) => Promise<KnowledgeBaseResponse>;
|
|
13
|
+
smartIntentsConfig?: {
|
|
14
|
+
numSmartIntentsToUse: number;
|
|
15
|
+
};
|
|
13
16
|
}
|
|
14
17
|
export interface FlowBuilderApiOptions {
|
|
15
18
|
url: string;
|
|
@@ -33,6 +36,16 @@ export interface KnowledgeBaseResponse {
|
|
|
33
36
|
page?: number;
|
|
34
37
|
}[];
|
|
35
38
|
}
|
|
39
|
+
export interface SmartIntentResponse {
|
|
40
|
+
data: {
|
|
41
|
+
smart_intent_title: string;
|
|
42
|
+
text: string;
|
|
43
|
+
smart_intents_used: {
|
|
44
|
+
title: string;
|
|
45
|
+
description: string;
|
|
46
|
+
}[];
|
|
47
|
+
};
|
|
48
|
+
}
|
|
36
49
|
export interface PayloadParamsBase {
|
|
37
50
|
followUpContentID?: string;
|
|
38
51
|
}
|
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":"AA8BA,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"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ActionRequest } from '@botonic/react';
|
|
2
2
|
import { FlowBuilderApi } from '../api';
|
|
3
3
|
import { HtIntentNode, HtKeywordNode, HtSmartIntentNode } from '../content-fields/hubtype-fields';
|
|
4
|
-
|
|
4
|
+
import { SmartIntentsInferenceConfig } from './smart-intent';
|
|
5
|
+
export declare function getNodeByUserInput(cmsApi: FlowBuilderApi, locale: string, request: ActionRequest, smartIntentsConfig: SmartIntentsInferenceConfig): Promise<HtSmartIntentNode | HtIntentNode | HtKeywordNode | undefined>;
|
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
2
|
import { getIntentNodeByInput } from './intent';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
export function getNodeByUserInput(cmsApi, locale, request) {
|
|
3
|
+
import { KeywordMatcher } from './keyword';
|
|
4
|
+
import { SmartIntentsApi } from './smart-intent';
|
|
5
|
+
export function getNodeByUserInput(cmsApi, locale, request, smartIntentsConfig) {
|
|
6
6
|
return __awaiter(this, void 0, void 0, function* () {
|
|
7
7
|
if (request.input.data) {
|
|
8
|
-
const
|
|
8
|
+
const keywordMatcher = new KeywordMatcher({
|
|
9
|
+
cmsApi,
|
|
10
|
+
locale,
|
|
11
|
+
request,
|
|
12
|
+
});
|
|
13
|
+
const keywordNode = yield keywordMatcher.getNodeByInput(request.input.data);
|
|
9
14
|
if (keywordNode)
|
|
10
15
|
return keywordNode;
|
|
11
|
-
const
|
|
16
|
+
const smartIntentsApi = new SmartIntentsApi(cmsApi, request, smartIntentsConfig);
|
|
17
|
+
const smartIntentNode = smartIntentsApi.getNodeByInput();
|
|
12
18
|
if (smartIntentNode)
|
|
13
19
|
return smartIntentNode;
|
|
14
20
|
const intentNode = yield getIntentNodeByInput(cmsApi, locale, request);
|
|
@@ -1 +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,
|
|
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,cAAc,EAAE,MAAM,WAAW,CAAA;AAC1C,OAAO,EAAE,eAAe,EAA+B,MAAM,gBAAgB,CAAA;AAE7E,MAAM,UAAgB,kBAAkB,CACtC,MAAsB,EACtB,MAAc,EACd,OAAsB,EACtB,kBAA+C;;QAE/C,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE;YACtB,MAAM,cAAc,GAAG,IAAI,cAAc,CAAC;gBACxC,MAAM;gBACN,MAAM;gBACN,OAAO;aACR,CAAC,CAAA;YACF,MAAM,WAAW,GAAG,MAAM,cAAc,CAAC,cAAc,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;YAC3E,IAAI,WAAW;gBAAE,OAAO,WAAW,CAAA;YAEnC,MAAM,eAAe,GAAG,IAAI,eAAe,CACzC,MAAM,EACN,OAAO,EACP,kBAAkB,CACnB,CAAA;YACD,MAAM,eAAe,GAAG,eAAe,CAAC,cAAc,EAAE,CAAA;YACxD,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,24 +1,28 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
|
-
import {
|
|
2
|
+
import { EventAction, 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);
|
|
6
|
-
const eventArgs = {
|
|
7
|
-
intent: request.input.intent,
|
|
8
|
-
confidence: request.input.confidence,
|
|
9
|
-
confidence_successful: true,
|
|
10
|
-
};
|
|
11
6
|
if (request.input.confidence && request.input.intent && intentNode) {
|
|
7
|
+
yield trackIntentEvent(request, intentNode);
|
|
12
8
|
if (isIntentValid(intentNode, request, cmsApi)) {
|
|
13
|
-
yield trackEvent(request, EventName.botAiModel, eventArgs);
|
|
14
9
|
return intentNode;
|
|
15
10
|
}
|
|
16
|
-
eventArgs.confidence_successful = false;
|
|
17
|
-
yield trackEvent(request, EventName.botAiModel, eventArgs);
|
|
18
11
|
}
|
|
19
12
|
return undefined;
|
|
20
13
|
});
|
|
21
14
|
}
|
|
15
|
+
function trackIntentEvent(request, intentNode) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
const eventArgs = {
|
|
18
|
+
nluIntentLabel: request.input.intent,
|
|
19
|
+
nluIntentConfidence: request.input.confidence,
|
|
20
|
+
nluIntentThreshold: intentNode === null || intentNode === void 0 ? void 0 : intentNode.content.confidence,
|
|
21
|
+
nluIntentMessageId: request.input.message_id,
|
|
22
|
+
};
|
|
23
|
+
yield trackEvent(request, EventAction.intent, eventArgs);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
22
26
|
function isIntentValid(intentNode, request, cmsApi) {
|
|
23
27
|
return (request.input.confidence &&
|
|
24
28
|
cmsApi.hasMetConfidenceThreshold(intentNode, request.input.confidence));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intent.js","sourceRoot":"","sources":["../../../src/user-input/intent.ts"],"names":[],"mappings":";AAIA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"intent.js","sourceRoot":"","sources":["../../../src/user-input/intent.ts"],"names":[],"mappings":";AAIA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAErD,MAAM,UAAgB,oBAAoB,CACxC,MAAsB,EACtB,MAAc,EACd,OAAsB;;QAEtB,MAAM,UAAU,GAAG,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;QAE9D,IAAI,OAAO,CAAC,KAAK,CAAC,UAAU,IAAI,OAAO,CAAC,KAAK,CAAC,MAAM,IAAI,UAAU,EAAE;YAClE,MAAM,gBAAgB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAA;YAE3C,IAAI,aAAa,CAAC,UAAU,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE;gBAC9C,OAAO,UAAU,CAAA;aAClB;SACF;QAED,OAAO,SAAS,CAAA;IAClB,CAAC;CAAA;AAED,SAAe,gBAAgB,CAC7B,OAAsB,EACtB,UAAwB;;QAExB,MAAM,SAAS,GAAG;YAChB,cAAc,EAAE,OAAO,CAAC,KAAK,CAAC,MAAM;YACpC,mBAAmB,EAAE,OAAO,CAAC,KAAK,CAAC,UAAU;YAC7C,kBAAkB,EAAE,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,OAAO,CAAC,UAAU;YAClD,kBAAkB,EAAE,OAAO,CAAC,KAAK,CAAC,UAAU;SAC7C,CAAA;QACD,MAAM,UAAU,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;IAC1D,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,4 +1,24 @@
|
|
|
1
1
|
import { ActionRequest } from '@botonic/react';
|
|
2
2
|
import { FlowBuilderApi } from '../api';
|
|
3
3
|
import { HtKeywordNode } from '../content-fields/hubtype-fields';
|
|
4
|
-
|
|
4
|
+
interface KeywordProps {
|
|
5
|
+
cmsApi: FlowBuilderApi;
|
|
6
|
+
locale: string;
|
|
7
|
+
request: ActionRequest;
|
|
8
|
+
}
|
|
9
|
+
export declare class KeywordMatcher {
|
|
10
|
+
cmsApi: FlowBuilderApi;
|
|
11
|
+
locale: string;
|
|
12
|
+
request: ActionRequest;
|
|
13
|
+
isRegExp: boolean;
|
|
14
|
+
matchedKeyword?: string;
|
|
15
|
+
keywordNodeId?: string;
|
|
16
|
+
constructor({ cmsApi, locale, request }: KeywordProps);
|
|
17
|
+
getNodeByInput(userInput: string): Promise<HtKeywordNode | undefined>;
|
|
18
|
+
private getNodeByKeyword;
|
|
19
|
+
private matchKeywords;
|
|
20
|
+
private inputMatchesAnyKeyword;
|
|
21
|
+
private resolveKeywordAsRegExp;
|
|
22
|
+
private trackKeywordEvent;
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
@@ -1,16 +1,71 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
import { REG_EXP_PATTERN } from '../constants';
|
|
3
|
+
import { EventAction, trackEvent } from '../tracking';
|
|
4
|
+
export class KeywordMatcher {
|
|
5
|
+
constructor({ cmsApi, locale, request }) {
|
|
6
|
+
this.cmsApi = cmsApi;
|
|
7
|
+
this.locale = locale;
|
|
8
|
+
this.request = request;
|
|
9
|
+
this.isRegExp = false;
|
|
10
|
+
}
|
|
11
|
+
getNodeByInput(userInput) {
|
|
12
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
13
|
+
const keywordNodes = this.cmsApi.getKeywordNodes();
|
|
14
|
+
const keywordNode = this.getNodeByKeyword(userInput, keywordNodes);
|
|
15
|
+
if (!keywordNode) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
this.trackKeywordEvent();
|
|
19
|
+
return keywordNode;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
getNodeByKeyword(userInput, keywordNodes) {
|
|
23
|
+
const matchedKeywordNodes = keywordNodes.filter(node => this.matchKeywords(userInput, node));
|
|
24
|
+
if (matchedKeywordNodes.length > 0 && matchedKeywordNodes[0].target) {
|
|
25
|
+
return matchedKeywordNodes[0];
|
|
8
26
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
matchKeywords(userInput, node) {
|
|
30
|
+
const result = node.content.keywords.find(keywords => {
|
|
31
|
+
if (keywords.locale === this.locale) {
|
|
32
|
+
this.keywordNodeId = node.id;
|
|
33
|
+
return this.inputMatchesAnyKeyword(userInput, keywords.values);
|
|
34
|
+
}
|
|
35
|
+
return false;
|
|
36
|
+
});
|
|
37
|
+
return Boolean(result);
|
|
38
|
+
}
|
|
39
|
+
inputMatchesAnyKeyword(userInput, keywords) {
|
|
40
|
+
return keywords.some(keyword => {
|
|
41
|
+
const regExpMatchArray = keyword.match(REG_EXP_PATTERN);
|
|
42
|
+
if (regExpMatchArray) {
|
|
43
|
+
const keywordAsRegExp = this.resolveKeywordAsRegExp(regExpMatchArray);
|
|
44
|
+
const match = userInput.match(keywordAsRegExp);
|
|
45
|
+
this.isRegExp = true;
|
|
46
|
+
this.matchedKeyword = match ? match[0] : undefined;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
this.isRegExp = false;
|
|
50
|
+
this.matchedKeyword = userInput.includes(keyword) ? keyword : undefined;
|
|
51
|
+
}
|
|
52
|
+
return this.matchedKeyword !== undefined;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
resolveKeywordAsRegExp(regExpMatchArray) {
|
|
56
|
+
const [, pattern, flags] = regExpMatchArray;
|
|
57
|
+
return new RegExp(pattern, flags);
|
|
58
|
+
}
|
|
59
|
+
trackKeywordEvent() {
|
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
const eventArgs = {
|
|
62
|
+
nluKeywordId: this.keywordNodeId,
|
|
63
|
+
nluKeywordName: this.matchedKeyword,
|
|
64
|
+
nluKeywordIsRegex: this.isRegExp,
|
|
65
|
+
nluKeywordMessageId: this.request.input.message_id,
|
|
66
|
+
};
|
|
67
|
+
yield trackEvent(this.request, EventAction.keyword, eventArgs);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
15
70
|
}
|
|
16
71
|
//# sourceMappingURL=keyword.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyword.js","sourceRoot":"","sources":["../../../src/user-input/keyword.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"keyword.js","sourceRoot":"","sources":["../../../src/user-input/keyword.ts"],"names":[],"mappings":";AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAE9C,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAOrD,MAAM,OAAO,cAAc;IAQzB,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAgB;QACnD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,MAAM,GAAG,M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C,CAAA;QAChE,CAAC;KAAA;CACF"}
|
|
@@ -1,4 +1,21 @@
|
|
|
1
1
|
import { ActionRequest } from '@botonic/react';
|
|
2
2
|
import { FlowBuilderApi } from '../api';
|
|
3
3
|
import { HtSmartIntentNode } from '../content-fields/hubtype-fields/smart-intent';
|
|
4
|
-
export
|
|
4
|
+
export interface SmartIntentsInferenceParams {
|
|
5
|
+
bot_id: string;
|
|
6
|
+
text: string;
|
|
7
|
+
num_smart_intents_to_use?: number;
|
|
8
|
+
use_latest: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface SmartIntentsInferenceConfig {
|
|
11
|
+
useLatest: boolean;
|
|
12
|
+
numSmartIntentsToUse?: number;
|
|
13
|
+
}
|
|
14
|
+
export declare class SmartIntentsApi {
|
|
15
|
+
cmsApi: FlowBuilderApi;
|
|
16
|
+
currentRequest: ActionRequest;
|
|
17
|
+
smartIntentsConfig: SmartIntentsInferenceConfig;
|
|
18
|
+
constructor(cmsApi: FlowBuilderApi, currentRequest: ActionRequest, smartIntentsConfig: SmartIntentsInferenceConfig);
|
|
19
|
+
getNodeByInput(): Promise<HtSmartIntentNode | undefined>;
|
|
20
|
+
private getInference;
|
|
21
|
+
}
|
|
@@ -1,38 +1,56 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
2
|
import axios from 'axios';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
3
|
+
import { EventAction, trackEvent } from '../tracking';
|
|
4
|
+
export class SmartIntentsApi {
|
|
5
|
+
constructor(cmsApi, currentRequest, smartIntentsConfig) {
|
|
6
|
+
this.cmsApi = cmsApi;
|
|
7
|
+
this.currentRequest = currentRequest;
|
|
8
|
+
this.smartIntentsConfig = smartIntentsConfig;
|
|
9
|
+
}
|
|
10
|
+
getNodeByInput() {
|
|
11
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
12
|
+
if (!this.currentRequest.input.data)
|
|
13
|
+
return undefined;
|
|
14
|
+
const smartIntentNodes = this.cmsApi.getSmartIntentNodes();
|
|
15
|
+
if (!smartIntentNodes.length)
|
|
16
|
+
return undefined;
|
|
17
|
+
const params = {
|
|
18
|
+
bot_id: this.currentRequest.session.bot.id,
|
|
19
|
+
text: this.currentRequest.input.data,
|
|
20
|
+
num_smart_intents_to_use: this.smartIntentsConfig.numSmartIntentsToUse,
|
|
21
|
+
use_latest: this.smartIntentsConfig.useLatest,
|
|
13
22
|
};
|
|
23
|
+
try {
|
|
24
|
+
const response = yield this.getInference(params);
|
|
25
|
+
const smartIntentNode = smartIntentNodes.find(smartIntentNode => smartIntentNode.content.title === response.data.smart_intent_title);
|
|
26
|
+
if (smartIntentNode) {
|
|
27
|
+
trackEvent(this.currentRequest, EventAction.intentSmart, {
|
|
28
|
+
nluIntentSmartTitle: response.data.smart_intent_title,
|
|
29
|
+
nluIntentSmartNumUsed: response.data.smart_intents_used,
|
|
30
|
+
nluIntentSmartMessageId: this.currentRequest.input.message_id,
|
|
31
|
+
});
|
|
32
|
+
return smartIntentNode;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
console.error(e);
|
|
37
|
+
}
|
|
38
|
+
return undefined;
|
|
14
39
|
});
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
try {
|
|
20
|
-
const response = yield axios({
|
|
40
|
+
}
|
|
41
|
+
getInference(inferenceParams) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
return yield axios({
|
|
21
44
|
method: 'POST',
|
|
22
|
-
url: `${process.env.HUBTYPE_API_URL}/external/
|
|
45
|
+
url: `${process.env.HUBTYPE_API_URL}/external/v2/ai/smart_intents/inference/`,
|
|
23
46
|
headers: {
|
|
24
|
-
Authorization: `Bearer ${
|
|
47
|
+
Authorization: `Bearer ${this.currentRequest.session._access_token}`,
|
|
25
48
|
'Content-Type': 'application/json',
|
|
26
49
|
},
|
|
27
|
-
data:
|
|
50
|
+
data: inferenceParams,
|
|
28
51
|
timeout: 10000,
|
|
29
52
|
});
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
catch (e) {
|
|
33
|
-
console.error(e);
|
|
34
|
-
return undefined;
|
|
35
|
-
}
|
|
36
|
-
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
37
55
|
}
|
|
38
56
|
//# sourceMappingURL=smart-intent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"smart-intent.js","sourceRoot":"","sources":["../../../src/user-input/smart-intent.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"smart-intent.js","sourceRoot":"","sources":["../../../src/user-input/smart-intent.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,MAAM,OAAO,CAAA;AAIzB,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAerD,MAAM,OAAO,eAAe;IAC1B,YACS,MAAsB,EACtB,cAA6B,EAC7B,kBAA+C;QAF/C,WAAM,GAAN,MAAM,CAAgB;QACtB,mBAAc,GAAd,cAAc,CAAe;QAC7B,uBAAkB,GAAlB,kBAAkB,CAA6B;IACrD,CAAC;IAEE,cAAc;;YAClB,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,IAAI;gBAAE,OAAO,SAAS,CAAA;YACrD,MAAM,gBAAgB,GAAG,IAAI,CAAC,MAAM,CAAC,mBAAmB,EAAE,CAAA;YAC1D,IAAI,CAAC,gBAAgB,CAAC,MAAM;gBAAE,OAAO,SAAS,CAAA;YAE9C,MAAM,MAAM,GAAG;gBACb,MAAM,EAAE,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;gBAC1C,IAAI,EAAE,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,IAAI;gBACpC,wBA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@botonic/plugin-flow-builder",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.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.27.0-alpha.0",
|
|
18
18
|
"axios": "^1.6.8",
|
|
19
19
|
"uuid": "^9.0.1"
|
|
20
20
|
},
|
package/src/action/index.tsx
CHANGED
|
@@ -5,7 +5,8 @@ import { FlowBuilderApi } from '../api'
|
|
|
5
5
|
import { FlowContent, FlowHandoff } from '../content-fields'
|
|
6
6
|
import { HtNodeWithContent } from '../content-fields/hubtype-fields'
|
|
7
7
|
import { getFlowBuilderPlugin } from '../helpers'
|
|
8
|
-
import
|
|
8
|
+
import BotonicPluginFlowBuilder from '../index'
|
|
9
|
+
import { EventAction, getNodeEventArgs, trackEvent } from '../tracking'
|
|
9
10
|
import { createNodeFromKnowledgeBase } from './knowledge-bases'
|
|
10
11
|
|
|
11
12
|
export type FlowBuilderActionProps = {
|
|
@@ -18,15 +19,7 @@ export class FlowBuilderAction extends React.Component<FlowBuilderActionProps> {
|
|
|
18
19
|
static async botonicInit(
|
|
19
20
|
request: ActionRequest
|
|
20
21
|
): Promise<FlowBuilderActionProps> {
|
|
21
|
-
const
|
|
22
|
-
const locale = flowBuilderPlugin.getLocale(request.session)
|
|
23
|
-
|
|
24
|
-
const targetNode = await getTargetNode(flowBuilderPlugin.cmsApi, request)
|
|
25
|
-
|
|
26
|
-
const contents = await flowBuilderPlugin.getContentsByNode(
|
|
27
|
-
targetNode,
|
|
28
|
-
locale
|
|
29
|
-
)
|
|
22
|
+
const contents = await getContents(request)
|
|
30
23
|
|
|
31
24
|
const handoffContent = contents.find(
|
|
32
25
|
content => content instanceof FlowHandoff
|
|
@@ -55,26 +48,64 @@ export class FlowBuilderMultichannelAction extends FlowBuilderAction {
|
|
|
55
48
|
}
|
|
56
49
|
}
|
|
57
50
|
|
|
58
|
-
async function
|
|
51
|
+
async function getContents(request: ActionRequest): Promise<FlowContent[]> {
|
|
52
|
+
const flowBuilderPlugin = getFlowBuilderPlugin(request.plugins)
|
|
53
|
+
const cmsApi = flowBuilderPlugin.cmsApi
|
|
54
|
+
const locale = flowBuilderPlugin.getLocale(request.session)
|
|
55
|
+
const resolvedLocale = flowBuilderPlugin.cmsApi.getResolvedLocale(locale)
|
|
56
|
+
const context = {
|
|
57
|
+
cmsApi,
|
|
58
|
+
flowBuilderPlugin,
|
|
59
|
+
request,
|
|
60
|
+
resolvedLocale,
|
|
61
|
+
}
|
|
62
|
+
|
|
59
63
|
if (request.session.is_first_interaction) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
64
|
+
return await flowBuilderPlugin.getStartContents(resolvedLocale)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (request.input.payload) {
|
|
68
|
+
return await getContentsByPayload(context)
|
|
63
69
|
}
|
|
64
|
-
const contentId = request.input.payload
|
|
65
70
|
|
|
66
|
-
|
|
67
|
-
|
|
71
|
+
return await getContentsByFallback(context)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
interface FlowBuilderContext {
|
|
75
|
+
cmsApi: FlowBuilderApi
|
|
76
|
+
flowBuilderPlugin: BotonicPluginFlowBuilder
|
|
77
|
+
request: ActionRequest
|
|
78
|
+
resolvedLocale: string
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function getContentsByPayload({
|
|
82
|
+
cmsApi,
|
|
83
|
+
flowBuilderPlugin,
|
|
84
|
+
request,
|
|
85
|
+
resolvedLocale,
|
|
86
|
+
}: FlowBuilderContext): Promise<FlowContent[]> {
|
|
87
|
+
const targetNode = request.input.payload
|
|
88
|
+
? cmsApi.getNodeById<HtNodeWithContent>(request.input.payload)
|
|
68
89
|
: undefined
|
|
69
90
|
|
|
70
91
|
if (targetNode) {
|
|
71
|
-
const eventArgs =
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
await trackEvent(request, EventName.botFaq, eventArgs)
|
|
75
|
-
return targetNode
|
|
92
|
+
const eventArgs = getNodeEventArgs(request, targetNode)
|
|
93
|
+
await trackEvent(request, EventAction.flowNode, eventArgs)
|
|
94
|
+
return await flowBuilderPlugin.getContentsByNode(targetNode, resolvedLocale)
|
|
76
95
|
}
|
|
77
|
-
return
|
|
96
|
+
return []
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async function getContentsByFallback({
|
|
100
|
+
cmsApi,
|
|
101
|
+
flowBuilderPlugin,
|
|
102
|
+
request,
|
|
103
|
+
resolvedLocale,
|
|
104
|
+
}: FlowBuilderContext): Promise<FlowContent[]> {
|
|
105
|
+
const fallbackNode = await getFallbackNode(cmsApi, request)
|
|
106
|
+
const eventArgs = getNodeEventArgs(request, fallbackNode)
|
|
107
|
+
await trackEvent(request, EventAction.flowNode, eventArgs)
|
|
108
|
+
return await flowBuilderPlugin.getContentsByNode(fallbackNode, resolvedLocale)
|
|
78
109
|
}
|
|
79
110
|
|
|
80
111
|
async function getFallbackNode(cmsApi: FlowBuilderApi, request: ActionRequest) {
|
|
@@ -95,6 +126,9 @@ async function getFallbackNode(cmsApi: FlowBuilderApi, request: ActionRequest) {
|
|
|
95
126
|
const fallbackNode = cmsApi.getFallbackNode(isFirstFallbackOption)
|
|
96
127
|
request.session.user.extra_data.isFirstFallbackOption = !isFirstFallbackOption
|
|
97
128
|
|
|
98
|
-
|
|
129
|
+
trackEvent(request, EventAction.fallback, {
|
|
130
|
+
fallbackAttempt: isFirstFallbackOption ? 1 : 2,
|
|
131
|
+
})
|
|
132
|
+
|
|
99
133
|
return fallbackNode
|
|
100
134
|
}
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
HtTextNode,
|
|
10
10
|
} from '../content-fields/hubtype-fields'
|
|
11
11
|
import { getFlowBuilderPlugin } from '../helpers'
|
|
12
|
-
import {
|
|
12
|
+
import { EventAction, trackEvent } from '../tracking'
|
|
13
13
|
|
|
14
14
|
export async function createNodeFromKnowledgeBase(
|
|
15
15
|
cmsApi: FlowBuilderApi,
|
|
@@ -28,11 +28,11 @@ export async function createNodeFromKnowledgeBase(
|
|
|
28
28
|
const knowledgeBaseResponse =
|
|
29
29
|
await flowBuilderPlugin.getKnowledgeBaseResponse(request)
|
|
30
30
|
if (knowledgeBaseResponse.hasKnowledge) {
|
|
31
|
-
await trackEvent(request,
|
|
32
|
-
|
|
33
|
-
knowledge_source_ids: knowledgeBaseResponse.sources.map(
|
|
31
|
+
await trackEvent(request, EventAction.knowledgebase, {
|
|
32
|
+
knowledgebaseSourcesIds: knowledgeBaseResponse.sources.map(
|
|
34
33
|
source => source.knowledgeSourceId
|
|
35
34
|
),
|
|
35
|
+
knowledgebaseChunksIds: [],
|
|
36
36
|
})
|
|
37
37
|
|
|
38
38
|
const knowledgeBaseNode: HtTextNode = {
|
|
@@ -58,8 +58,19 @@ export async function createNodeFromKnowledgeBase(
|
|
|
58
58
|
}
|
|
59
59
|
return knowledgeBaseNode
|
|
60
60
|
}
|
|
61
|
+
await trackEvent(request, EventAction.knowledgebase, {
|
|
62
|
+
knowledgebaseFailReason:
|
|
63
|
+
'The knowledge base does not have enough knowledge',
|
|
64
|
+
knowledgeSourceIds: [],
|
|
65
|
+
knowledgebaseChunksIds: [],
|
|
66
|
+
})
|
|
61
67
|
} catch (e) {
|
|
62
|
-
console.
|
|
68
|
+
console.error('Hubtype knowledge base api error: ', { e })
|
|
69
|
+
await trackEvent(request, EventAction.knowledgebase, {
|
|
70
|
+
knowledgebaseFailReason: 'Knowledge base api error',
|
|
71
|
+
knowledgeSourceIds: [],
|
|
72
|
+
knowledgebaseChunksIds: [],
|
|
73
|
+
})
|
|
63
74
|
return undefined
|
|
64
75
|
}
|
|
65
76
|
}
|