@bigbinary/react-use-neeto-widget
v1.5.1
Published
A React integration of neeto widgets powered by hooks.
Readme
react-use-neeto-widget
A React integration of neeto widgets powered by hooks.
Installation
yarn add @bigbinary/react-use-neeto-widgetAPI
NeetoWidgetProvider
Place the NeetoWidgetProvider as high as possible in your application. This
will make sure you can call useNeetoWidget anywhere.
Example
import { NeetoWidgetProvider } from "@bigbinary/react-use-neeto-widget";
const App = () => {
return (
<NeetoWidgetProvider>
<p>Hi there, I am a child of the NeetoWidgetProvider</p>
</NeetoWidgetProvider>
);
};initializeNeetoWidget
The initializeNeetoWidget method is used to initialize the global widget
instance. It requires a valid API key to embed the widgets. It accepts API key
(required) and widget configurations (optional) as parameters.
Widget configurations in neetoChat
| name | type | description |
| -------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| visibleOnMount | boolean | The default value is true. If not set to false, there's no need to explicitly call the showWidget method, as the widget will be automatically set to the visible state after initialization. If the value is false, the widget will not be visible on initializing. You have to explicitly call the showWidget method.|
Example
import { initializeNeetoWidget } from "@bigbinary/react-use-neeto-widget";
const NEETO_WIDGET_API_KEY = "your-neeto-widget-api-key";
useEffect(() => {
initializeNeetoWidget(NEETO_WIDGET_API_KEY, {
neetoChat: {
visibleOnMount: false,
},
});
}, []);useNeetoWidget
useNeetoWidget hook is used to retrieve all methods bundled with neeto
widgets.
Make sure NeetoWidgetProvider is wrapped around your component when calling
useNeetoWidget().
Remark - You can't use useNeetoWidget() in the same component where
NeetoWidgetProvider is initialized.
Currently, we expose the following methods to interact with neetoChat widget. More methods will be added in future.
API
neetoChat
| name | description | | ----------------- | ----------------------------------------------------------- | | showWidget | Shows the Messenger | | hideWidget | Hides the Messenger | | maximizeWidget | Maximizes the Messenger | | minimizeWidget | Minimizes the Messenger | | isWidgetShown | Returns a boolean whether the Messenger is visible or not | | isWidgetMaximized | Returns a boolean whether the Messenger is maximized or not |
Example
import React from "react";
import {
NeetoWidgetProvider,
useNeetoWidget,
initializeNeetoWidget,
} from "@bigbinary/react-use-neeto-widget";
const App = () => (
<NeetoWidgetProvider>
<HomePage />
</NeetoWidgetProvider>
);
const HomePage = () => {
const { neetoChat } = useNeetoWidget();
const {
showWidget,
hideWidget,
maximizeWidget,
minimizeWidget,
isWidgetShown,
isWidgetMaximized
} = neetoChat;
const NEETO_WIDGET_API_KEY = "your-neeto-widget-api-key";
useEffect(() => {
initializeNeetoWidget(NEETO_WIDGET_API_KEY);
}, []);
return (
<>
<button onClick={showWidget}>Show messenger</button>
<button onClick={hideWidget}>Hide messenger</button>
<button onClick={maximizeWidget}>Maximize messenger</button>
<button onClick={minimizeWidget}>Minimize messenger</button>
<button onClick={() => {alert("Is messenger visible? -> ", isWidgetShown)}}>
Is messenger visible?
</button>
<button onClick={() => {alert("Is messenger maximized? -> ", isWidgetMaximized)}}>
Is messenger maximized?
</button>
</>
);
};Local development instructions
To test the changes in an application locally, follow the below steps. Let's test with the staging build of neetoChatWidget.
Update the value of the property
PUBLIC_PATHin.env.stagingof neetoChatWidget to point to the dist folder of the same project. You can also remove theHONEYBADGER_API_KEYfrom the.env.stagingfile and comment out theHoneybadgerPlugininitialization logic fromwebpack.prod.jsfile temporarily.eg:
http://127.0.0.1:5500/dist/. You can use extensions like Live Server to spin up a server from VSCode in neetoChatWidget and get the URL.Run
yarn build-stagingto build the staging version of neetoChatWidget.Update the
CHAT_WIDGET_SRCproperty in the.env.stagingfile ofneeto-base-widgetto the build output of the neetoChatWidget and comment out thegzipPluginfrom the plugins list in therollup.config.jsfile.eg:
http://127.0.0.1:5500/dist/neeto-widget-chat.js.Run the command
yarn build-stagingin the neeto-base-widget.Start a server as mentioned above in the neeto-base-widget and obtain the URL to the dist folder.
Set the value of
NEETO_BASE_WIDGET_SRCinsrc/constants.jsof react-use-neeto-widget pointing to the server serving the neeto-base-widget dist folder. eg:http://127.0.0.1:5501/dist/neeto-widget-staging.jsRun the command
yarn bundlein the react-use-neeto-widget and then runyalc publish.Add the package to the application you want to test using the command
yalc add @bigbinary/react-use-neeto-widget.
