1.1.0 • Published 6 years ago

react-native-simple-chatbot v1.1.0

Weekly downloads
105
License
MIT
Repository
github
Last release
6 years ago

ChatBot

A Simple react-native Chat Bot.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Prerequisites

What things you need to install the software:

Download and Install: Node

Once Node is installed, run

npm install react-native

Have an up and running react-native project. See https://facebook.github.io/react-native/docs/getting-started for more information.

Installing

To install component, navigate to project root directory and run

npm install react-native-simple-chatbot

Documentation

Props

NameTypeRequiredDefaultDescription
ChatBotIDPropTypes.stringYesUnique ID for the Chat Bot.
questionsPropTypes.arrayYesArray for the Chat Bot questions.
chatHeaderPropTypes.stringYesSmall text prior to asking questions.
userIconPropTypes.objectYesUser Icon image source.
cpuIconPropTypes.objectYesCPU Icon image source.
imagesArrayPropTypes.objectYesArray of React.Component images
refPropTypes.stringNoUsed for referencing in parent react-native js file.
customComponentCallbackPropTypes.funcNoFunction to add and handle custom components.
onChatEndCallbackPropTypes.funcNoFunction to handle chat completion.
previousValuePropTypes.objectNoVariable to initialize chat.

Steps

NameTypeRequiredDescription
idstringYesUnique ID for step
messagestringNoCPU message to the user.
userbooleanYesBoolean to determine wheter user input is required.
multipleOptionsSelectbooleanNoBoolean to determine if user can select multiple options.
optionsarrayNoArray to hold options for user to select.
sliderarrayNoArray to hold options for the slider.
custombooleanNoBoolean to determine if a custom component is used.
customidstringNoUnique ID for the custom component.
triggerstringYesUnique ID for the Chat Bot to determine next step.
endbooleanYesBoolean to determine end of chat.

Options

NameTypeRequiredDescription
valuestringYesValue for choice.
triggerstringYesUnique ID for the Chat Bot to determine next step.
imageUstringNoImage id (from images.js) for unselected choice.
imageSstringNoImage id (from images.js) once user selects choice.

Slider

NameTypeRequiredDescription
valuenumberYesValue for choice.
triggerstringYesUnique ID for the Chat Bot to determine next step.
markerstringYesValue saved by ChatBot.

Usage

Within react-native js file

import ChatBot from 'react-native-simple-chatbot';
import images from '.../images/images';

const ChatFile = require('../json/chatbot.json'); // Array from json file for chatbot

customComponents(customID) {
    if (customID === 'CustomID') {
        this.refs.handleCustomReturn('Some Text'); // Method to add Text to Chat Bot
        this.refs.addCustomToChatArray(<CustomComponent />); // Method to add a custom react-native component to Chat Bot
    }
}

<ChatBot
    ref="ChatBot"
    ChatBotID="ChatBot ID"
    questions={ChatFile.chatone} 
    chatHeader={(new Date()).toDateString()}
    customComponentCallback={this.customComponents.bind(this)}
    userIcon={images.UserIcon}
    cpuIcon={images.CPUIcon}
    imagesArray={images}
/>

Within json file

{
    "chatone": [
        {
            "id": "1",
            "message": "Hello. ",
            "user": "false",
            "options": [],
            "slider": [],
            "custom": "false",
            "customid": "",
            "trigger": "2",
            "end": "false"
        },
        {
            "id": "2",
            "message": "",
            "user": "true",
            "options": [],
            "slider": [],
            "custom": "false",
            "customid": "",
            "trigger": "3",
            "end": "false"
        },
        {
            "id": "3",
            "message": "",
            "user": "true",
            "multipleOptionsSelect": "false",
            "options": [
                {"value": "Yes", "trigger": "4","imageU": "", "imageS": ""},
                {"value": "No", "trigger": "4","imageU": "", "imageS": ""}
            ],
            "slider": [],
            "custom": "false",
            "customid": "",
            "trigger": "",
            "end": "false"
        },
        {
            "id": "4",
            "message": "",
            "user": "false",
            "options": [],
            "slider": [],
            "custom": "true",
            "customid": "CustomID",
            "trigger": "5",
            "end": "false"
        },
        {
            "id": "5",
            "message": "",
            "user": "true",
            "options": [],
            "slider": [
                {"value": "1", "trigger": "6", "marker": "None"},
                {"value": "2", "trigger": "6", "marker": "Little"},
                {"value": "3", "trigger": "6", "marker": "Somewhat"},
                {"value": "4", "trigger": "6", "marker": "A bit"},
                {"value": "5", "trigger": "6", "marker": "A lot"}
            ],
            "custom": "false",
            "customid": "",
            "trigger": "",
            "end": "false"
        },
        {
            "id": "6",
            "message": "Thank you.",
            "user": "false",
            "options": [],
            "slider": [],
            "custom": "false",
            "customid": "",
            "trigger": "",
            "end": "true"
        }
    ]
}

Within images.js

const images = {
    // Image for logo
    Logo: require('../images/Logo.png'),
    // Image for ChatBot Icons
    UserIcon: require("../images/user_icon.png"),
    CPUIcon: require("../images/cpu_Logo.png"),
};

export default images;

Built With

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

  • Hamza Varvani - Initial work - HamzaKV

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments