Skip to content

Commit 9a863cd

Browse files
committed
refactor: create new file for getNextPayloadByUserInput and export all from user-input/index file
1 parent c78efa1 commit 9a863cd

2 files changed

Lines changed: 66 additions & 64 deletions

File tree

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import type { ActionRequest } from '@botonic/react'
2+
3+
import type { FlowBuilderApi } from '../api'
4+
import {
5+
getTextOrTranscript,
6+
isKeywordsAllowed,
7+
isSmartIntentsAllowed,
8+
} from '../utils/input'
9+
import { CaptureUserInputApi } from './capture-user-input-api'
10+
import { KeywordMatcher } from './keyword'
11+
import {
12+
SmartIntentsApi,
13+
type SmartIntentsInferenceConfig,
14+
} from './smart-intent'
15+
16+
export async function getNextPayloadByUserInput(
17+
cmsApi: FlowBuilderApi,
18+
locale: string,
19+
request: ActionRequest,
20+
smartIntentsConfig: SmartIntentsInferenceConfig
21+
): Promise<string | undefined> {
22+
const userTextOrTranscript = getTextOrTranscript(request.input)
23+
if (userTextOrTranscript) {
24+
if (cmsApi.shouldCaptureUserInput()) {
25+
const captureUserInputApi = new CaptureUserInputApi(
26+
cmsApi,
27+
request,
28+
userTextOrTranscript
29+
)
30+
return await captureUserInputApi.getNextNodeId()
31+
}
32+
33+
if (isKeywordsAllowed(request)) {
34+
const keywordMatcher = new KeywordMatcher({
35+
cmsApi,
36+
locale,
37+
request,
38+
userTextOrTranscript,
39+
})
40+
const keywordNode = await keywordMatcher.getNodeByInput()
41+
if (keywordNode) {
42+
return cmsApi.getPayload(keywordNode.target)
43+
}
44+
}
45+
46+
if (isSmartIntentsAllowed(request)) {
47+
const smartIntentsApi = new SmartIntentsApi(
48+
cmsApi,
49+
request,
50+
smartIntentsConfig,
51+
userTextOrTranscript
52+
)
53+
const smartIntentNode = await smartIntentsApi.getNodeByInput()
54+
if (smartIntentNode) {
55+
return cmsApi.getPayload(smartIntentNode.target)
56+
}
57+
}
58+
}
59+
60+
return undefined
61+
}
Lines changed: 5 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,5 @@
1-
import type { ActionRequest } from '@botonic/react'
2-
3-
import type { FlowBuilderApi } from '../api'
4-
import {
5-
getTextOrTranscript,
6-
isKeywordsAllowed,
7-
isSmartIntentsAllowed,
8-
} from '../utils/input'
9-
import { CaptureUserInputApi } from './capture-user-input-api'
10-
import { KeywordMatcher } from './keyword'
11-
import { LanguageDetectionApi } from './language-detection-api'
12-
import {
13-
SmartIntentsApi,
14-
type SmartIntentsInferenceConfig,
15-
} from './smart-intent'
16-
17-
export async function getNextPayloadByUserInput(
18-
cmsApi: FlowBuilderApi,
19-
locale: string,
20-
request: ActionRequest,
21-
smartIntentsConfig: SmartIntentsInferenceConfig
22-
): Promise<string | undefined> {
23-
const userTextOrTranscript = getTextOrTranscript(request.input)
24-
if (userTextOrTranscript) {
25-
if (cmsApi.shouldCaptureUserInput()) {
26-
const captureUserInputApi = new CaptureUserInputApi(
27-
cmsApi,
28-
request,
29-
userTextOrTranscript
30-
)
31-
return await captureUserInputApi.getNextNodeId()
32-
}
33-
34-
if (isKeywordsAllowed(request)) {
35-
const keywordMatcher = new KeywordMatcher({
36-
cmsApi,
37-
locale,
38-
request,
39-
userTextOrTranscript,
40-
})
41-
const keywordNode = await keywordMatcher.getNodeByInput()
42-
if (keywordNode) {
43-
return cmsApi.getPayload(keywordNode.target)
44-
}
45-
}
46-
47-
if (isSmartIntentsAllowed(request)) {
48-
const smartIntentsApi = new SmartIntentsApi(
49-
cmsApi,
50-
request,
51-
smartIntentsConfig,
52-
userTextOrTranscript
53-
)
54-
const smartIntentNode = await smartIntentsApi.getNodeByInput()
55-
if (smartIntentNode) {
56-
return cmsApi.getPayload(smartIntentNode.target)
57-
}
58-
}
59-
}
60-
61-
return undefined
62-
}
63-
64-
export { LanguageDetectionApi }
1+
export * from './capture-user-input-api'
2+
export * from './get-next-payload-by-user-input'
3+
export * from './keyword'
4+
export * from './language-detection-api'
5+
export * from './smart-intent'

0 commit comments

Comments
 (0)