0.1.5 • Published 4 years ago

@platformbuilders/react-native-chatbot v0.1.5

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

React Native Chatbot

Build Status npm react-native MIT

A react native chatbot component to create conversation chats. Based on react-simple-chatbot.

Getting Start

yarn add react-native-chatbot @react-native-community/art --save

Usage

import ChatBot from 'react-native-chatbot';

const steps = [
  {
    id: '0',
    message: 'Welcome to react chatbot!',
    trigger: '1',
  },
  {
    id: '1',
    message: 'Bye!',
    end: true,
  },
];

<ChatBot steps={steps} />

Documentation

Properties

NameTypeDefaultDescription
avatarStylePropTypes.objectThe style object to use to override the avatar element
avatarWrapperStylePropTypes.objectThe style object to use to override the avatar surrounding element
botAvatarPropTypes.stringimgBot image source
botBubbleColorPropTypes.string#6E48AABot bubble color
botDelayPropTypes.number1000The delay time of bot messages
botFontColorPropTypes.string#fffBot font color
bubbleStylePropTypes.objectThe style object to use to override the bubble element
optionStylePropTypes.objectThe style object to use to override the option container
optionElementStylePropTypes.objectThe style object to use to override the option element
optionFontColorPropTypes.stringOption font color
optionBubbleColorPropTypes.stringOption bubble color
classNamePropTypes.stringAdd a class name to root element
contentStylePropTypes.objectThe style object to use to override the scroll element
customDelayPropTypes.number1000The delay time of custom messages
customStylePropTypes.objectThe style object to use to override the custom step element
footerStylePropTypes.objectThe style object to use to override the footer element
handleEnd({ renderedSteps, steps, values })PropTypes.funcThe callback function when chat ends
headerComponentPropTypes.elementHeader component for the chatbot
hideUserAvatarPropTypes.boolfalseIf true the user avatar will be hidden in all steps
inputStylePropTypes.objectThe style object to use to override the input element
keyboardVerticalOffsetPropTypes.numberios ? 44 : 0Vertical offset of keyboard view. Check keyboardVerticalOffset
placeholderPropTypes.stringType the message ...Chatbot input placeholder
stepsPropTypes.arrayThe chatbot steps to display
stylePropTypes.objectThe style object to use to override the submit button element
submitButtonStylePropTypes.objectThe style object to use to override the button element
submitButtonContentPropTypes.string or PropTypes.elementSENDThe string or object to use to override the button content
userAvatarPropTypes.stringimgUser image source
userBubbleStylePropTypes.stringimgThe style object to use to override the user's bubble element
userBubbleColorPropTypes.string#fffUser bubble color
userDelayPropTypes.number1000The delay time of user messages
userFontColorPropTypes.string#4a4a4aUser font color
scrollViewPropsPropTypes.object#4a4a4aUse to override scroll view props

Steps

Text Step

NameTypeRequiredDescription
idString / NumbertrueThe step id. Required for any step
messageString / FunctiontrueThe text message. If function, it will receive ({ previousValue, steps }) params
triggerString / Number / FunctionfalseThe id of next step to be triggered. If function, it will receive ({ value, steps }) params
avatarStringfalsethe avatar to be showed just in this step. Note: this step must be a step that avatar appears
delayNumberfalseset the delay time to message be shown
endBooleanfalseif true indicate that this step is the last
inputAttributesObjectSet any attributes on the input field (keyboardType, autoCapitalize, autoComplete)
metadataObjectSet of key-value pairs that you can attach to an object. This can be useful for storing additional information about the object in a structured format

Example:

{
  id: '1',
  message: 'Hello World',
  trigger: '2',
},
{
  id: '2',
  message: ({ previousValue, steps }) => 'Hello',
  end: true,
}

User Step

NameTypeRequiredDescription
idString / NumbertrueThe step id. Required for any step
userBooleantrueif true indicate that you waiting a user type action
triggerString / Number / FunctionfalseThe id of next step to be triggered. If function, it will receive ({ value, steps }) params
validatorString / Numberfalseif user attribute is true you can pass a validator function to validate the text typed by the user
endBooleanfalseif true indicate that this step is the last
inputAttributesObjectSet any attributes on the input field (keyboardType, autoCapitalize, autoComplete)
metadataObjectSet of key-value pairs that you can attach to an object. This can be useful for storing additional information about the object in a structured format

Example:

{
  id: '1',
  user: true,
  inputAttributes: {
    keyboardType: 'email-address'
  },
  end: true,
}

Options Step

NameTypeRequiredDescription
idString / NumbertrueThe step id. Required for any step
optionsArraytrueArray of options with { label, value, trigger } properties
endBooleanfalseif true indicate that this step is the last
inputAttributesObjectSet any attributes on the input field (keyboardType, autoCapitalize, autoComplete)
metadataObjectSet of key-value pairs that you can attach to an object. This can be useful for storing additional information about the object in a structured format

Example:

{
  id: '1',
  options: [
    { value: 1, label: 'Number 1', trigger: '3' },
    { value: 2, label: 'Number 2', trigger: '2' },
    { value: 3, label: 'Number 3', trigger: '2' },
  ],
}

Custom Step

NameTypeRequiredDescription
idString / NumbertrueThe step id. Required for any step
componentComponenttrueCustom React Component
replaceBooleanfalseif true indicate that component will be replaced by the next step
waitActionBooleanfalseif true indicate that you waiting some action. You must use the triggerNextStep prop in your component to execute the action
asMessageBooleanfalsef true indicate that the component will be displayed as a text step
triggerString / Number / FunctionfalseThe id of next step to be triggered. If function, it will receive ({ value, steps }) params
delayNumberfalseset the delay time to component be shown
endBooleanfalseif true indicate that this step is the last
inputAttributesObjectSet any attributes on the input field (keyboardType, autoCapitalize, autoComplete)
metadataObjectSet of key-value pairs that you can attach to an object. This can be useful for storing additional information about the object in a structured format

Example:

{
  id: '1',
  component: <CustomComponent />
  trigger: '2'
}

Update Step

NameTypeRequiredDescription
idString / NumbertrueThe step id. Required for any step
updateString / NumbertrueThe id of next step to be updated
triggerString / Number / FunctionfalseThe id of next step to be triggered. If function, it will receive ({ value, steps }) params
inputAttributesObjectSet any attributes on the input field (keyboardType, autoCapitalize, autoComplete)
metadataObjectSet of key-value pairs that you can attach to an object. This can be useful for storing additional information about the object in a structured format

Example:

{
  id: '1',
  options: [
    { value: 1, label: 'Number 1', trigger: '3' },
    { value: 2, label: 'Number 2', trigger: '2' },
    { value: 3, label: 'Number 3', trigger: '2' },
  ],
}

Custom Component

When you declare a custom step, you need indicate a custom React Component to be rendered in the chat. This custom component will receive the following properties.

NameTypeDescription
previousStepPropTypes.objectPrevious step rendered
stepPropTypes.objectCurrent step rendered
stepsPropTypes.objectAll steps rendered
triggerNextStep({ value, trigger })PropTypes.funcCallback function to trigger next step when user attribute is true. Optionally you can pass a object with value to be setted in the step and the next step to be triggered
inputAttributesObjectSet any attributes on the input field (keyboardType, autoCapitalize, autoComplete)
metadataObjectSet of key-value pairs that you can attach to an object. This can be useful for storing additional information about the object in a structured format

How to Contribute

Please check the contributing guide

Authors

Lucas Bassetti
Lucas Bassetti

See also the list of contributors who participated in this project.

Donate

If you liked this project, you can donate to support it :heart:

paypal

License

MIT · Lucas Bassetti