1.1.1 • Published 6 years ago

react-livechat v1.1.1

Weekly downloads
8,839
License
MIT
Repository
github
Last release
6 years ago

LiveChat for React

This is a React component to easily add LiveChat widget to your application.

Getting Started

Prerequisites

To use LiveChat in your React application, you will need LiveChat license ID.

If you already have a LiveChat account, get your license_id here.

LiveChat license ID

If you don't have an account, you can create one here.

Installation

To import LiveChat for React, run the following command:

npm install react-livechat --save

User Guide

Start

Having imported LiveChat for React, put it in your render method:

import LiveChat from 'react-livechat'

...

<LiveChat license={your_license_id} />

Group

You can set up group directly in LiveChat component prop. Thanks to this, all chats will be routed to the specified group:

<LiveChat license={your_license_id} group={3} />

Here you can learn more about groups: Dividing live chat by group.

Separated chat sessions

You can separate chat sessions between groups by using chatBetweenGroups prop:

<LiveChat license={your_license_id} group={3} chatBetweenGroups={false} />

Here is an article about it.

Visitor's details

If you already know who your visitor is, you can set up his/her name and/or email:

<LiveChat license={your_license_id} visitor={{name: 'John', email: 'john@example.com'}} />

Custom variables

Custom variables are additional details that you can pass to LiveChat from the code (i.e., login or profile link). Here is how to make it:

const params = [
  { name: 'Login', value: 'joe_public' },
  { name: 'Account ID', value: 'ABCD1234' },
  { name: 'Total order value', value: '$123' }
];

<LiveChat license={your_license_id} params={params} />

Customization

You can change the look and feel of your chat widget in Settings > Chat window section.

Methods

This module uses LiveChat JS API.

Get your chat reference using onChatLoaded callback:

<LiveChat 
  onChatLoaded={ ref => this.livechat = ref }
  license={your_license_id} 
/>

You have access to all methods and variables of LiveChat JS API with your livechat reference or window.LC_API.

Example:

this.livechat.hide_chat_window();
// is the same as:
window.LC_API.hide_chat_window();

LC_Invite exception

Sometimes it can happen that LC_Invite is is still being loaded when onChatLoaded is called. To ensure that LC_Invite is loaded you can give additional check to onChatLoaded function:

onChatLoaded = (ref) => {
 ref.on_after_load = function ()  {
    //here you can use any method you want!
  }		
}

Available methods

NameNote
close_chatCloses the ongoing chat.
disable_soundsMutes all sounds in the chat window on visitor's side (not supported with the pop-up chat window).
open_chat_windowMaximizes the chat window (when using the embedded chat window) or opens the chat window (when using the pop-up window).
minimize_chat_windowMinimizes the chat window (not supported with the pop-up chat window).
hide_chat_windowHides the chat window (not supported with the pop-up chat window).
agents_are_availableReturns true if your agents are available to chat, otherwise it returns false.
chat_window_maximizedReturns true if the chat window is maximized, returns false otherwise.
chat_window_minimizedReturns true if the chat window is minimized, returns false otherwise.
chat_window_hiddenReturns true if the chat window is hidden, returns false otherwise.
visitor_queuedReturns true if the visitor is currently waiting in the queue, returns false otherwise.
chat_runningReturns true if the visitor is currently chatting with an agent, returns false otherwise.
visitor_engagedReturns true if the visitor is currently chatting, waiting in the queue or the greeting is displayed to them. Returns false otherwise.
get_window_typeReturns embedded if the chat window is embedded on the website or popup if the chat window opens in a new window.
set_custom_variablesYou can set custom variables that the LiveChat agents will see in their apps. Custom variables will be saved in the chat transcript, so you will see them in the Archives even after the chat has been finished.

Callbacks

LiveChat React component gives you the option to control chat callbacks.

Let's say that you want display a received or sent message somewhere else. You can get new messages using the code below:

<LiveChat
  ...
  onMessage={ data => console.log(data) } 
/>

Available callbacks

NameNote
onChatLoadedExecuted when LC_API object is loaded and ready to use. Returns reference to your LC_API object.
onBeforeLoadExecuted before the chat window has been rendered (not supported with the pop-up chat window).
onAfterLoadExecuted right after the chat window has been rendered (not supported with the pop-up chat window).
onChatWindowOpenedExecuted when the chat window is opened.
onChatWindowMinimizedExecuted when the chat window is minimized (not supported with the pop-up chat window).
onChatWindowHiddenExecuted when the chat window is hidden (not supported with the pop-up chat window).
onChatStateChangedExecuted when the chat state is changed. You can find more information here.
onChatStartedExecuted when the chat is started.
onChatEndedExecuted when the chat is ended.
onMessageExecuted when the message has been sent or received. You can find more information here.
onTicketCreatedExecuted when the ticket form has been filled in by the visitor. You can find more information here.
onPrechatSurveySubmittedExecuted when the pre-chat survey has been submitted by visitor.
onPostchatSurveySubmittedExecuted when the post-chat survey has been submitted by visitor.
onRatingSubmittedExecuted when the chat rating is submitted. The only argument, data, can have three values: good, bad or none.
onRatingCommentSubmittedExecuted when a chat rating comment is submitted. The only argument, data, contains the message entered by the visitor.

Support

If you need any help, you can chat with us via email or on chat.

I hope you will find this module useful. Happy coding!

1.1.1

6 years ago

1.0.29

6 years ago

1.0.28

6 years ago

1.0.27

6 years ago

1.0.26

6 years ago

1.0.25

6 years ago

1.0.24

6 years ago

1.0.23

6 years ago

1.0.22

6 years ago

1.0.21

6 years ago

1.0.20

6 years ago

1.0.19

6 years ago

1.0.18

6 years ago

1.0.17

6 years ago

1.0.16

6 years ago

1.0.15

6 years ago

1.0.14

6 years ago

1.0.13

6 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago