Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nuzhy/_/intercom integration [POC] #854

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
"@deriv-com/utils": "^0.0.38",
"@deriv/deriv-api": "^1.0.15",
"@deriv/quill-icons": "^1.23.1",
"@intercom/messenger-js-sdk": "^0.0.14",
"@livechat/customer-sdk": "4.0.2",
"canvas-toBlob": "1.0.0",
"classnames": "2.2.5",
Expand Down
2 changes: 1 addition & 1 deletion src/javascript/_common/base/livechat.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const LiveChat = (() => {
// Reroute group
const rerouteGroup = () => {

if (!window.fcWidget) {
if (!window.intercomSettings) {
LiveChat.livechatDeletion().then(() => {
LiveChat.liveChatInitialization().then(() => {
LiveChat.initialize();
Expand Down
9 changes: 5 additions & 4 deletions src/javascript/_common/utility.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { show } = require('@intercom/messenger-js-sdk');
const extend = require('extend');
const getCurrentBinaryDomain = require('../config').getCurrentBinaryDomain;
require('./lib/polyfills/element.matches');
Expand Down Expand Up @@ -290,17 +291,17 @@ const lc_licenseID = 12049137;
const lc_clientID = '66aa088aad5a414484c1fd1fa8a5ace7';

const openChat = () => {
if (window.fcWidget) {
window.fcWidget.open();
if (window.intercomSettings) {
show();
} else {
window.LC_API.open_chat_window();
}
};

const openChatWithParam = () => {
const interval = setInterval(() => {
if (window.fcWidget) {
window.fcWidget.open();
if (window.intercomSettings) {
show();
clearInterval(interval);
} else if (window.LiveChatWidget) {
window.LiveChatWidget?.on('ready', () => {
Expand Down
8 changes: 4 additions & 4 deletions src/javascript/app/base/header.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// const BinaryPjax = require('./binary_pjax');
const { shutdown } = require('@intercom/messenger-js-sdk');
const Client = require('./client');
const BinarySocket = require('./socket');
const AuthClient = require('../../_common/auth');
Expand Down Expand Up @@ -656,10 +657,9 @@ const Header = (() => {
};

const logoutOnClick = async () => {
window.fcWidget?.user.clear().then(
() => window.fcWidget.destroy(),
() => {}
);
if (window.intercomSettings) {
shutdown();
}
// This will wrap the logout call Client.sendLogoutRequest with our own logout iframe, which is to inform Hydra that the user is logging out
// and the session should be cleared on Hydra's side. Once this is done, it will call the passed-in logout handler Client.sendLogoutRequest.
// If Hydra authentication is not enabled, the logout handler Client.sendLogoutRequest will just be called instead.
Expand Down
24 changes: 20 additions & 4 deletions src/javascript/app/pages/livechat.jsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
import React from 'react';
import React, { useEffect } from 'react';
import ReactDOM from 'react-dom';
import useFreshChat from '../hooks/useFreshChat';
import Intercom from '@intercom/messenger-js-sdk';
import useGrowthbookGetFeatureValue from '../hooks/useGrowthbookGetFeatureValue';

const LiveChat = ({ cs_live_chat }) => {

const loginid = localStorage.getItem('active_loginid');
const client_info = loginid && JSON.parse(localStorage.getItem('client.accounts') || '{}')[loginid];
const token = client_info?.token ?? null;

const [isFreshChatEnabled] = useGrowthbookGetFeatureValue({
featureFlag: 'enable_freshworks_live_chat',
});
useFreshChat(token);

useEffect(() => {
if (!isFreshChatEnabled) return;

const intercomConfig = {
app_id : 'rfwdy059',
hide_default_launcher: true,
};

if (loginid && client_info) {
intercomConfig.email = client_info.email;
intercomConfig.name = client_info.email.split('@')[0];
intercomConfig.user_id = client_info.user_id;
intercomConfig.created_at = client_info.created_at;
}

Intercom(intercomConfig);
}, [isFreshChatEnabled, client_info, loginid]);

if (!isFreshChatEnabled && !cs_live_chat) return null;

Expand Down
Loading