0.2.11 • Published 6 years ago

i-chatbot v0.2.11

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

Getting Started 🚀

Installation

npm i i-chatbot --save

Basic Usage

Import component

import ChatBot, { ChatBotUtil } from 'i-chatbot'

Create methods that will handle postback events from a chatbot. It should return an array of message objects to reply on user's action with a callback.

  getStarted () {
    return [
      ChatBotUtil.textMessage(['Hi!', 'Hey there!'].any()),
      ChatBotUtil.textMessage(['How is life?', 'What\'s up?'].any(),
        ChatBotUtil.makeReplyButton('Great!', this.intro))
    ]
  }

  intro () {
    return [
      ChatBotUtil.textMessage('That\'s good to hear!')
    ]
  }

Render ChatBot with a get started callback method and a start button.

<ChatBot onGetStarted={this.getStarted}
         getStartedButton={ChatBotUtil.makeGetStartedButton('Get Started')} />

ChatBot

Props

PropDefaultTypeDescription
onGetStarted-funcInital callback method to return first messages
getStartedButton-objectStart button parameters

Methods

startOver (message)

Resets a state of chat and adds a message object if no get started button set.

ChatBotUtil

Methods

textMessage (text, ...actions)

Create a text message object.

Parameters:

NameTypeDescription
textstringMessage text
actionsobject(s)Quick reply button(s) object

userTextMessage (text)

Create a user's text message object.

Parameters:

NameTypeDescription
textstringMessage text

makeReplyButton (title)

Create a get started button.

Parameters:

NameTypeDescription
titlestringTitle

makeReplyButton (title, postback)

Create a quick reply button.

Parameters:

NameTypeDescription
titlestringTitle
postbackstringPostback value

makeTextInputField (title, postback)

Create a text input field.

Parameters:

NameTypeDescription
sendstringTitle of the submit button
placeholderstringPlaceholder for input field
postbackstringPostback value

Style

As CSS pre-processor is used LESS. Copy and modify styles from demo/src/i-chatbot.less and then import in your app.

Built with i-chatbot 🤘

  • Personal website of Oleh Stasula
  • Landing page of Justin Case

Have you built something cool with i-chatbot? Submit a pull-request and add it to this list! 😉

To-do 🛠

  • Bottom-up chat direction
  • Better input validation
  • Avatar placeholder

Contribution 💪

Your contribution is welcomed, no matter how big or small!

Please have a look at the contribution guide for details about project structure, development environment, test suite, code style, etc. All the version updates are mentioned in the changelog.

License 🔖

The library is available as open source under the terms of the MIT License.

0.2.11

6 years ago

0.2.10

7 years ago

0.2.9

7 years ago

0.2.8

7 years ago

0.2.7

7 years ago

0.2.6

7 years ago

0.2.5

7 years ago

0.2.4

7 years ago

0.2.3

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago