0.0.57 • Published 6 years ago
chat-form v0.0.57
Chat Form
chat-form is a react based chat-bot like form that allows a dev user to customize the message response to a user on every entry and even add validation reply message with Typescript support.
Why?
I needed to use in some of my projects.
Installation
npm install chat-formor
yarn add chat-formUsage
Import the component
Javascript
import ChatBot from 'chat-form/dist/js/export';or lazy load
import React, { lazy, Suspense } from 'react';
const ChatBot = lazy(() => import('chat-form/dist/js/export'));Typescript
import ChatBot from 'chat-form';or lazy load
import React, { lazy, Suspense } from 'react';
const ChatBot = lazy(() => import('chat-form'));Example
import ChatBot from 'chat-form';
const Component = (props) => {
const [questions, setQuestions] = React.useState([
{
question: () => 'First Question',
answerType: 'input',
identifier: 'name',
validator: {
message: (value) => `Your name length should range between 5 - 26 characters`,
validatorCallback: (value) => value.length > 4 && value.length < 27,
},
},
]);
return (
<ChatBot
lastMessage={'Last message after all the questions have been answered'}
onAnswer={setQuestions}
questions={questions}
/>
);
}Interfaces
####Validator
interface ValidatorObject {
message: (value: any) => string; // value argument is the user input value
validatorCallback: (value: any) => boolean;
}Question
interface Question {
question: (value: any) => string;
answerType: 'paragraph' | 'input' | 'boolean' | 'select' | 'file' | 'number' | 'csv' | any;
identifier: string; // identifier is the key of response values
options?: string[]; // only if answerType is select
validator?: ValidatorObject;
}Message
interface Message {
message: string;
sender: 'bot' | 'user';
time?: string;
fileSrc?: string; // Required if message is of file type
file?: File;
}Props
interface Props {
className?: string;
lastMessage: (value: any) => string; // The message after all the values have been filled. It takes in an object of { [identifier]: user input }
questions: Question[];
initialMessages?: Message[];
onAnswer: (questions: Question[], value?: any) => void; // where value is an object of { [identifier]: user input }
}Here is the full demo
0.0.57
6 years ago
0.0.56
6 years ago
0.0.55
6 years ago
0.0.53
6 years ago
0.0.50
6 years ago
0.0.49
6 years ago
0.0.47
6 years ago
0.0.48
6 years ago
0.0.46
6 years ago
0.0.37
6 years ago
0.0.36
6 years ago
0.0.35
6 years ago
0.0.34
6 years ago
0.0.33
6 years ago
0.0.32
6 years ago
0.0.31
6 years ago
0.0.30
6 years ago
0.0.29
6 years ago
0.0.28
6 years ago
0.0.27
6 years ago
0.0.26
6 years ago
0.0.25
6 years ago
0.0.24
6 years ago
0.0.23
6 years ago
0.0.22
6 years ago
0.0.21
6 years ago
0.0.20
6 years ago
0.0.19
6 years ago
0.0.18
6 years ago
0.0.17
6 years ago
0.0.16
6 years ago
0.0.15
6 years ago
0.0.14
6 years ago
0.0.13
6 years ago
0.0.12
6 years ago
0.0.11
6 years ago
0.0.1
6 years ago
0.1.0
6 years ago
