-
-
Notifications
You must be signed in to change notification settings - Fork 755
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate Facebook Customer Chat (#331)
- Loading branch information
Showing
22 changed files
with
167 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* React Starter Kit for Firebase | ||
* https://github.com/kriasoft/react-firebase-starter | ||
* Copyright (c) 2015-present Kriasoft | MIT License | ||
*/ | ||
|
||
import React from 'react'; | ||
import { fb } from '../utils'; | ||
import { ConfigContext } from '../hooks'; | ||
|
||
// https://developers.facebook.com/docs/messenger-platform/discovery/customer-chat-plugin | ||
class CustomerChat extends React.PureComponent { | ||
componentDidMount() { | ||
this.timeout = setTimeout(() => { | ||
fb(FB => this.timeout && FB.XFBML.parse()); | ||
}, 3000); | ||
} | ||
|
||
componentWillUnmount() { | ||
clearTimeout(this.timeout); | ||
delete this.timeout; | ||
} | ||
|
||
render() { | ||
return ( | ||
<ConfigContext.Consumer> | ||
{config => ( | ||
<div | ||
className="fb-customerchat" | ||
attribution="setup_tool" | ||
page_id={config.facebook.pageId} | ||
// theme_color="..." | ||
// logged_in_greeting="..." | ||
// logged_out_greeting="..." | ||
// greeting_dialog_display="..." | ||
// greeting_dialog_delay="..." | ||
// minimized="false" | ||
// ref="..." | ||
/> | ||
)} | ||
</ConfigContext.Consumer> | ||
); | ||
} | ||
} | ||
|
||
export default CustomerChat; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* React Starter Kit for Firebase | ||
* https://github.com/kriasoft/react-firebase-starter | ||
* Copyright (c) 2015-present Kriasoft | MIT License | ||
*/ | ||
|
||
export const canUseDOM = !!( | ||
typeof window !== 'undefined' && | ||
window.document && | ||
window.document.createElement | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* React Starter Kit for Firebase | ||
* https://github.com/kriasoft/react-firebase-starter | ||
* Copyright (c) 2015-present Kriasoft | MIT License | ||
*/ | ||
|
||
import loadScript from 'load-script'; | ||
import { canUseDOM } from './env'; | ||
|
||
let initialized = false; | ||
let queue = []; | ||
|
||
export function fb(callback) { | ||
if (!canUseDOM) { | ||
return; | ||
} else if (initialized) { | ||
callback(window.FB); | ||
} else { | ||
queue.push(callback); | ||
if (!window.fbAsyncInit) { | ||
// https://developers.facebook.com/docs/javascript/reference/FB.init | ||
window.fbAsyncInit = () => { | ||
window.FB.init({ | ||
appId: window.config.facebook.appId, | ||
autoLogAppEvents: true, | ||
status: true, | ||
cookie: true, | ||
xfbml: false, | ||
version: 'v3.2', | ||
}); | ||
initialized = true; | ||
queue.forEach(cb => cb(window.FB)); | ||
queue = null; | ||
}; | ||
const isDebug = window.localStorage.getItem('fb:debug') === 'true'; | ||
loadScript(`https://connect.facebook.net/en_US/sdk/xfbml.customerchat${isDebug ? '/debug' : ''}.js`, { async: true }); // prettier-ignore | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.