1.0.3 • Published 3 years ago

react-chat-window-file v1.0.3

Weekly downloads
49
License
MIT
Repository
github
Last release
3 years ago

react-live-chat

react-live-chat provides an intercom-like chat window that can be included easily in any project for free. It provides no messaging facilities, only the view component.

Alt Text

Features

  • Customizeable
  • Backend agnostic
  • Free

Demo

Table of Contents

Installation

$ npm install react-chat-window

Example

import React, {Component} from 'react'
import {render} from 'react-dom'
import {Launcher} from '../../src'

class Demo extends Component {

  constructor() {
    super();
    this.state = {
      messageList: messageHistory
    };
  }

  _onMessageWasSent(message) {
    this.setState({
      messageList: [...this.state.messageList, message]
    })
  }

  _sendMessage(text) {
    if (text.length > 0) {
      this.setState({
        messageList: [...this.state.messageList, {
          author: 'them',
          type: 'text',
          data: { text }
        }]
      })
    }
  }

  render() {
    return (<div>
      <Launcher
        agentProfile={{
          teamName: 'react-live-chat',
          imageUrl: 'https://a.slack-edge.com/66f9/img/avatars-teams/ava_0001-34.png'
        }}
        onMessageWasSent={this._onMessageWasSent.bind(this)}
        messageList={this.state.messageList}
      />
    </div>)
  }
}

For more detailed examples see the demo folder.

Components

Launcher

Launcher is the only component needed to use react-live-chat. It will react dynamically to changes in messages. All new messages must be added via a change in props as shown in the example.

Launcher props:

proptypedescription
*agentProfileobjectRepresents your product or service's customer service agent. Fields: teamName, imageUrl
onMessageWasSentfunction(message)Called when a message a message is sent with a message object as an argument.
messageListmessageAn array of message objects to be rendered as a conversation.
isOpenbooleanForce the open/close state of the chat window. If this is not set, it will open and close when clicked.
handleClickFunctionIntercept the click event on the launcher
newMessagesCountNumberIf greater than 0, this number will be displayed in a badge on the launcher
onFilesSelectedFunctionCalled after file has been selected from dialogue in chat window
newMessagesCountNumberThe number of new messages. To be displayed in a badge on the launcher. 0 for no badge

Message Objects

Message objects are rendered differently depending on their type. Currently, only text, file, and emoji types are supported. Each message object has an author field which can have the value 'me' or 'them'.

{
  author: 'them',
  type: 'text',
  data: {
    text: 'some text'
  }
}

{
  author: 'me',
  type: 'emoji',
  data: {
    code: 'someCode'
  }
}


{
  author: 'me',
  type: 'file',
  data: {
    url: 'somefile.mp3',
    fileName: 'Any old name'
  }
}

Issues

waffle.io