README
react-messenger-chat-plugin :speech_balloon:
Table of contents
Installation
First, whitelist your domain to be eligible to use the messenger chat in facebooks page settings:
Facebook page > Settings > Messaging (in sidebar) > Add messenger to your website > Whitelist domain
:warning: NOTE: Facebook doesn't allow whitelisting localhost, so for dev-mode use a wrapper like ngrok.
npm
npm install react-messenger-chat-plugin
yarn
yarn add react-messenger-chat-plugin
Usage
MessengerChat Component
import React from 'react';
import ReactDOM from 'react-dom';
import { MessengerChat } from 'react-messenger-chat-plugin';
ReactDOM.render(
<MessengerChat
pageId='123456789101112'
language='en_US'
themeColor={'#F2F3G2'}
height={24}
loggedInGreeting='Hello logged in user!'
loggedOutGreeting='Hello stranger!'
autoExpand={true}
debugMode={false}
onMessengerShow={() => {console.log('onMessengerShow')}}
onMessengerHide={() => {console.log('onMessengerHide')}}
onMessengerDialogShow={() => {console.log('onMessengerDialogShow')}}
onMessengerDialogHide={() => {console.log('onMessengerDialogHide')}}
/>;
document.getElementById('demo')
);
Attribute | Description |
---|---|
pageId (string) Required | Id of page which can be found on the facebook page |
language (string) | Language locale, e.g. 'en_US' for english or 'sv_SE' for swedish |
themeColor (string) | Hexcode color of the theme color |
height (integer) | Pixel height from bottom of the page |
autoExpand (bool) | Smart autoexpanding feature which expands the dialog for each new session. NOTE: Will not expand on refresh or back/forward-load, but will remember UI state |
loggedInGreeting (string) | Greeting message displayed if user is logged in |
loggedOutGreeting (string) | Greeting message displayed if user is logged out |
ref (string) | Addittional context to be passed in requests |
onMessengerMounted (function) | Callback which is called when the messenger chat is mounted |
onMessengerLoad (function) | Callback which is called on load |
onMessengerShow (function) | Callback which is called when the component is shown. |
onMessengerHide (function) | Callback which is called when the component is hidden |
onMessengerDialogShow (function) | Callback which is called each time the dialog is expanded |
onMessengerDialogHide (function) | Callback which is called each time the dialog is hidden |
debugMode (bool) | Enables debug mode which console.logs every event in the component |
version | Version of the messenger chat |
:warning: NOTE: some attributes can be controlled from your facebook page messenger chat plugin configurations. These are by default overriden by the props, so if you want more control from facebook -> populate less props.
MessengerChat Control Functions
This package also supports control functions for the messenger chat which can be accessed globally. The control functions will only work after the messenger chat has succesfully mounted.
import { MessengerChat, showMessenger, hideMessenger, showDialog, hideDialog, setMessengerHeight } from 'react-messenger-customer-chat';
function App() {
return (
<div className="App">
<button onClick={() => {showMessenger(true)}}>show messenger</button>
<button onClick={() => {hideMessenger()}}>hide messenger</button>
<button onClick={() => {showDialog()}}>show dialog</button>
<button onClick={() => {hideDialog()}}>hide dialog</button>
<button onclick={() => {setMessengerHeight(100)}}>set chat 100px from bottom<button>
<MessengerChat pageId='123456789101112' />
</div>
);
}
export default App;
Function | Description |
---|---|
setMessengerHeight(height: integer) | Immediately sets height of messenger chat in pixels from bottom of the page |
showMessenger(shouldShowDialog: bool) | Shows the whole component |
hideMessenger() | Hides the whole component |
showDialog() | Expands dialog |
hideDialog() | Hides dialog |
Official docs
Facebook provides official docs for messenger customer chat plugin and chat plugin sdk which the package is based on.
Author
My name is Alexander Huang and you can find my linkedin here! Don't hesitate to contact and thank you for tuning in :raised_hands: