|
1 | | -import ChatBot, { Flow } from "react-chatbotify"; |
2 | | - |
3 | | -import RcbPlugin from "./factory/RcbPluginFactory"; |
4 | | -import { InputValidatorBlock } from "./types/InputValidatorBlock"; |
5 | | -import { validateFile } from "./utils/validateFile"; |
6 | | - |
7 | | -const App = () => { |
8 | | - // Initialize the plugin |
9 | | - const plugins = [RcbPlugin()]; |
10 | | - |
11 | | - // Example flow for testing |
12 | | - const flow: Flow = { |
13 | | - start: { |
14 | | - message: "Hey there! Please enter your age.", |
15 | | - path: "age_validation", |
16 | | - validateTextInput: (userInput?: string) => { |
17 | | - if (userInput && !Number.isNaN(Number(userInput))) { |
18 | | - return { success: true }; |
19 | | - } |
20 | | - return { |
21 | | - success: false, |
22 | | - promptContent: "Age must be a number!", |
23 | | - promptDuration: 3000, |
24 | | - promptType: "error", |
25 | | - highlightTextArea: true, |
26 | | - }; |
27 | | - }, |
28 | | - } as InputValidatorBlock, |
29 | | - |
30 | | - age_validation: { |
31 | | - message: |
32 | | - "Great! Now please upload a profile picture (JPEG or PNG) or provide a URL.", |
33 | | - path: "file_upload_validation", |
34 | | - chatDisabled: true, // Text input is disabled |
35 | | - validateFileInput: (file?: File) => { |
36 | | - return validateFile(file); // Validation is handled here |
37 | | - }, |
38 | | - file: async ({ files }) => { |
39 | | - console.log("Files received:", files); |
40 | | - |
41 | | - if (files && files[0]) { |
42 | | - console.log("File uploaded successfully:", files[0]); |
43 | | - } else { |
44 | | - console.error("No file provided."); |
45 | | - } |
46 | | - }, |
47 | | - } as InputValidatorBlock, |
48 | | - |
49 | | - |
50 | | - file_upload_validation: { |
51 | | - message: |
52 | | - "Thank you! Your input has been received. You passed the validation!", |
53 | | - path: "start", |
54 | | - }, |
55 | | - }; |
56 | | - |
57 | | - return ( |
58 | | - <ChatBot id="chatbot-id" plugins={plugins} flow={flow}></ChatBot> |
59 | | - ); |
60 | | -}; |
61 | | - |
62 | | -export default App; |
| 1 | +import ChatBot, { Flow } from 'react-chatbotify'; |
| 2 | + |
| 3 | +import RcbPlugin from './factory/RcbPluginFactory'; |
| 4 | +import { InputValidatorBlock } from './types/InputValidatorBlock'; |
| 5 | +import { validateFile } from './utils/validateFile'; |
| 6 | + |
| 7 | +const App = () => { |
| 8 | + // Initialize the plugin |
| 9 | + const plugins = [RcbPlugin()]; |
| 10 | + |
| 11 | + // Example flow for testing |
| 12 | + const flow: Flow = { |
| 13 | + start: { |
| 14 | + message: 'Hey there! Please enter your age.', |
| 15 | + path: 'age_validation', |
| 16 | + validateTextInput: (userInput?: string) => { |
| 17 | + if (userInput && !Number.isNaN(Number(userInput))) { |
| 18 | + return { success: true }; |
| 19 | + } |
| 20 | + return { |
| 21 | + success: false, |
| 22 | + promptContent: 'Age must be a number!', |
| 23 | + promptDuration: 3000, |
| 24 | + promptType: 'error', |
| 25 | + highlightTextArea: true, |
| 26 | + }; |
| 27 | + }, |
| 28 | + } as InputValidatorBlock, |
| 29 | + |
| 30 | + age_validation: { |
| 31 | + message: 'Great! Now please upload a profile picture (JPEG or PNG) or provide a URL.', |
| 32 | + path: 'file_upload_validation', |
| 33 | + chatDisabled: true, // Text input is disabled |
| 34 | + validateFileInput: (file?: File) => { |
| 35 | + return validateFile(file); // Validation is handled here |
| 36 | + }, |
| 37 | + file: async ({ files }) => { |
| 38 | + console.log('Files received:', files); |
| 39 | + |
| 40 | + if (files && files[0]) { |
| 41 | + console.log('File uploaded successfully:', files[0]); |
| 42 | + } else { |
| 43 | + console.error('No file provided.'); |
| 44 | + } |
| 45 | + }, |
| 46 | + } as InputValidatorBlock, |
| 47 | + |
| 48 | + file_upload_validation: { |
| 49 | + message: 'Thank you! Your input has been received. You passed the validation!', |
| 50 | + path: 'start', |
| 51 | + }, |
| 52 | + }; |
| 53 | + |
| 54 | + return <ChatBot id="chatbot-id" plugins={plugins} flow={flow}></ChatBot>; |
| 55 | +}; |
| 56 | + |
| 57 | +export default App; |
0 commit comments