@botonic/plugin-flow-builder 0.34.2 → 0.35.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.
Files changed (92) hide show
  1. package/lib/cjs/action/index.d.ts +1 -1
  2. package/lib/cjs/action/index.js +1 -1
  3. package/lib/cjs/action/index.js.map +1 -1
  4. package/lib/cjs/action/knowledge-bases.js.map +1 -1
  5. package/lib/cjs/api.d.ts +3 -6
  6. package/lib/cjs/api.js +6 -24
  7. package/lib/cjs/api.js.map +1 -1
  8. package/lib/cjs/content-fields/hubtype-fields/common.d.ts +1 -0
  9. package/lib/cjs/content-fields/hubtype-fields/index.d.ts +0 -1
  10. package/lib/cjs/content-fields/hubtype-fields/index.js +0 -1
  11. package/lib/cjs/content-fields/hubtype-fields/index.js.map +1 -1
  12. package/lib/cjs/content-fields/hubtype-fields/node-types.d.ts +0 -1
  13. package/lib/cjs/content-fields/hubtype-fields/node-types.js +0 -1
  14. package/lib/cjs/content-fields/hubtype-fields/node-types.js.map +1 -1
  15. package/lib/cjs/content-fields/hubtype-fields/nodes.d.ts +1 -2
  16. package/lib/cjs/helpers.d.ts +2 -4
  17. package/lib/cjs/helpers.js +8 -5
  18. package/lib/cjs/helpers.js.map +1 -1
  19. package/lib/cjs/index.d.ts +2 -2
  20. package/lib/cjs/index.js +7 -2
  21. package/lib/cjs/index.js.map +1 -1
  22. package/lib/cjs/tracking.d.ts +0 -1
  23. package/lib/cjs/tracking.js +0 -1
  24. package/lib/cjs/tracking.js.map +1 -1
  25. package/lib/cjs/types.d.ts +7 -8
  26. package/lib/cjs/types.js.map +1 -1
  27. package/lib/cjs/user-input/index.d.ts +2 -2
  28. package/lib/cjs/user-input/index.js +0 -8
  29. package/lib/cjs/user-input/index.js.map +1 -1
  30. package/lib/cjs/utils.d.ts +1 -2
  31. package/lib/cjs/utils.js +2 -2
  32. package/lib/cjs/utils.js.map +1 -1
  33. package/lib/esm/action/index.d.ts +1 -1
  34. package/lib/esm/action/index.js +1 -1
  35. package/lib/esm/action/index.js.map +1 -1
  36. package/lib/esm/action/knowledge-bases.js.map +1 -1
  37. package/lib/esm/api.d.ts +3 -6
  38. package/lib/esm/api.js +6 -24
  39. package/lib/esm/api.js.map +1 -1
  40. package/lib/esm/content-fields/hubtype-fields/common.d.ts +1 -0
  41. package/lib/esm/content-fields/hubtype-fields/index.d.ts +0 -1
  42. package/lib/esm/content-fields/hubtype-fields/index.js +0 -1
  43. package/lib/esm/content-fields/hubtype-fields/index.js.map +1 -1
  44. package/lib/esm/content-fields/hubtype-fields/node-types.d.ts +0 -1
  45. package/lib/esm/content-fields/hubtype-fields/node-types.js +0 -1
  46. package/lib/esm/content-fields/hubtype-fields/node-types.js.map +1 -1
  47. package/lib/esm/content-fields/hubtype-fields/nodes.d.ts +1 -2
  48. package/lib/esm/helpers.d.ts +2 -4
  49. package/lib/esm/helpers.js +8 -5
  50. package/lib/esm/helpers.js.map +1 -1
  51. package/lib/esm/index.d.ts +2 -2
  52. package/lib/esm/index.js +7 -2
  53. package/lib/esm/index.js.map +1 -1
  54. package/lib/esm/tracking.d.ts +0 -1
  55. package/lib/esm/tracking.js +0 -1
  56. package/lib/esm/tracking.js.map +1 -1
  57. package/lib/esm/types.d.ts +7 -8
  58. package/lib/esm/types.js.map +1 -1
  59. package/lib/esm/user-input/index.d.ts +2 -2
  60. package/lib/esm/user-input/index.js +0 -8
  61. package/lib/esm/user-input/index.js.map +1 -1
  62. package/lib/esm/utils.d.ts +1 -2
  63. package/lib/esm/utils.js +3 -3
  64. package/lib/esm/utils.js.map +1 -1
  65. package/package.json +2 -2
  66. package/src/action/index.tsx +1 -1
  67. package/src/action/knowledge-bases.ts +7 -5
  68. package/src/api.ts +13 -44
  69. package/src/content-fields/hubtype-fields/common.ts +1 -0
  70. package/src/content-fields/hubtype-fields/index.ts +0 -1
  71. package/src/content-fields/hubtype-fields/node-types.ts +0 -1
  72. package/src/content-fields/hubtype-fields/nodes.ts +0 -2
  73. package/src/helpers.ts +17 -11
  74. package/src/index.ts +14 -4
  75. package/src/tracking.ts +0 -1
  76. package/src/types.ts +23 -10
  77. package/src/user-input/index.ts +1 -11
  78. package/src/utils.ts +3 -7
  79. package/lib/cjs/content-fields/hubtype-fields/intent.d.ts +0 -10
  80. package/lib/cjs/content-fields/hubtype-fields/intent.js +0 -3
  81. package/lib/cjs/content-fields/hubtype-fields/intent.js.map +0 -1
  82. package/lib/cjs/user-input/intent.d.ts +0 -4
  83. package/lib/cjs/user-input/intent.js +0 -45
  84. package/lib/cjs/user-input/intent.js.map +0 -1
  85. package/lib/esm/content-fields/hubtype-fields/intent.d.ts +0 -10
  86. package/lib/esm/content-fields/hubtype-fields/intent.js +0 -2
  87. package/lib/esm/content-fields/hubtype-fields/intent.js.map +0 -1
  88. package/lib/esm/user-input/intent.d.ts +0 -4
  89. package/lib/esm/user-input/intent.js +0 -41
  90. package/lib/esm/user-input/intent.js.map +0 -1
  91. package/src/content-fields/hubtype-fields/intent.ts +0 -12
  92. package/src/user-input/intent.ts +0 -59
package/src/helpers.ts CHANGED
@@ -1,19 +1,25 @@
1
- import { Plugin } from '@botonic/core'
1
+ import { ResolvedPlugins } from '@botonic/core'
2
2
 
3
3
  import BotonicPluginFlowBuilder from './index'
4
4
 
5
5
  const FLOW_BUILDER_PLUGIN_NAME = 'BotonicPluginFlowBuilder'
6
6
 
7
- export function getFlowBuilderPlugin(plugins: {
8
- [id: string]: Plugin
9
- }): BotonicPluginFlowBuilder {
7
+ export function getFlowBuilderPlugin(
8
+ plugins: ResolvedPlugins
9
+ ): BotonicPluginFlowBuilder {
10
+ const ERROR_MESSAGE = `You must include '@botonic/plugin-flow-builder' in your plugins file.`
11
+
12
+ if (Object.values(plugins).length === 0) {
13
+ throw new Error(ERROR_MESSAGE)
14
+ }
15
+
10
16
  const flowBuilderPlugin = Object.values(plugins).find(
11
- // @ts-ignore
12
- plugin => plugin.name.includes(FLOW_BUILDER_PLUGIN_NAME)
13
- ) as BotonicPluginFlowBuilder
14
- if (!flowBuilderPlugin)
15
- throw new Error(
16
- `You must include '@botonic/plugin-flow-builder' in your plugins file.`
17
- )
17
+ plugin => plugin.constructor.name === FLOW_BUILDER_PLUGIN_NAME
18
+ ) as unknown as BotonicPluginFlowBuilder
19
+
20
+ if (!flowBuilderPlugin) {
21
+ throw new Error(ERROR_MESSAGE)
22
+ }
23
+
18
24
  return flowBuilderPlugin
19
25
  }
package/src/index.ts CHANGED
@@ -1,4 +1,9 @@
1
- import { Plugin, PluginPreRequest, Session } from '@botonic/core'
1
+ import {
2
+ Plugin,
3
+ PluginPreRequest,
4
+ ResolvedPlugins,
5
+ Session,
6
+ } from '@botonic/core'
2
7
  import { ActionRequest } from '@botonic/react'
3
8
  import { v7 as uuidv7 } from 'uuid'
4
9
 
@@ -61,12 +66,17 @@ export default class BotonicPluginFlowBuilder implements Plugin {
61
66
  public jsonVersion: FlowBuilderJSONVersion
62
67
  public apiUrl: string
63
68
 
64
- constructor(options: BotonicPluginFlowBuilderOptions) {
69
+ constructor(options: BotonicPluginFlowBuilderOptions<ResolvedPlugins, any>) {
65
70
  this.apiUrl = options.apiUrl || FLOW_BUILDER_API_URL_PROD
66
71
  this.jsonVersion = options.jsonVersion || FlowBuilderJSONVersion.LATEST
67
72
  this.flow = options.flow
68
- this.getLocale = options.getLocale
69
- this.getAccessToken = resolveGetAccessToken(options)
73
+ this.getLocale =
74
+ typeof options.getLocale === 'function'
75
+ ? options.getLocale
76
+ : (session: Session) => {
77
+ return session.user.system_locale
78
+ }
79
+ this.getAccessToken = resolveGetAccessToken(options.getAccessToken)
70
80
  this.trackEvent = options.trackEvent
71
81
  this.getKnowledgeBaseResponse = options.getKnowledgeBaseResponse
72
82
  this.smartIntentsConfig = {
package/src/tracking.ts CHANGED
@@ -11,7 +11,6 @@ import { getFlowBuilderPlugin } from './helpers'
11
11
  export enum EventAction {
12
12
  FlowNode = 'flow_node',
13
13
  Keyword = 'nlu_keyword',
14
- Intent = 'nlu_intent',
15
14
  IntentSmart = 'nlu_intent_smart',
16
15
  Knowledgebase = 'knowledgebase',
17
16
  Fallback = 'fallback',
package/src/types.ts CHANGED
@@ -1,5 +1,9 @@
1
- import { PluginPreRequest, Session } from '@botonic/core'
2
- import { ActionRequest } from '@botonic/react'
1
+ import {
2
+ BotContext,
3
+ PluginPreRequest,
4
+ ResolvedPlugins,
5
+ Session,
6
+ } from '@botonic/core'
3
7
 
4
8
  import { HtFlowBuilderData } from './content-fields/hubtype-fields'
5
9
 
@@ -9,27 +13,36 @@ export interface InShadowingConfig {
9
13
  allowKnowledgeBases: boolean
10
14
  }
11
15
 
12
- export interface BotonicPluginFlowBuilderOptions {
16
+ export interface BotonicPluginFlowBuilderOptions<
17
+ TPlugins extends ResolvedPlugins = ResolvedPlugins,
18
+ TExtraData = any,
19
+ > {
13
20
  apiUrl?: string
14
21
  jsonVersion?: FlowBuilderJSONVersion
15
22
  flow?: HtFlowBuilderData
16
23
  customFunctions?: Record<any, any>
17
- getLocale: (session: Session) => string
24
+ getLocale?: (session: Session) => string
18
25
  getAccessToken: () => string
19
- trackEvent?: TrackEventFunction
20
- getKnowledgeBaseResponse?: KnowledgeBaseFunction
26
+ trackEvent?: TrackEventFunction<TPlugins, TExtraData>
27
+ getKnowledgeBaseResponse?: KnowledgeBaseFunction<TPlugins, TExtraData>
21
28
  smartIntentsConfig?: { numSmartIntentsToUse: number }
22
29
  inShadowing?: Partial<InShadowingConfig>
23
30
  }
24
31
 
25
- export type TrackEventFunction = (
26
- request: ActionRequest,
32
+ export type TrackEventFunction<
33
+ TPlugins extends ResolvedPlugins = ResolvedPlugins,
34
+ TExtraData = any,
35
+ > = (
36
+ request: BotContext<TPlugins, TExtraData>,
27
37
  eventAction: string,
28
38
  args?: Record<string, any>
29
39
  ) => Promise<void>
30
40
 
31
- export type KnowledgeBaseFunction = (
32
- request: ActionRequest,
41
+ export type KnowledgeBaseFunction<
42
+ TPlugins extends ResolvedPlugins = ResolvedPlugins,
43
+ TExtraData = any,
44
+ > = (
45
+ request: BotContext<TPlugins, TExtraData>,
33
46
  sources: string[],
34
47
  instructions: string,
35
48
  messageId: string,
@@ -2,7 +2,6 @@ import { ActionRequest } from '@botonic/react'
2
2
 
3
3
  import { FlowBuilderApi } from '../api'
4
4
  import {
5
- HtIntentNode,
6
5
  HtKeywordNode,
7
6
  HtSmartIntentNode,
8
7
  } from '../content-fields/hubtype-fields'
@@ -11,7 +10,6 @@ import {
11
10
  isKeywordsAllowed,
12
11
  isSmartIntentsAllowed,
13
12
  } from '../utils'
14
- import { getIntentNodeByInput } from './intent'
15
13
  import { KeywordMatcher } from './keyword'
16
14
  import { SmartIntentsApi, SmartIntentsInferenceConfig } from './smart-intent'
17
15
 
@@ -20,7 +18,7 @@ export async function getNodeByUserInput(
20
18
  locale: string,
21
19
  request: ActionRequest,
22
20
  smartIntentsConfig: SmartIntentsInferenceConfig
23
- ): Promise<HtSmartIntentNode | HtIntentNode | HtKeywordNode | undefined> {
21
+ ): Promise<HtSmartIntentNode | HtKeywordNode | undefined> {
24
22
  if (inputHasTextData(request.input)) {
25
23
  if (isKeywordsAllowed(request)) {
26
24
  const keywordMatcher = new KeywordMatcher({
@@ -47,14 +45,6 @@ export async function getNodeByUserInput(
47
45
  return smartIntentNode
48
46
  }
49
47
  }
50
-
51
- // TODO: Remove this because frontend no allow create intents babel
52
- if (isSmartIntentsAllowed(request)) {
53
- const intentNode = await getIntentNodeByInput(cmsApi, locale, request)
54
- if (intentNode) {
55
- return intentNode
56
- }
57
- }
58
48
  }
59
49
 
60
50
  return undefined
package/src/utils.ts CHANGED
@@ -2,11 +2,7 @@ import { INPUT, Input, Session } from '@botonic/core'
2
2
  import { ActionRequest } from '@botonic/react'
3
3
 
4
4
  import { getFlowBuilderPlugin } from './helpers'
5
- import {
6
- BotonicPluginFlowBuilderOptions,
7
- InShadowingConfig,
8
- ProcessEnvNodeEnvs,
9
- } from './types'
5
+ import { InShadowingConfig, ProcessEnvNodeEnvs } from './types'
10
6
 
11
7
  function getAccessTokenFromSession(session: Session): string {
12
8
  if (!session._access_token) {
@@ -16,13 +12,13 @@ function getAccessTokenFromSession(session: Session): string {
16
12
  }
17
13
 
18
14
  export function resolveGetAccessToken(
19
- options: BotonicPluginFlowBuilderOptions
15
+ getAccessToken: (session: Session) => string
20
16
  ): (session: Session) => string {
21
17
  switch (process.env.NODE_ENV) {
22
18
  case ProcessEnvNodeEnvs.PRODUCTION:
23
19
  return getAccessTokenFromSession
24
20
  case ProcessEnvNodeEnvs.DEVELOPMENT:
25
- return options.getAccessToken
21
+ return getAccessToken
26
22
  default:
27
23
  throw new Error('No method defined for getting access token')
28
24
  }
@@ -1,10 +0,0 @@
1
- import { HtBaseNode, HtInputLocale, HtTextLocale } from './common';
2
- import { HtNodeWithContentType } from './node-types';
3
- export interface HtIntentNode extends HtBaseNode {
4
- type: HtNodeWithContentType.INTENT;
5
- content: {
6
- title: HtTextLocale[];
7
- intents: HtInputLocale[];
8
- confidence: number;
9
- };
10
- }
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=intent.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"intent.js","sourceRoot":"","sources":["../../../../src/content-fields/hubtype-fields/intent.ts"],"names":[],"mappings":""}
@@ -1,4 +0,0 @@
1
- import { ActionRequest } from '@botonic/react';
2
- import { FlowBuilderApi } from '../api';
3
- import { HtIntentNode } from '../content-fields/hubtype-fields';
4
- export declare function getIntentNodeByInput(cmsApi: FlowBuilderApi, locale: string, request: ActionRequest): Promise<HtIntentNode | undefined>;
@@ -1,45 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getIntentNodeByInput = void 0;
4
- const tslib_1 = require("tslib");
5
- const core_1 = require("@botonic/core");
6
- const tracking_1 = require("../tracking");
7
- function getIntentNodeByInput(cmsApi, locale, request) {
8
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
9
- const intentNode = cmsApi.getIntentNode(request.input, locale);
10
- if (request.input.confidence && request.input.intent && intentNode) {
11
- yield trackIntentEvent(request, intentNode);
12
- if (isIntentValid(intentNode, request, cmsApi)) {
13
- const targetPayload = cmsApi.getPayload(intentNode.target);
14
- request.input.nluResolution = {
15
- type: core_1.NluType.Intent,
16
- matchedValue: request.input.intent,
17
- payload: targetPayload,
18
- };
19
- return intentNode;
20
- }
21
- }
22
- return undefined;
23
- });
24
- }
25
- exports.getIntentNodeByInput = getIntentNodeByInput;
26
- function trackIntentEvent(request, intentNode) {
27
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
28
- const eventArgs = {
29
- nluIntentLabel: request.input.intent,
30
- nluIntentConfidence: request.input.confidence,
31
- nluIntentThreshold: intentNode === null || intentNode === void 0 ? void 0 : intentNode.content.confidence,
32
- nluIntentMessageId: request.input.message_id,
33
- userInput: request.input.data,
34
- flowThreadId: request.session.flow_thread_id,
35
- flowId: intentNode.flow_id,
36
- flowNodeId: intentNode.id,
37
- };
38
- yield (0, tracking_1.trackEvent)(request, tracking_1.EventAction.Intent, eventArgs);
39
- });
40
- }
41
- function isIntentValid(intentNode, request, cmsApi) {
42
- return (request.input.confidence &&
43
- cmsApi.hasMetConfidenceThreshold(intentNode, request.input.confidence));
44
- }
45
- //# sourceMappingURL=intent.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"intent.js","sourceRoot":"","sources":["../../../src/user-input/intent.ts"],"names":[],"mappings":";;;;AAAA,wCAAuC;AAKvC,0CAAqD;AAErD,SAAsB,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,MAAM,aAAa,GAAG,MAAM,CAAC,UAAU,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA;gBAE1D,OAAO,CAAC,KAAK,CAAC,aAAa,GAAG;oBAC5B,IAAI,EAAE,cAAO,CAAC,MAAM;oBACpB,YAAY,EAAE,OAAO,CAAC,KAAK,CAAC,MAAM;oBAClC,OAAO,EAAE,aAAa;iBACvB,CAAA;gBACD,OAAO,UAAU,CAAA;aAClB;SACF;QAED,OAAO,SAAS,CAAA;IAClB,CAAC;CAAA;AAvBD,oDAuBC;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;YAC5C,SAAS,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI;YAC7B,YAAY,EAAE,OAAO,CAAC,OAAO,CAAC,cAAc;YAC5C,MAAM,EAAE,UAAU,CAAC,OAAO;YAC1B,UAAU,EAAE,UAAU,CAAC,EAAE;SAC1B,CAAA;QACD,MAAM,IAAA,qBAAU,EAAC,OAAO,EAAE,sBAAW,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,10 +0,0 @@
1
- import { HtBaseNode, HtInputLocale, HtTextLocale } from './common';
2
- import { HtNodeWithContentType } from './node-types';
3
- export interface HtIntentNode extends HtBaseNode {
4
- type: HtNodeWithContentType.INTENT;
5
- content: {
6
- title: HtTextLocale[];
7
- intents: HtInputLocale[];
8
- confidence: number;
9
- };
10
- }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=intent.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"intent.js","sourceRoot":"","sources":["../../../../src/content-fields/hubtype-fields/intent.ts"],"names":[],"mappings":""}
@@ -1,4 +0,0 @@
1
- import { ActionRequest } from '@botonic/react';
2
- import { FlowBuilderApi } from '../api';
3
- import { HtIntentNode } from '../content-fields/hubtype-fields';
4
- export declare function getIntentNodeByInput(cmsApi: FlowBuilderApi, locale: string, request: ActionRequest): Promise<HtIntentNode | undefined>;
@@ -1,41 +0,0 @@
1
- import { __awaiter } from "tslib";
2
- import { NluType } from '@botonic/core';
3
- import { EventAction, trackEvent } from '../tracking';
4
- export function getIntentNodeByInput(cmsApi, locale, request) {
5
- return __awaiter(this, void 0, void 0, function* () {
6
- const intentNode = cmsApi.getIntentNode(request.input, locale);
7
- if (request.input.confidence && request.input.intent && intentNode) {
8
- yield trackIntentEvent(request, intentNode);
9
- if (isIntentValid(intentNode, request, cmsApi)) {
10
- const targetPayload = cmsApi.getPayload(intentNode.target);
11
- request.input.nluResolution = {
12
- type: NluType.Intent,
13
- matchedValue: request.input.intent,
14
- payload: targetPayload,
15
- };
16
- return intentNode;
17
- }
18
- }
19
- return undefined;
20
- });
21
- }
22
- function trackIntentEvent(request, intentNode) {
23
- return __awaiter(this, void 0, void 0, function* () {
24
- const eventArgs = {
25
- nluIntentLabel: request.input.intent,
26
- nluIntentConfidence: request.input.confidence,
27
- nluIntentThreshold: intentNode === null || intentNode === void 0 ? void 0 : intentNode.content.confidence,
28
- nluIntentMessageId: request.input.message_id,
29
- userInput: request.input.data,
30
- flowThreadId: request.session.flow_thread_id,
31
- flowId: intentNode.flow_id,
32
- flowNodeId: intentNode.id,
33
- };
34
- yield trackEvent(request, EventAction.Intent, eventArgs);
35
- });
36
- }
37
- function isIntentValid(intentNode, request, cmsApi) {
38
- return (request.input.confidence &&
39
- cmsApi.hasMetConfidenceThreshold(intentNode, request.input.confidence));
40
- }
41
- //# sourceMappingURL=intent.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"intent.js","sourceRoot":"","sources":["../../../src/user-input/intent.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAKvC,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,MAAM,aAAa,GAAG,MAAM,CAAC,UAAU,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA;gBAE1D,OAAO,CAAC,KAAK,CAAC,aAAa,GAAG;oBAC5B,IAAI,EAAE,OAAO,CAAC,MAAM;oBACpB,YAAY,EAAE,OAAO,CAAC,KAAK,CAAC,MAAM;oBAClC,OAAO,EAAE,aAAa;iBACvB,CAAA;gBACD,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;YAC5C,SAAS,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI;YAC7B,YAAY,EAAE,OAAO,CAAC,OAAO,CAAC,cAAc;YAC5C,MAAM,EAAE,UAAU,CAAC,OAAO;YAC1B,UAAU,EAAE,UAAU,CAAC,EAAE;SAC1B,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,12 +0,0 @@
1
- import { HtBaseNode, HtInputLocale, HtTextLocale } from './common'
2
- import { HtNodeWithContentType } from './node-types'
3
-
4
- // TODO: Remove this because frontend no allow create intents babel
5
- export interface HtIntentNode extends HtBaseNode {
6
- type: HtNodeWithContentType.INTENT
7
- content: {
8
- title: HtTextLocale[]
9
- intents: HtInputLocale[]
10
- confidence: number
11
- }
12
- }
@@ -1,59 +0,0 @@
1
- import { NluType } from '@botonic/core'
2
- import { ActionRequest } from '@botonic/react'
3
-
4
- import { FlowBuilderApi } from '../api'
5
- import { HtIntentNode } from '../content-fields/hubtype-fields'
6
- import { EventAction, trackEvent } from '../tracking'
7
-
8
- export async function getIntentNodeByInput(
9
- cmsApi: FlowBuilderApi,
10
- locale: string,
11
- request: ActionRequest
12
- ): Promise<HtIntentNode | undefined> {
13
- const intentNode = cmsApi.getIntentNode(request.input, locale)
14
-
15
- if (request.input.confidence && request.input.intent && intentNode) {
16
- await trackIntentEvent(request, intentNode)
17
-
18
- if (isIntentValid(intentNode, request, cmsApi)) {
19
- const targetPayload = cmsApi.getPayload(intentNode.target)
20
-
21
- request.input.nluResolution = {
22
- type: NluType.Intent,
23
- matchedValue: request.input.intent,
24
- payload: targetPayload,
25
- }
26
- return intentNode
27
- }
28
- }
29
-
30
- return undefined
31
- }
32
-
33
- async function trackIntentEvent(
34
- request: ActionRequest,
35
- intentNode: HtIntentNode
36
- ) {
37
- const eventArgs = {
38
- nluIntentLabel: request.input.intent,
39
- nluIntentConfidence: request.input.confidence,
40
- nluIntentThreshold: intentNode?.content.confidence,
41
- nluIntentMessageId: request.input.message_id,
42
- userInput: request.input.data,
43
- flowThreadId: request.session.flow_thread_id,
44
- flowId: intentNode.flow_id,
45
- flowNodeId: intentNode.id,
46
- }
47
- await trackEvent(request, EventAction.Intent, eventArgs)
48
- }
49
-
50
- function isIntentValid(
51
- intentNode: HtIntentNode,
52
- request: ActionRequest,
53
- cmsApi: FlowBuilderApi
54
- ) {
55
- return (
56
- request.input.confidence &&
57
- cmsApi.hasMetConfidenceThreshold(intentNode, request.input.confidence)
58
- )
59
- }