calibreapp / react-live-chat-loader Goto Github PK
View Code? Open in Web Editor NEWImplement a live chat beacon in your React application without performance regressions.
Home Page: https://react-live-chat-loader.now.sh
License: MIT License
Implement a live chat beacon in your React application without performance regressions.
Home Page: https://react-live-chat-loader.now.sh
License: MIT License
I have implemented the intercom provider into my nextjs app. However, it never loads until the tab is in the background (switching tabs for idlePeriod) and then switching back. This is most definitely not the intended functionality.
Adding Freshdesk's Freshchat (https://www.freshworks.com/live-chat-software/) widget to a webpage adds a huge amount of additional JavaScript.
I'd like to see react-live-chat-loader add support for Freshchat
I'd love to be able to customize the Intercom background_color
before initialization. Before using react-live-chat-loader I would simply put that in my window.Intercom('boot')
call, but no there's nowhere to put it.
I'd like for either the color prop to also apply to the background, or for a backgroundColor
prop to be added to LiveChatLoaderProvider
.
I currently use the onReady
callback to switch the background color after Intercom loads, but it can cause the default blue to flash to my color on the user's screen if they click the button before Intercom lazy loads.
I'm wondering if the user switches to a new page if he will receive messages that our support team writes? I believe they won't be since the widget is only loaded once the user hovers that mouse over the icon?
Any advice on how to overcome this?
When trying to use the facebook provider="messenger" and providerKey="172743013379" (application ID) I get
=> Refused to display 'https://www.facebook.com/' in a frame because it set 'X-Frame-Options' to 'deny'.
I have white listed the domain from which I using the "react-chat-loader" package.
If I understood the code correctly, when Intercom finishes loading
state will be set tocomplete
and Intercom is opened automatically without user interaction.
Call to setting complete
state:
This is very bad UX since on mobile Intercom pops up and takes the whole viewport when opened. Therefore, without any notice a new screen pops up for the user on mobile. I think it should be out of scope of this package to automatically open the Intercom window without user interaction involved or people calling window.Intercom('show')
on their code manually.
@michaeldijkstra thanks for adjusting messenger provider and component first!
I used the latest version in my project, but no customer chat dialog pop up, Have you test it?
I know you move fb-customerchat
from preload phase to a component called CustomerChat
,
it seems not working, we know that fb-customerchat
is necessary for Customer Chat SDK, I think the problem is when you finish loading script, then state
will become complete
, then LiveChatLoaderContext
will update which will trigger useProvider update as well, then re-render
CustomerChat
, in the same time, Customer Chat SDK is parsed and executed, it tries to find the fb-customerchat
, but CustomerChat
just render, so it can't find any match, so it won't work.
I try to move fb-customerchat
to any place except inside of LiveChatLoaderProvider
, it works as expected.
Is not convenient to have to write additional code for using react-live-chat-loader, What if we wrap code which creates fb-customerchat
in useEffect
of Messenger component? I think this a great way to decouple all code in load script and still work as you want and you did before.
by the way, I would like you to help me delete this PR: #10, that was a mistake. please delete it.
Trying to start a server to see the app in action. I've cloned it and and npm installed. I don't see a script for how to start the app.
We are getting a weird error about memory leak when we browse 2/3 pages of our website, after some seconds we got it telling us:
commons.js:77200 Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.
in LiveChatLoaderProvider (at layout.js:114)
in ThemeProvider (at layout.js:88)
in Layout (at print-on-demand.js:23)
in PoD (created by HotExportedPoD)
in AppContainer (created by HotExportedPoD)
in HotExportedPoD (created by PageRenderer)
Using the Messenger component in Typescript results in annoying typing errors. The props field is defined with
providerKey: Provider | undefined;
but would be better served as providerKey?: Provider
so we are not forced to do <Messenger providerKey={undefined} />
or <Messenger providerKey='messenger' />
This also does not match with the documentation which doesn't indicate any props are necessary. The same is true with the mention of locale
property which does not exist.
Using version 2.7.3
Lighthouse is complaining about an aria-* rule violation: [aria-*] attributes do not match their roles
<LiveChatLoaderProvider providerKey="lksanlsknksal" provider="drift">
...
<Drift />
</LiveChatLoaderProvider>
No accessibility errors should be present
Hi, I'm trying to add a new provider.
following the instructions to add an example page
i get the error
Error: Invalid hook call. Hooks can only be called inside of the body of a function component.
any idea what i'm doing wrong?
When using drift chat on my Gatsby site, the first pop up shows up correctly that greets the user but upon changing routes/url's it cuts off the pop up box due to the inline style setting of "width: 76px !important"
the bug can currently bee seen here on my staging site https://dripsstaging.gtsb.io
Second pop up box should not have a set width of 76px
It seems that this module does not work in a browserless situation (e.g. server-side rendering). To workaround, I can conditionally render the component, but that's a bit of a pain. It would be nice if the module could detect whether the browser is present (and if not, there is no need to do anything).
HelpScout's state to see if it's open or closed doesn't seem to work. Once you open it, you can't close it unless you click HelpScout's specific close button.
You can see it happening in the demo docs as well:
https://react-live-chat-loader.vercel.app/helpscout
No response
I get this warning from time to time.
Warning: The final argument passed to useEffect changed size between renders. The order and size of this array must remain constant.
Previous: []
Incoming: [function () {
// Don't load if idlePeriod is 0, null or undefined
if (typeof window === 'undefined' || !loadWhenIdle || !idlePeriod) return; // Don't load if 2g connection or save-data is enabled
if (connection && (connection.saveData || /2g/.test(connection.effectiveType))) return;
var idleThreshold = parseInt(idlePeriod, 10);
if (isNaN(idleThreshold)) return; // deadline.timeRemaining() has an upper limit of 50 milliseconds
// We want to ensure the page has been idle for a significant period of time
// Therefore we count consecutive maximum timeRemaining counts and load chat when we reach our threshold
var elapsedIdlePeriod = 0;
var previousTimeRemaining = 0;
var scheduleLoadChat = function scheduleLoadChat(deadline) {
if (elapsedIdlePeriod > idleThreshold) return loadChat({
open: false
});
var timeRemaining = deadline.timeRemaining(); // To ensure browser is idle, only accumalte elapsedIdlePeriod when
// two consecutive maximum timeRemaining's have been observed
if (previousTimeRemaining > 49 && timeRemaining > 49) elapsedIdlePeriod += timeRemaining;
previousTimeRemaining = timeRemaining;
requestIdleCallback(scheduleLoadChat);
};
if (requestIdleCallback) {
requestIdleCallback(scheduleLoadChat);
} else {
setTimeout(function () {
return loadChat({
open: false
});
}, idleThreshold);
}
}]
in HelpScout (at App.js:908)
in LiveChatLoaderProvider (at App.js:902)
in Provider (at App.js:966)
...
All components are being bundled when using Gatsby V3 and Webpack V5, see screenshot.
I think it is due to fact that providers are exported as object instead of named exports (https://github.com/calibreapp/react-live-chat-loader/blob/main/src/providers/index.ts).
Changing exports and then using named imports like:
import * as Providers from 'providers'
in (https://github.com/calibreapp/react-live-chat-loader/blob/main/src/components/LiveChatLoaderProvider.tsx#L2)
might make them tree-shakeable. Could you look into this?
It would simplify the logic a bit if you always used requestIdleCallback
and required anyone supporting a browser without support to polyfill it using setTimeout
.
When trying to implement this with Drift I'm getting the following error:
TypeError: undefined is not a function (near '...(0, _react.memo)...')
> 205 | var CustomerChat = (0, _react.memo)(function (_ref) {
My implementation:
import React, { Component } from "react";
import { LiveChatLoaderProvider, Drift } from 'react-live-chat-loader'
class App extends Component {
render() {
return (
<LiveChatLoaderProvider provider="drift" providerKey="***" >
<Drift icon="A" color="#0176ff"/>
</LiveChatLoaderProvider>
);
}
}
export default App;
Any thoughts on what could be causing this?
Facebook Messenger also provides a customer chat plugin which is common to consumer-facing services.
Just wanted to give you a heads up that I've adapted the Intercom chat widget to a pure JavaScript implementation (my first JS library, too) https://github.com/danielbachhuber/intercom-facade
We're not using React, so I wanted to do something super plain and simple.
React-facebook provides variety of FB-related components. I strongly suspect there is a conflict causing the chat to often not show (but not always), possibly depending on the order of initialization of both packages.
Steps to reproduce the behavior:
<FacebookProvider appId="xxxx">
<LiveChatLoaderProvider providerKey="yyyy" appId="xxxxx" provider="messenger" locale="en_US">
...
<Messenger />
</LiveChatLoaderProvider>
</FacebookProvider>
(Tried also without appId in LiveChatLoaderProvider)
2. Load the page
3. Click the messenger button
Actual results:
TypeError: window.FB.CustomerChat is undefined
at .open ( [../../../src/providers/messenger.ts:81] )
at .open ( [../../../src/providers/messenger.ts:81] )
at .check ( [../../../src/utils/waitForLoad.ts:15] )
at .check ( [../../../src/utils/waitForLoad.ts:20] )
at .check ( [../../../src/utils/waitForLoad.ts:20] )
...
messenger.ts:loadScript:16
(link) returns false
because window.FB
is already there, possibly initialized by react-facebook package.Should the check in messenger.ts not relay on window.FB
presence, or ensure that customer chat is there?
If you're a user with an ad-blocker, the chat button click does nothing.
Hide the chat button entirely if the user is using an ad-blocker
Hosting the embed script on another domain under a different name in-order to avoid the ad-blocker altogether. This was thrown out because of user privacy.
In-case you'd like to read the HelpScout section about ad-blocking: https://docs.helpscout.com/article/911-beacon-and-ad-blockers
I don't know if this is a bug, feature request or a chore, but if I import this module in a TS file, I get the following error:
TS7016: Could not find a declaration file for module 'react-live-chat-loader'. Try `npm i --save-dev @types/react-live-chat-loader` if it exists or add a new declaration (.d.ts)
Trying to run that npm
command yields:
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/@types%2freact-live-chat-loader - Not found
npm ERR! 404
npm ERR! 404 '@types/react-live-chat-loader@latest' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.
If there is another recommended way to avoid TS7016 with this package, please let me know. Thanks.
👋🏻 Hi there! Chat only loads if the user puts the window in the background or hovers over the icon on GatsbyJS. I have included a codesandbox below of a Gatsby starter template with react-live-chat-loader installed to demonstrate this issue.
Not properly detecting idle period while using react-live-chat-loader with Gatsby JS
Steps to reproduce the behavior:
Chatbot loads after set idle period(setting idlePeriod has no effect)
First, I want to thank you so much for this library! I enjoy using this.
Unfortunately, this library does not work with React 18.
Please provide a clear and concise description of what the bug is. Include relevant operating system, browser and other environment information.
Steps to reproduce the behavior:
A clean npm install
Currently Intercom allows certain positional changes. It is not possible to mirror this, since the <Intercom>
component uses hard-coded styling, other than the color
Ability to pass in a style object to override any defaults
Using Intercom, you're able to set user data when registering the chat loader. For example:
window.Intercom('boot', {
app_id: 'app_id_here',
...(user && {
name: `${user.name.first} ${user.name.last}`,
email: user.email,
user_id: user.id,
created_at: user.created_at,
}),
Is there any way to do this with this loader currently?
This was observed on the live chat loader using it for Intercom. The div element wrapping the loader has an aria-label attribute causing an accessibility issue on lighthouse. Removing the aria-label by hand fixed the issue for me.
The issue on the lighthouse report (accessibility) would be solved.
Remove the aria-label="Load Chat" attribute.
Replace the aria-label attribute by another one not causing a lighthouse error.
Here are some screenshots showing the issue
Thanks for this great library!
It seems like the imports in the bundled type definitions are broken.
For example, at https://unpkg.com/browse/[email protected]/dist/components/LiveChatLoaderProvider.d.ts, provider
resolves to any
because your absolute import settings (baseUrl
) aren't used to create relative paths when declarations are created.
I don't know of any solution that wouldn't involve adding another package to your build toolchain. Potentially interesting without adding webpack or a full rollup setup:
I want to hide Userlike when printing a page. Are there any things that I can easily add to do that?
Trying to do something like this
@media print {
....
display: none !important;
....
}
But there is no possibility for now as I understood.
Thanks!
I imagine this will be quite difficult to solve but here goes..
Intercom's admin panel can control on which pages to display the chat widget.
As developers by adding the <Intercom />
component to certain pages we lose the flexibility of having our support team manage which pages to display the widget.
Drift allows you to respond to a number of events (beyond the 'ready' event) but the drift
script has to be loaded and ready before you can attach any listeners.
Right now, to attach listeners to drift events you can wrap either the Drift
component and orchestrate it yourself based on the state
returned from the useChat
hook being set to complete
. A simple example:
const [ state ] = useChat();
useEffect(() => {
if (state === "complete") {
window.drift.on('conversationStarted', () => {})
}
}, [ state ]);
This can be introduced, likely without a breaking change, by accepting an optional events
prop in the Drift
component and registering the provided event handlers with drift once appropriate.
The events
prop type could be an object of Drift event names to handlers:
const driftListeners: DriftEventHandlers = {
startConversation: ({ conversationId }) => {
// do something here...
},
};
This type could defined using something like:
I'm new to TypeScript so take this with a grain of salt
type DriftEventPayloads = {
startConversation: {
conversationId: number;
inboxId: number;
};
chatOpen: undefined;
chatClose: undefined;
// ... all other supported events
};
type DriftEventHandler<P> = (data: P) => void;
export type DriftEventHandlers = {
[K in keyof DriftEventPayloads]?: DriftEventHandler<DriftEventPayloads[K]>;
};
If this or an alternate solution makes sense I'm happy to submit a PR.
It's possible to accept a prop in the LiveChatLoaderProvider
, which in theory makes sense because that's where the initialization props are provided and extra props are included in the context. However, it's unclear to me if event listening would be applicable/beneficial with other providers and would require a change to useChat
and the provider api.
Allowing left alignment of Drift widget
Adding component props for left (right default) for Drift
Alternatively, can you place an ID or Class on the div that contains the button so I can target it via CSS for left alignment?
No
No response
No response
See the note at the bottom of this article
Right now, I'm using Segment's device-based Intercom integration to load the Intercom script, identify users, and sync analytics events.
Do you have any suggestion for how to use this facade with Segment? Ideally, I'm thinking it'll work like this:
window.Intercom
function that enables other scripts (like Segment) to call the Intercom API while the actual Intercom widget is still being fetched.I've also opened a support ticket with Segment, because I'm guessing they'll be able to help more than you guys.
This project is amazing and we are currently adding it to our own website.
I was wondering if you have any plans on adding type definitions?
Cheers
Hello,
I am using Webflow to create my website and google tag manager to make drift works. But I am not sure how to install this inside the google tag manager since npm seems does not work inside the google tag manager.
Thank you ahead for your help!
This code from the README.md
file...
import { useChat } from 'react-live-chat-loader'
export const LoadChatButton = () => {
const [state, loadChat] = useChat()
return <button onClick={loadChat}>Load Chat</button>
}
... throws the following error:
Server Error
TypeError: Cannot destructure property 'loadWhenIdle' of 'undefined' as it is undefined.
I'd like to use react-live-chat-loader with Help Scout. The RLCL docs call for me to use aproviderKey
. Help Scout doesn't seem to supply me with a providerKey
. None is required when I load Help Scout on my site without using a facade, which I do like this:
<script async type="text/javascript">
!function (e, t, n) {
function a() {
var e = t.getElementsByTagName("script")[0], n = t.createElement("script");
n.type = "text/javascript", n.async = !0, n.src = "https://beacon-v2.helpscout.net", e.parentNode.insertBefore(n, e)
}
if (e.Beacon = n = function (t, n, a) {
e.Beacon.readyQueue.push({method: t, options: n, data: a})
}, n.readyQueue = [], "complete" === t.readyState) return a();
e.attachEvent ? e.attachEvent("onload", a) : e.addEventListener("load", a, !1)
}(window, document, window.Beacon || function () {
});
</script>
I've looked in the RLCL docs and haven't yet found a reference to where I can find the providerKey
.
Where can I find the providerKey
for Help Scout?
UPDATE: I found it on the HelpScout site.
Hi there, first of all, thanks for the amazing component, this is great! Anything that can help load less JavaScript on the client is awesome! 💯
I wanted to ask whether it would be possible to have a provider for Crisp chat, since Intercom and Drift are supported.
I'm sure its already in the pipeline for this package, but adding Drift messenger support would be awesome as well!
I have the latest version installed and using Intercom via the instructions. On iOS Safari and Chrome, the placeholder Intercom chat widget appears but then disappears after about 6 seconds. Any idea why this is happening?
Let me preface this by saying I do not know much about this issue, other than I've had multiple users report it. I do not know if it is HelpScout or this package, but it seems it might be more widespread if it was HelpScout and I could not find any sign of it when searching.
I've had some users, all on iPhones, report that the Beacon shows up twice on some page loads. See this image:
When this happens, they also report some kind of loss of functionality on the page itself. This makes me think there has been some sort of javascript error impeding the app. I know these types of issues are very difficult to track down and I don't have a small repro scenario (nor currently the resources to craft one), but I thought I should post this here in case anyone has an idea what might be going on.
I'm using HelpScout and nextjs.
When I maximise HelpScout and then navigate to another route, the placeholder button shows up over the top of the real button, making it impossible to close the live chat.
No response
No response
No response
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.