# react-messenger-chat-plugin

> A react component for Facebook Messenger Chat Plugin with extra Customer Chat SDK features

Latest version **3.0.5** (published 2022-04-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-messenger-chat-plugin
pnpm add react-messenger-chat-plugin
yarn add react-messenger-chat-plugin
bun add react-messenger-chat-plugin
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.5 |
| Published | 2022-04-26 |
| First published | 2021-07-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 20.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Author | Alexander Charles Huang |
| Maintainers | hueindahaus |
| Keywords | react, messenger, chat, plugin, customer, chat |

## Links

- npm: https://www.npmjs.com/package/react-messenger-chat-plugin
- Repository: https://github.com/hueindahaus/react-messenger-chat-plugin
- Homepage: https://github.com/hueindahaus/react-messenger-chat-plugin#README.md
- Issues: https://github.com/hueindahaus/react-messenger-chat-plugin/issues
- npm.io page: https://npm.io/package/react-messenger-chat-plugin

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 3.0.5 (latest) — 2022-04-26
- 3.0.4 — 2022-04-26
- 3.0.3 — 2022-04-26
- 3.0.2 — 2022-04-26
- 2.0.2 — 2022-02-21
- 2.0.1 — 2022-02-20
- 1.0.9 — 2021-10-29
- 1.0.8 — 2021-10-29
- 1.0.7 — 2021-10-04
- 1.0.6 — 2021-07-06
- 1.0.5 — 2021-07-04
- 1.0.4 — 2021-07-04
- 1.0.3 — 2021-07-04
- 1.0.2 — 2021-07-04
- 1.0.1 — 2021-07-04
- … 1 more at https://npm.io/package/react-messenger-chat-plugin/versions

## README

# react-messenger-chat-plugin :speech_balloon: [![npm](https://img.shields.io/npm/v/react-messenger-chat-plugin.svg)](https://www.npmjs.com/package/react-messenger-chat-plugin) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) ![size](https://img.shields.io/bundlephobia/min/react-messenger-chat-plugin?color=success) ![language](https://img.shields.io/github/languages/top/hueindahaus/react-messenger-chat-plugin?color=ff69b4)

 <p align="center">
 <img width="340" src="https://user-images.githubusercontent.com/45295311/124386303-16e4b280-dcda-11eb-9470-2ee68e7fc209.png">
 <img width="340" src="https://user-images.githubusercontent.com/45295311/124386301-164c1c00-dcda-11eb-83fe-aa50c9297a7f.png">
</p>

<p align="center">
 <img width="340" height="600" src="https://user-images.githubusercontent.com/45295311/124386300-164c1c00-dcda-11eb-8992-b0b96bf32f53.png">
 <img width="340" height="600" src="https://user-images.githubusercontent.com/45295311/124386299-15b38580-dcda-11eb-9e3d-19e368d1cfc1.png">
 </p>

<br />

## Table of contents

- [Installation](#installation)
- [Usage](#usage)
  - [MessengerChat Component](#messenger-chat-component)
  - [MessengerChat Control Functions](#messenger-chat-control-functions)
- [Official docs](#official-docs)

<br />

## Installation <a name="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](https://ngrok.com/).

### npm

```sh
npm install react-messenger-chat-plugin
```

### yarn

```sh
yarn add react-messenger-chat-plugin
```

<br />

## Usage <a name="usage" />

### MessengerChat Component<a name="messenger-chat-component" />

```js
import React from "react";
import ReactDOM from "react-dom";
import { MessengerChat } from "react-messenger-chat-plugin";

ReactDOM.render(
  <MessengerChat
    pageId="109268111769502"
    language="sv_SE"
    themeColor={"#000000"}
    bottomSpacing={300}
    loggedInGreeting="loggedInGreeting"
    loggedOutGreeting="loggedOutGreeting"
    greetingDialogDisplay={"show"}
    debugMode={true}
    onMessengerShow={() => {
      console.log("onMessengerShow");
    }}
    onMessengerHide={() => {
      console.log("onMessengerHide");
    }}
    onMessengerDialogShow={() => {
      console.log("onMessengerDialogShow");
    }}
    onMessengerDialogHide={() => {
      console.log("onMessengerDialogHide");
    }}
    onMessengerMounted={() => {
      console.log("onMessengerMounted");
    }}
    onMessengerLoad={() => {
      console.log("onMessengerLoad");
    }}
  />,
  document.getElementById("demo")
);
```

| Attribute                        |                                             Description                                             | Default |
| -------------------------------- | :-------------------------------------------------------------------------------------------------: | :-----: |
| 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                   | "en_US" |
| themeColor (string)              |                                  Hexcode color of the theme color                                   |         |
| bottomSpacing (number)           |                                         Bottom spacing (px)                                         |         |
| greetingDialogDisplay (string)   |     Determine how the greeting dialog will be displayed. One of "hide", "show", "fade", "icon"      |         |
| greetingDialogDelay (number)     | Sets the number of seconds of delay before the greeting dialog is shown after the plugin is loaded. |    0    |
| loggedInGreeting (string)        |                           Greeting message displayed if user is logged in                           |         |
| loggedOutGreeting (string)       |                          Greeting message displayed if user is logged out                           |         |
| 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                  |  false  |
| version                          |                                    Version of the messenger chat                                    | "v13.0" |

> :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.

<br />

### MessengerChat Control Functions <a name="messenger-chat-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.

```js
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={() => {setMessengerBottomSpacing(100)}}>set chat 100px in bottom spacing<button>

      <MessengerChat pageId='123456789101112' />
    </div>
  );
}

export default App;
```

| Function                                   |                                 Description                                 |
| ------------------------------------------ | :-------------------------------------------------------------------------: |
| setMessengerBottomSpacing(spacing: number) | 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                                 |

<br />

## Official docs <a name="official-docs" />

Facebook provides official docs for [messenger customer chat plugin](https://developers.facebook.com/docs/messenger-platform/discovery/facebook-chat-plugin/) and [chat plugin sdk](https://developers.facebook.com/docs/messenger-platform/discovery/customer-chat-plugin/sdk/) which the package is based on.

<br />

## Author

My name is Alexander Huang and you can find my linkedin [here](https://www.linkedin.com/in/alexander-huang-4370991a3/)! Don't hesitate to contact and thank you for tuning in :raised_hands:

---
_Source: https://npm.io/package/react-messenger-chat-plugin · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
