|
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