0.1.25 • Published 4 years ago

react-native-chatflow v0.1.25

Weekly downloads
1
License
ISC
Repository
github
Last release
4 years ago

ReactNative Chat Flow

ReactNative component that helps you to quickly and easily build interactive chat applications.

Installation

npm install --save react-native-chatflow

Note: this package requires react-native-linear-gradient. It is part of the dependencies of the package so will be automatically installed, but note that you will need to run the following command to link it as it is a native module:

react-native link react-native-linear-gradient

Basic Usage

It's really easy to get started. Put the following code in one of your components...

import ChatFlow from "react-native-chatflow";
import chatScript from "./chatScript.json";

<ChatFlow 
    chatScript={chatScript}
    backgroundColor={Styles.colours.lightBackground}

Then you need to include a chat script (in the example above, chatScript.json), which defines what the chat flow will be. An example is shown below:

{
    "_start": "hello",
    "hello": {
        "text": "Hello I'm an example bot 👋🏼",
        "next": "getName"
    },
    "getName": {
        "text": "First up, what's your name?",
        "input": "text",
        "placeholder": "Enter your name",
        "field": "name",
        "next": "favouriteEmoji"
    },
    "favouriteEmoji": {
        "text": "What food do you want?",
        "field": "food",
        "options": [
            {"value": "small", "text": "🥕"},
            {"value": "medium", "text": "🍕"},
            {"value": "big", "text": "🐔"}
        ]
    }
}

Properties/Options

NameDescription
chatScriptThe chat script JSON object
imagesMap of static images to use in chats
backgroundColorBackground color of the chat holder
userBubbleStyleObject with styles for the user bubble
userBubbleTextStyleObject with styles for the user bubble text
botBubbleTextStyleObject with styles for the bot bubble
bubbleOptionStyleObject with styles for the option bubble
bubbleOptionTextStyleObject with styles for the option bubble text (the options shown at the bottom of the screen)
textInputStyleText styles for the text input box
hiddenIf set to true, the chat component will be hidden
onRenderComponentMethod that renders custom components (see below)
onChangeAnswersEvent fired when the user answers a question or clicks an option
onChangeField(field, value)Event fired when a user changes a field
onChatHistoryChangeEvent fired when the chat history changes (i.e. when the user or bot speaks)
getChatHistoryMethod that returns the chat history

Loading existing chat history

If you need to load chat history, create a ref on your component and then call chatFlow.loadChatHistory(chats)

0.1.25

4 years ago

0.1.20

4 years ago

0.1.21

4 years ago

0.1.22

4 years ago

0.1.23

4 years ago

0.1.24

4 years ago

0.1.18

4 years ago

0.1.19

4 years ago

0.1.17

4 years ago

0.1.16

4 years ago

0.1.14

4 years ago

0.1.15

4 years ago

0.1.13

4 years ago

0.1.12

7 years ago

0.1.10

7 years ago

0.1.9

7 years ago

0.1.8

7 years ago

0.1.7

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago