1- import React from "react" ;
21import ChatBot , { Flow } from "react-chatbotify" ;
2+
33import RcbPlugin from "./factory/RcbPluginFactory" ;
44import { InputValidatorBlock } from "./types/InputValidatorBlock" ;
55import { validateFile } from "./utils/validateFile" ;
66
77const App = ( ) => {
8+ // initialize example plugin
89 const plugins = [ RcbPlugin ( ) ] ;
910
11+ // example flow for testing
1012 const flow : Flow = {
1113 start : {
1214 message : "Hey there! Please enter your age." ,
@@ -31,9 +33,9 @@ const App = () => {
3133 validateInput : ( userInput ?: string ) => {
3234 console . log ( "validateInput called with userInput:" , userInput ) ;
3335
34- // Allow empty input or file names with allowed extensions
36+
3537 if (
36- ! userInput ||
38+ userInput &&
3739 / \. ( j p g | j p e g | p n g ) $ / i. test ( userInput . trim ( ) )
3840 ) {
3941 return { success : true } ;
@@ -42,44 +44,46 @@ const App = () => {
4244 // Disallow other text inputs
4345 return {
4446 success : false ,
45- promptContent : "Please upload a file." ,
47+ promptContent : "Please upload a valid file (JPEG or PNG). Empty inputs are not allowed ." ,
4648 promptDuration : 3000 ,
4749 promptType : "error" ,
4850 } ;
4951 } ,
50- validateFile : ( file ?: File ) => {
52+ validateFileInput : ( file ?: File ) => {
5153 return validateFile ( file ) ; // Validate file input
5254 } ,
5355 file : async ( { files } ) => {
5456 console . log ( "Files received:" , files ) ;
55-
57+
5658 if ( files && files [ 0 ] ) {
5759 const validationResult = validateFile ( files [ 0 ] ) ;
5860 if ( ! validationResult . success ) {
5961 console . error ( validationResult . promptContent ) ;
60- return ;
62+ // Return early to prevent success
63+ return { success : false } ;
6164 }
6265 console . log ( "File uploaded successfully:" , files [ 0 ] ) ;
6366 } else {
6467 console . error ( "No file provided." ) ;
6568 }
6669 } ,
70+
6771 } as InputValidatorBlock ,
6872
6973 file_upload_validation : {
7074 message :
71- "Thank you! Your profile picture has been uploaded successfully." ,
72- path : "end " ,
75+ "Thank you! Your picture has been uploaded successfully. You passed the file upload validation! " ,
76+ path : "start " ,
7377 } ,
78+ }
7479
75- end : {
76- message : "This is the end of the flow. Thank you!" ,
77- } ,
78- } ;
79-
80-
81-
82- return < ChatBot id = "chatbot-id" plugins = { plugins } flow = { flow } /> ;
83- } ;
80+ return (
81+ < ChatBot
82+ id = "chatbot-id"
83+ plugins = { plugins }
84+ flow = { flow }
85+ > </ ChatBot >
86+ ) ;
87+ }
8488
8589export default App ;
0 commit comments