Skip to content

Commit 45a04b5

Browse files
authored
Merge pull request tangly1024#153 from txs/feature_facebook_messenger_customer_chat_plugin
Add Facebook Customer Chat for the blogging system
2 parents 37c0b07 + 3b6dc46 commit 45a04b5

File tree

4 files changed

+44
-8
lines changed

4 files changed

+44
-8
lines changed

blog.config.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ const BLOG = {
99
process.env.NOTION_PAGE_ID || '02ab3b8678004aa69e9e415905ef32a5', // Important page_id!!!Duplicate Template from https://www.notion.so/tanghh/02ab3b8678004aa69e9e415905ef32a5
1010
NOTION_ACCESS_TOKEN: process.env.NOTION_ACCESS_TOKEN || '', // Useful if you prefer not to make your database public
1111
DEBUG: process.env.NEXT_PUBLIC_DEBUG || false, // 是否显示调试按钮
12-
FACEBOOK_PAGE: 'https://www.facebook.com/tw.andys.pro', // Facebook Page 的連結
12+
13+
FACEBOOK_PAGE_ID: process.env.NEXT_PUBLIC_FACEBOOK_PAGE_ID || '', //Facebook Page ID 來啟用 messenger 聊天功能
14+
FACEBOOK_APP_ID: process.env.NEXT_PUBLIC_FACEBOOK_APP_ID || '', //Facebook App ID 來啟用 messenger 聊天功能
15+
FACEBOOK_PAGE: process.env.NEXT_PUBLIC_FACEBOOK_PAGE || 'https://www.facebook.com/tw.andys.pro', // Facebook Page 的連結
16+
1317
THEME: process.env.NEXT_PUBLIC_THEME || 'next', // 主题, 支持 ['next','hexo',"fukasawa','medium']
1418
THEME_SWITCH: process.env.NEXT_PUBLIC_THEME_SWITCH || false, // 是否显示切换主题按钮
1519
LANG: 'zh-CN', // e.g 'zh-CN','en-US' see /lib/lang.js for more.

components/FacebookMessenger.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import BLOG from '@/blog.config'
2+
import MessengerCustomerChat from 'react-messenger-customer-chat'
3+
4+
const Messenger = () => (
5+
<MessengerCustomerChat
6+
pageId={BLOG.FACEBOOK_PAGE_ID}
7+
appId={BLOG.FACEBOOK_APP_ID}
8+
language={BLOG.LANG.replace('-', '_')}
9+
/>
10+
)
11+
export default Messenger

next.config.js

+16-4
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,28 @@ module.exports = withBundleAnalyzer({
66
webpack5: true
77
},
88
images: {
9-
domains: ['gravatar.com', 'www.notion.so', 'avatars.githubusercontent.com', 'images.unsplash.com'] // 允许next/image加载的图片 域名
9+
domains: [
10+
'gravatar.com',
11+
'www.notion.so',
12+
'avatars.githubusercontent.com',
13+
'images.unsplash.com'
14+
] // 允许next/image加载的图片 域名
1015
},
11-
async headers () {
16+
async headers() {
1217
return [
1318
{
1419
source: '/:path*{/}?',
1520
headers: [
21+
{ key: 'Access-Control-Allow-Credentials', value: 'true' },
22+
{ key: 'Access-Control-Allow-Origin', value: '*' },
1623
{
17-
key: 'Permissions-Policy',
18-
value: 'interest-cohort=()'
24+
key: 'Access-Control-Allow-Methods',
25+
value: 'GET,OPTIONS,PATCH,DELETE,POST,PUT'
26+
},
27+
{
28+
key: 'Access-Control-Allow-Headers',
29+
value:
30+
'X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version'
1931
}
2032
]
2133
}

pages/_app.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ import { ThemeSwitch } from '@/components/ThemeSwitch'
2121
const Ackee = dynamic(() => import('@/components/Ackee'), { ssr: false })
2222
const Gtag = dynamic(() => import('@/components/Gtag'), { ssr: false })
2323
const Busuanzi = dynamic(() => import('@/components/Busuanzi'), { ssr: false })
24-
const GoogleAdsense = dynamic(() => import('@/components/GoogleAdsense'), { ssr: false })
24+
const GoogleAdsense = dynamic(() => import('@/components/GoogleAdsense'), {
25+
ssr: false
26+
})
27+
const Messenger = dynamic(() => import('@/components/FacebookMessenger'), {
28+
ssr: false
29+
})
2530

2631
const MyApp = ({ Component, pageProps }) => {
2732
return (
@@ -32,10 +37,14 @@ const MyApp = ({ Component, pageProps }) => {
3237
{BLOG.ANALYTICS_GOOGLE_ID && <Gtag />}
3338
{JSON.parse(BLOG.ANALYTICS_BUSUANZI_ENABLE) && <Busuanzi />}
3439
{BLOG.ADSENSE_GOOGLE_ID && <GoogleAdsense />}
40+
{BLOG.FACEBOOK_APP_ID && BLOG.FACEBOOK_PAGE_ID && <Messenger />}
3541
{/* FontawesomeCDN */}
36-
<link href={BLOG.FONT_AWESOME_PATH} rel="stylesheet" referrerPolicy="no-referrer" />
42+
<link
43+
href={BLOG.FONT_AWESOME_PATH}
44+
rel="stylesheet"
45+
referrerPolicy="no-referrer"
46+
/>
3747
<Component {...pageProps} />
38-
3948
</GlobalContextProvider>
4049
)
4150
}

0 commit comments

Comments
 (0)