@botonic/plugin-flow-builder 0.27.0-alpha.4 → 0.27.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/fallback.d.ts +3 -0
- package/lib/cjs/action/fallback.js +30 -0
- package/lib/cjs/action/fallback.js.map +1 -0
- package/lib/cjs/action/index.d.ts +8 -0
- package/lib/cjs/action/index.js +8 -32
- package/lib/cjs/action/index.js.map +1 -1
- package/lib/cjs/action/knowledge-bases.d.ts +3 -4
- package/lib/cjs/action/knowledge-bases.js +51 -49
- package/lib/cjs/action/knowledge-bases.js.map +1 -1
- package/lib/cjs/api.d.ts +2 -0
- package/lib/cjs/api.js +10 -0
- package/lib/cjs/api.js.map +1 -1
- package/lib/cjs/constants.d.ts +3 -0
- package/lib/cjs/constants.js +4 -1
- package/lib/cjs/constants.js.map +1 -1
- package/lib/cjs/content-fields/flow-knowledge-base.d.ts +9 -0
- package/lib/cjs/content-fields/flow-knowledge-base.js +25 -0
- package/lib/cjs/content-fields/flow-knowledge-base.js.map +1 -0
- package/lib/cjs/content-fields/flow-whatsapp-cta-url-button.d.ts +1 -1
- package/lib/cjs/content-fields/flow-whatsapp-cta-url-button.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 +2 -0
- package/lib/cjs/content-fields/hubtype-fields/index.js +2 -0
- package/lib/cjs/content-fields/hubtype-fields/index.js.map +1 -1
- package/lib/cjs/content-fields/hubtype-fields/knowledge-base.d.ts +8 -0
- package/lib/cjs/content-fields/hubtype-fields/knowledge-base.js +3 -0
- package/lib/cjs/content-fields/hubtype-fields/knowledge-base.js.map +1 -0
- package/lib/cjs/content-fields/hubtype-fields/node-types.d.ts +2 -1
- 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/index.d.ts +3 -2
- package/lib/cjs/content-fields/index.js +3 -1
- package/lib/cjs/content-fields/index.js.map +1 -1
- package/lib/cjs/index.d.ts +3 -4
- package/lib/cjs/index.js +6 -8
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/types.d.ts +4 -2
- package/lib/cjs/types.js.map +1 -1
- package/lib/cjs/user-input/intent.js +1 -0
- package/lib/cjs/user-input/intent.js.map +1 -1
- package/lib/cjs/user-input/keyword.js +1 -0
- package/lib/cjs/user-input/keyword.js.map +1 -1
- package/lib/cjs/user-input/smart-intent.js +1 -0
- package/lib/cjs/user-input/smart-intent.js.map +1 -1
- package/lib/esm/action/fallback.d.ts +3 -0
- package/lib/esm/action/fallback.js +26 -0
- package/lib/esm/action/fallback.js.map +1 -0
- package/lib/esm/action/index.d.ts +8 -0
- package/lib/esm/action/index.js +9 -33
- package/lib/esm/action/index.js.map +1 -1
- package/lib/esm/action/knowledge-bases.d.ts +3 -4
- package/lib/esm/action/knowledge-bases.js +49 -47
- package/lib/esm/action/knowledge-bases.js.map +1 -1
- package/lib/esm/api.d.ts +2 -0
- package/lib/esm/api.js +11 -1
- package/lib/esm/api.js.map +1 -1
- package/lib/esm/constants.d.ts +3 -0
- package/lib/esm/constants.js +3 -0
- package/lib/esm/constants.js.map +1 -1
- package/lib/esm/content-fields/flow-knowledge-base.d.ts +9 -0
- package/lib/esm/content-fields/flow-knowledge-base.js +21 -0
- package/lib/esm/content-fields/flow-knowledge-base.js.map +1 -0
- package/lib/esm/content-fields/flow-whatsapp-cta-url-button.d.ts +1 -1
- package/lib/esm/content-fields/flow-whatsapp-cta-url-button.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 +2 -0
- package/lib/esm/content-fields/hubtype-fields/index.js +2 -0
- package/lib/esm/content-fields/hubtype-fields/index.js.map +1 -1
- package/lib/esm/content-fields/hubtype-fields/knowledge-base.d.ts +8 -0
- package/lib/esm/content-fields/hubtype-fields/knowledge-base.js +2 -0
- package/lib/esm/content-fields/hubtype-fields/knowledge-base.js.map +1 -0
- package/lib/esm/content-fields/hubtype-fields/node-types.d.ts +2 -1
- 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/index.d.ts +3 -2
- package/lib/esm/content-fields/index.js +2 -1
- package/lib/esm/content-fields/index.js.map +1 -1
- package/lib/esm/index.d.ts +3 -4
- package/lib/esm/index.js +4 -6
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/types.d.ts +4 -2
- package/lib/esm/types.js.map +1 -1
- package/lib/esm/user-input/intent.js +1 -0
- package/lib/esm/user-input/intent.js.map +1 -1
- package/lib/esm/user-input/keyword.js +1 -0
- package/lib/esm/user-input/keyword.js.map +1 -1
- package/lib/esm/user-input/smart-intent.js +1 -0
- package/lib/esm/user-input/smart-intent.js.map +1 -1
- package/package.json +2 -2
- package/src/action/fallback.ts +42 -0
- package/src/action/index.tsx +11 -52
- package/src/action/knowledge-bases.ts +91 -61
- package/src/api.ts +19 -1
- package/src/constants.ts +4 -0
- package/src/content-fields/flow-knowledge-base.tsx +23 -0
- package/src/content-fields/flow-whatsapp-cta-url-button.tsx +1 -2
- package/src/content-fields/hubtype-fields/common.ts +1 -0
- package/src/content-fields/hubtype-fields/index.ts +2 -0
- package/src/content-fields/hubtype-fields/knowledge-base.ts +9 -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/index.ts +10 -1
- package/src/index.ts +10 -18
- package/src/types.ts +14 -8
- package/src/user-input/intent.ts +1 -0
- package/src/user-input/keyword.ts +1 -0
- package/src/user-input/smart-intent.ts +1 -0
|
@@ -1,79 +1,108 @@
|
|
|
1
|
-
|
|
1
|
+
import { INPUT } from '@botonic/core'
|
|
2
2
|
import { ActionRequest } from '@botonic/react'
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { FlowBuilderApi } from '../api'
|
|
6
|
-
import {
|
|
7
|
-
HtNodeWithContent,
|
|
8
|
-
HtNodeWithContentType,
|
|
9
|
-
HtTextNode,
|
|
10
|
-
} from '../content-fields/hubtype-fields'
|
|
11
|
-
import { getFlowBuilderPlugin } from '../helpers'
|
|
3
|
+
|
|
4
|
+
import { FlowContent, FlowKnowledgeBase } from '../content-fields'
|
|
12
5
|
import { EventAction, KnowledgebaseFailReason, trackEvent } from '../tracking'
|
|
13
|
-
import { KnowledgeBaseResponse } from '../types'
|
|
6
|
+
import { KnowledgeBaseFunction, KnowledgeBaseResponse } from '../types'
|
|
7
|
+
import { getContentsByFallback } from './fallback'
|
|
8
|
+
import { FlowBuilderContext } from './index'
|
|
14
9
|
|
|
15
|
-
export async function
|
|
16
|
-
cmsApi
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
10
|
+
export async function getContentsByKnowledgeBase({
|
|
11
|
+
cmsApi,
|
|
12
|
+
flowBuilderPlugin,
|
|
13
|
+
request,
|
|
14
|
+
resolvedLocale,
|
|
15
|
+
}: FlowBuilderContext): Promise<FlowContent[]> {
|
|
16
|
+
const startNodeKnowledeBaseFlow = cmsApi.getStartNodeKnowledeBaseFlow()
|
|
17
|
+
|
|
18
|
+
if (!startNodeKnowledeBaseFlow) {
|
|
19
|
+
return await getContentsByFallback({
|
|
20
|
+
cmsApi,
|
|
21
|
+
flowBuilderPlugin,
|
|
22
|
+
request,
|
|
23
|
+
resolvedLocale,
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const contents = await flowBuilderPlugin.getContentsByNode(
|
|
28
|
+
startNodeKnowledeBaseFlow,
|
|
29
|
+
resolvedLocale
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
const knowledgeBaseContent = contents.find(
|
|
33
|
+
content => content instanceof FlowKnowledgeBase
|
|
34
|
+
) as FlowKnowledgeBase
|
|
35
|
+
|
|
36
|
+
if (!knowledgeBaseContent) {
|
|
37
|
+
return contents
|
|
38
|
+
}
|
|
23
39
|
|
|
24
40
|
if (
|
|
25
41
|
flowBuilderPlugin.getKnowledgeBaseResponse &&
|
|
26
|
-
|
|
42
|
+
request.input.data &&
|
|
43
|
+
request.input.type === INPUT.TEXT
|
|
27
44
|
) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
type: HtNodeWithContentType.TEXT,
|
|
39
|
-
content: {
|
|
40
|
-
text: [
|
|
41
|
-
{
|
|
42
|
-
message: knowledgeBaseResponse.answer,
|
|
43
|
-
locale: resolvedLocale,
|
|
44
|
-
},
|
|
45
|
-
],
|
|
46
|
-
buttons_style: undefined,
|
|
47
|
-
buttons: [],
|
|
48
|
-
},
|
|
49
|
-
flow_id: 'randomUUID', // TODO: Add flow_id consequentially with HtBaseNode changes
|
|
50
|
-
id: uuid(),
|
|
51
|
-
code: 'knowledge-response',
|
|
52
|
-
meta: {
|
|
53
|
-
x: 0,
|
|
54
|
-
y: 0,
|
|
55
|
-
},
|
|
56
|
-
follow_up: knowledgeBaseConfig.followup,
|
|
57
|
-
}
|
|
58
|
-
return knowledgeBaseNode
|
|
59
|
-
}
|
|
60
|
-
} catch (e) {
|
|
61
|
-
console.error('Hubtype knowledge base api error: ', { e })
|
|
45
|
+
const contentsWithKnowledgeResponse =
|
|
46
|
+
await getContentsWithKnowledgeResponse(
|
|
47
|
+
flowBuilderPlugin.getKnowledgeBaseResponse,
|
|
48
|
+
request,
|
|
49
|
+
knowledgeBaseContent,
|
|
50
|
+
contents
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
if (contentsWithKnowledgeResponse) {
|
|
54
|
+
return contentsWithKnowledgeResponse
|
|
62
55
|
}
|
|
63
56
|
}
|
|
64
|
-
|
|
57
|
+
|
|
58
|
+
return await getContentsByFallback({
|
|
59
|
+
cmsApi,
|
|
60
|
+
flowBuilderPlugin,
|
|
61
|
+
request,
|
|
62
|
+
resolvedLocale,
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async function getContentsWithKnowledgeResponse(
|
|
67
|
+
getKnowledgeBaseResponse: KnowledgeBaseFunction,
|
|
68
|
+
request: ActionRequest,
|
|
69
|
+
knowledgeBaseContent: FlowKnowledgeBase,
|
|
70
|
+
contents: FlowContent[]
|
|
71
|
+
): Promise<FlowContent[] | undefined> {
|
|
72
|
+
const knowledgeBaseResponse = await getKnowledgeBaseResponse(
|
|
73
|
+
request,
|
|
74
|
+
request.input.data!,
|
|
75
|
+
knowledgeBaseContent.sources
|
|
76
|
+
)
|
|
77
|
+
await trackKnowledgeBase(knowledgeBaseResponse, request)
|
|
78
|
+
|
|
79
|
+
if (
|
|
80
|
+
!knowledgeBaseResponse.hasKnowledge ||
|
|
81
|
+
!knowledgeBaseResponse.isFaithuful
|
|
82
|
+
) {
|
|
83
|
+
return undefined
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return updateContentsWithAnswer(contents, knowledgeBaseResponse.answer)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function updateContentsWithAnswer(
|
|
90
|
+
contents: FlowContent[],
|
|
91
|
+
answer: string
|
|
92
|
+
): FlowContent[] {
|
|
93
|
+
return contents.map(content => {
|
|
94
|
+
if (content instanceof FlowKnowledgeBase) {
|
|
95
|
+
content.text = answer
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return content
|
|
99
|
+
})
|
|
65
100
|
}
|
|
66
101
|
|
|
67
102
|
async function trackKnowledgeBase(
|
|
68
103
|
response: KnowledgeBaseResponse,
|
|
69
104
|
request: ActionRequest
|
|
70
105
|
) {
|
|
71
|
-
/* TODO:
|
|
72
|
-
In order to have all these parameters in the base knowlege response
|
|
73
|
-
it is necessary to use the new endpoint to which the knowledge sources
|
|
74
|
-
have to be indicated. For now this will not work, we need to finish
|
|
75
|
-
the knowldege base node in the flow builder frontend.
|
|
76
|
-
*/
|
|
77
106
|
const knowledgebaseInferenceId = response.inferenceId
|
|
78
107
|
const knowledgebaseSourcesIds = response.sources.map(
|
|
79
108
|
source => source.knowledgeSourceId
|
|
@@ -97,5 +126,6 @@ async function trackKnowledgeBase(
|
|
|
97
126
|
knowledgebaseSourcesIds,
|
|
98
127
|
knowledgebaseChunksIds,
|
|
99
128
|
knowledgebaseMessageId,
|
|
129
|
+
userInput: request.input.data,
|
|
100
130
|
})
|
|
101
131
|
}
|
package/src/api.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { Input, PluginPreRequest } from '@botonic/core'
|
|
2
2
|
import axios from 'axios'
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
BOT_ACTION_PAYLOAD_PREFIX,
|
|
6
|
+
KNOWLEDGE_BASE_FLOW_NAME,
|
|
7
|
+
SEPARATOR,
|
|
8
|
+
} from './constants'
|
|
5
9
|
import {
|
|
6
10
|
HtBotActionNode,
|
|
7
11
|
HtFallbackNode,
|
|
@@ -204,6 +208,20 @@ export class FlowBuilderApi {
|
|
|
204
208
|
return flow ? flow.name : ''
|
|
205
209
|
}
|
|
206
210
|
|
|
211
|
+
getStartNodeKnowledeBaseFlow(): HtNodeWithContent | undefined {
|
|
212
|
+
const knowledgeBaseFlow = this.flow.flows.find(
|
|
213
|
+
flow => flow.name === KNOWLEDGE_BASE_FLOW_NAME
|
|
214
|
+
)
|
|
215
|
+
if (!knowledgeBaseFlow) {
|
|
216
|
+
return undefined
|
|
217
|
+
}
|
|
218
|
+
return this.getNodeById<HtNodeWithContent>(knowledgeBaseFlow.start_node_id)
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
isKnowledgeBaseEnabled(): boolean {
|
|
222
|
+
return this.flow.is_knowledge_base_active || false
|
|
223
|
+
}
|
|
224
|
+
|
|
207
225
|
getResolvedLocale(locale: string): string {
|
|
208
226
|
if (this.flow.locales.find(flowLocale => flowLocale === locale)) {
|
|
209
227
|
return locale
|
package/src/constants.ts
CHANGED
|
@@ -6,3 +6,7 @@ export const BOT_ACTION_PAYLOAD_PREFIX = `ba${SEPARATOR}`
|
|
|
6
6
|
export const VARIABLE_PATTERN = /{([^}]+)}/g
|
|
7
7
|
export const ACCESS_TOKEN_VARIABLE_KEY = '_access_token'
|
|
8
8
|
export const REG_EXP_PATTERN = /^\/(.*)\/([gimyus]*)$/
|
|
9
|
+
|
|
10
|
+
export const MAIN_FLOW_NAME = 'Main'
|
|
11
|
+
export const KNOWLEDGE_BASE_FLOW_NAME = 'Knowledge base'
|
|
12
|
+
export const FALLBACK_FLOW_NAME = 'Fallback'
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Text } from '@botonic/react'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
|
|
4
|
+
import { ContentFieldsBase } from './content-fields-base'
|
|
5
|
+
import { HtKnowledgeBaseNode } from './hubtype-fields'
|
|
6
|
+
|
|
7
|
+
export class FlowKnowledgeBase extends ContentFieldsBase {
|
|
8
|
+
public code = ''
|
|
9
|
+
public sources: string[] = []
|
|
10
|
+
public text = ''
|
|
11
|
+
|
|
12
|
+
static fromHubtypeCMS(component: HtKnowledgeBaseNode): FlowKnowledgeBase {
|
|
13
|
+
const newKnowledgeBase = new FlowKnowledgeBase(component.id)
|
|
14
|
+
newKnowledgeBase.code = component.code
|
|
15
|
+
newKnowledgeBase.sources = component.content.sources
|
|
16
|
+
|
|
17
|
+
return newKnowledgeBase
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
toBotonic(id: string): JSX.Element {
|
|
21
|
+
return <Text key={id}>{this.text}</Text>
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -4,8 +4,7 @@ import React from 'react'
|
|
|
4
4
|
import { FlowBuilderApi } from '../api'
|
|
5
5
|
import { ContentFieldsBase } from './content-fields-base'
|
|
6
6
|
import { FlowButton } from './flow-button'
|
|
7
|
-
import { HtUrlNode } from './hubtype-fields'
|
|
8
|
-
import { HtWhatsappCTAUrlButtonNode } from './hubtype-fields/whatsapp-cta-url-button'
|
|
7
|
+
import { HtUrlNode, HtWhatsappCTAUrlButtonNode } from './hubtype-fields'
|
|
9
8
|
|
|
10
9
|
export class FlowWhatsappCtaUrlButtonNode extends ContentFieldsBase {
|
|
11
10
|
public code = ''
|
|
@@ -9,6 +9,7 @@ export * from './handoff'
|
|
|
9
9
|
export * from './image'
|
|
10
10
|
export * from './intent'
|
|
11
11
|
export * from './keyword'
|
|
12
|
+
export * from './knowledge-base'
|
|
12
13
|
export * from './node-types'
|
|
13
14
|
export * from './nodes'
|
|
14
15
|
export * from './payload'
|
|
@@ -17,3 +18,4 @@ export * from './text'
|
|
|
17
18
|
export * from './url'
|
|
18
19
|
export * from './video'
|
|
19
20
|
export * from './whatsapp-button-list'
|
|
21
|
+
export * from './whatsapp-cta-url-button'
|
|
@@ -7,6 +7,7 @@ import { HtHandoffNode } from './handoff'
|
|
|
7
7
|
import { HtImageNode } from './image'
|
|
8
8
|
import { HtIntentNode } from './intent'
|
|
9
9
|
import { HtKeywordNode } from './keyword'
|
|
10
|
+
import { HtKnowledgeBaseNode } from './knowledge-base'
|
|
10
11
|
import { HtPayloadNode } from './payload'
|
|
11
12
|
import { HtSmartIntentNode } from './smart-intent'
|
|
12
13
|
import { HtTextNode } from './text'
|
|
@@ -28,6 +29,7 @@ export type HtNodeWithContent =
|
|
|
28
29
|
| HtWhatsappButtonListNode
|
|
29
30
|
| HtWhatsappCTAUrlButtonNode
|
|
30
31
|
| HtSmartIntentNode
|
|
32
|
+
| HtKnowledgeBaseNode
|
|
31
33
|
|
|
32
34
|
export type HtNodeWithoutContent =
|
|
33
35
|
| HtUrlNode
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { FlowCarousel } from './flow-carousel'
|
|
2
2
|
import { FlowHandoff } from './flow-handoff'
|
|
3
3
|
import { FlowImage } from './flow-image'
|
|
4
|
+
import { FlowKnowledgeBase } from './flow-knowledge-base'
|
|
4
5
|
import { FlowText } from './flow-text'
|
|
5
6
|
import { FlowVideo } from './flow-video'
|
|
6
7
|
import { FlowWhatsappCtaUrlButtonNode } from './flow-whatsapp-cta-url-button'
|
|
@@ -9,7 +10,14 @@ import { FlowWhatsappButtonList } from './whatsapp-button-list/flow-whatsapp-but
|
|
|
9
10
|
export { ContentFieldsBase } from './content-fields-base'
|
|
10
11
|
export { FlowButton } from './flow-button'
|
|
11
12
|
export { FlowElement } from './flow-element'
|
|
12
|
-
export {
|
|
13
|
+
export {
|
|
14
|
+
FlowCarousel,
|
|
15
|
+
FlowImage,
|
|
16
|
+
FlowKnowledgeBase,
|
|
17
|
+
FlowText,
|
|
18
|
+
FlowVideo,
|
|
19
|
+
FlowWhatsappButtonList,
|
|
20
|
+
}
|
|
13
21
|
export { FlowHandoff } from './flow-handoff'
|
|
14
22
|
export { FlowWhatsappCtaUrlButtonNode } from './flow-whatsapp-cta-url-button'
|
|
15
23
|
|
|
@@ -21,3 +29,4 @@ export type FlowContent =
|
|
|
21
29
|
| FlowWhatsappButtonList
|
|
22
30
|
| FlowWhatsappCtaUrlButtonNode
|
|
23
31
|
| FlowHandoff
|
|
32
|
+
| FlowKnowledgeBase
|
package/src/index.ts
CHANGED
|
@@ -14,11 +14,12 @@ import {
|
|
|
14
14
|
FlowContent,
|
|
15
15
|
FlowHandoff,
|
|
16
16
|
FlowImage,
|
|
17
|
+
FlowKnowledgeBase,
|
|
17
18
|
FlowText,
|
|
18
19
|
FlowVideo,
|
|
19
20
|
FlowWhatsappButtonList,
|
|
21
|
+
FlowWhatsappCtaUrlButtonNode,
|
|
20
22
|
} from './content-fields'
|
|
21
|
-
import { FlowWhatsappCtaUrlButtonNode } from './content-fields/flow-whatsapp-cta-url-button'
|
|
22
23
|
import {
|
|
23
24
|
HtBotActionNode,
|
|
24
25
|
HtFlowBuilderData,
|
|
@@ -30,12 +31,12 @@ import {
|
|
|
30
31
|
HtNodeWithContentType,
|
|
31
32
|
} from './content-fields/hubtype-fields'
|
|
32
33
|
import { DEFAULT_FUNCTIONS } from './functions'
|
|
33
|
-
import { trackFlowContent } from './tracking'
|
|
34
34
|
import {
|
|
35
35
|
BotonicPluginFlowBuilderOptions,
|
|
36
36
|
FlowBuilderJSONVersion,
|
|
37
|
-
|
|
37
|
+
KnowledgeBaseFunction,
|
|
38
38
|
PayloadParamsBase,
|
|
39
|
+
TrackEventFunction,
|
|
39
40
|
} from './types'
|
|
40
41
|
import { getNodeByUserInput } from './user-input'
|
|
41
42
|
import { SmartIntentsInferenceConfig } from './user-input/smart-intent'
|
|
@@ -48,14 +49,8 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
48
49
|
private currentRequest: PluginPreRequest
|
|
49
50
|
private getAccessToken: (session: Session) => string
|
|
50
51
|
public getLocale: (session: Session) => string
|
|
51
|
-
public trackEvent?:
|
|
52
|
-
|
|
53
|
-
eventAction: string,
|
|
54
|
-
args?: Record<string, any>
|
|
55
|
-
) => Promise<void>
|
|
56
|
-
public getKnowledgeBaseResponse?: (
|
|
57
|
-
request: ActionRequest
|
|
58
|
-
) => Promise<KnowledgeBaseResponse>
|
|
52
|
+
public trackEvent?: TrackEventFunction
|
|
53
|
+
public getKnowledgeBaseResponse?: KnowledgeBaseFunction
|
|
59
54
|
public smartIntentsConfig: SmartIntentsInferenceConfig
|
|
60
55
|
|
|
61
56
|
constructor(readonly options: BotonicPluginFlowBuilderOptions) {
|
|
@@ -154,13 +149,7 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
154
149
|
const resolvedLocale = this.cmsApi.getResolvedLocale(locale)
|
|
155
150
|
const startNode = this.cmsApi.getStartNode()
|
|
156
151
|
this.currentRequest.session.flow_thread_id = uuid()
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
await trackFlowContent(
|
|
160
|
-
this.currentRequest as unknown as ActionRequest,
|
|
161
|
-
contents
|
|
162
|
-
)
|
|
163
|
-
return contents
|
|
152
|
+
return await this.getContentsByNode(startNode, resolvedLocale)
|
|
164
153
|
}
|
|
165
154
|
|
|
166
155
|
async getContentsByNode(
|
|
@@ -216,6 +205,9 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
216
205
|
)
|
|
217
206
|
case HtNodeWithContentType.HANDOFF:
|
|
218
207
|
return FlowHandoff.fromHubtypeCMS(hubtypeContent, locale, this.cmsApi)
|
|
208
|
+
|
|
209
|
+
case HtNodeWithContentType.KNOWLEDGE_BASE:
|
|
210
|
+
return FlowKnowledgeBase.fromHubtypeCMS(hubtypeContent)
|
|
219
211
|
default:
|
|
220
212
|
return undefined
|
|
221
213
|
}
|
package/src/types.ts
CHANGED
|
@@ -10,17 +10,23 @@ export interface BotonicPluginFlowBuilderOptions {
|
|
|
10
10
|
customFunctions?: Record<any, any>
|
|
11
11
|
getLocale: (session: Session) => string
|
|
12
12
|
getAccessToken: () => string
|
|
13
|
-
trackEvent?:
|
|
14
|
-
|
|
15
|
-
eventAction: string,
|
|
16
|
-
args?: Record<string, any>
|
|
17
|
-
) => Promise<void>
|
|
18
|
-
getKnowledgeBaseResponse?: (
|
|
19
|
-
request: ActionRequest
|
|
20
|
-
) => Promise<KnowledgeBaseResponse>
|
|
13
|
+
trackEvent?: TrackEventFunction
|
|
14
|
+
getKnowledgeBaseResponse?: KnowledgeBaseFunction
|
|
21
15
|
smartIntentsConfig?: { numSmartIntentsToUse: number }
|
|
22
16
|
}
|
|
23
17
|
|
|
18
|
+
export type TrackEventFunction = (
|
|
19
|
+
request: ActionRequest,
|
|
20
|
+
eventAction: string,
|
|
21
|
+
args?: Record<string, any>
|
|
22
|
+
) => Promise<void>
|
|
23
|
+
|
|
24
|
+
export type KnowledgeBaseFunction = (
|
|
25
|
+
request: ActionRequest,
|
|
26
|
+
userInput: string,
|
|
27
|
+
sources: string[]
|
|
28
|
+
) => Promise<KnowledgeBaseResponse>
|
|
29
|
+
|
|
24
30
|
export interface FlowBuilderApiOptions {
|
|
25
31
|
url: string
|
|
26
32
|
flow?: HtFlowBuilderData
|
package/src/user-input/intent.ts
CHANGED
|
@@ -31,6 +31,7 @@ async function trackIntentEvent(
|
|
|
31
31
|
nluIntentConfidence: request.input.confidence,
|
|
32
32
|
nluIntentThreshold: intentNode?.content.confidence,
|
|
33
33
|
nluIntentMessageId: request.input.message_id,
|
|
34
|
+
userInput: request.input.data,
|
|
34
35
|
}
|
|
35
36
|
await trackEvent(request, EventAction.Intent, eventArgs)
|
|
36
37
|
}
|
|
@@ -91,6 +91,7 @@ export class KeywordMatcher {
|
|
|
91
91
|
nluKeywordName: this.matchedKeyword,
|
|
92
92
|
nluKeywordIsRegex: this.isRegExp,
|
|
93
93
|
nluKeywordMessageId: this.request.input.message_id,
|
|
94
|
+
userInput: this.request.input.data,
|
|
94
95
|
}
|
|
95
96
|
await trackEvent(this.request, EventAction.Keyword, eventArgs)
|
|
96
97
|
}
|
|
@@ -48,6 +48,7 @@ export class SmartIntentsApi {
|
|
|
48
48
|
nluIntentSmartTitle: response.data.smart_intent_title,
|
|
49
49
|
nluIntentSmartNumUsed: response.data.smart_intents_used.length,
|
|
50
50
|
nluIntentSmartMessageId: this.currentRequest.input.message_id,
|
|
51
|
+
userInput: this.currentRequest.input.data,
|
|
51
52
|
})
|
|
52
53
|
return smartIntentNode
|
|
53
54
|
}
|