Skip to content

Commit

Permalink
chatwoot integration
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlesNg35 committed Oct 24, 2023
1 parent 3fa899c commit 749c7c9
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 8 deletions.
3 changes: 3 additions & 0 deletions apps/web/.env
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,6 @@ JITSU_BROWSER_WRITE_KEY=

# Github Integration
NEXT_PUBLIC_GITHUB_APP_NAME=ever-github

# Chatwoot

Check warning on line 61 in apps/web/.env

View workflow job for this annotation

GitHub Actions / Cspell

Unknown word (Chatwoot)
NEXT_PUBLIC_CHATWOOT_API_KEY=

Check warning on line 62 in apps/web/.env

View workflow job for this annotation

GitHub Actions / Cspell

Unknown word (CHATWOOT)
42 changes: 42 additions & 0 deletions apps/web/lib/features/integrations/chatwoot/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React, { useEffect } from 'react';

declare global {
interface Window {
chatwootSettings: any;

Check warning on line 5 in apps/web/lib/features/integrations/chatwoot/index.tsx

View workflow job for this annotation

GitHub Actions / Cspell

Unknown word (chatwoot)
chatwootSDK: any;

Check warning on line 6 in apps/web/lib/features/integrations/chatwoot/index.tsx

View workflow job for this annotation

GitHub Actions / Cspell

Unknown word (chatwoot)
}
}

export default function ChatwootWidget() {

Check warning on line 10 in apps/web/lib/features/integrations/chatwoot/index.tsx

View workflow job for this annotation

GitHub Actions / Cspell

Unknown word (Chatwoot)
useEffect(() => {
const websiteToken = process.env.NEXT_PUBLIC_CHATWOOT_API_KEY;

Check warning on line 12 in apps/web/lib/features/integrations/chatwoot/index.tsx

View workflow job for this annotation

GitHub Actions / Cspell

Unknown word (CHATWOOT)
if (!websiteToken) {
return;
}

window.chatwootSettings = {

Check warning on line 17 in apps/web/lib/features/integrations/chatwoot/index.tsx

View workflow job for this annotation

GitHub Actions / Cspell

Unknown word (chatwoot)
hideMessageBubble: false,
position: 'right',
locale: 'en',
type: 'standard'
};

(function (d, t) {
const BASE_URL = 'https://app.chatwoot.com';
const g = d.createElement(t) as HTMLScriptElement;
const s = d.getElementsByTagName(t)[0];

g.src = BASE_URL + '/packs/js/sdk.js';
s.parentNode && s.parentNode.insertBefore(g, s);
g.async = !0;
g.onload = function () {
window.chatwootSDK.run({
websiteToken: websiteToken,
baseUrl: BASE_URL
});
};
})(document, 'script');
}, []);

return <></>;
}
13 changes: 5 additions & 8 deletions apps/web/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import { JitsuProvider } from '@jitsu/jitsu-react';
import React from 'react';
import { JitsuAnalytics } from '../lib/components/services/jitsu-analytics';
import { jitsuConfiguration } from '@app/constants';
import ChatwootWidget from 'lib/features/integrations/chatwoot';

export default function MyApp({ Component, pageProps }: AppProps) {
const isJitsuEnvsPresent =
jitsuConfiguration.host && jitsuConfiguration.writeKey;
const isJitsuEnvsPresent = jitsuConfiguration.host && jitsuConfiguration.writeKey;
return (
<>
<Script
Expand All @@ -32,26 +32,23 @@ export default function MyApp({ Component, pageProps }: AppProps) {
</Script>
<Head>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link
rel="preconnect"
href="https://fonts.gstatic.com"
crossOrigin=""
/>
<link rel="preconnect" href="https://fonts.gstatic.com" crossOrigin="" />
</Head>
<JitsuProvider
options={
isJitsuEnvsPresent
? { ...jitsuConfiguration }
: {
disabled: true
}
}
}
>
<RecoilRoot>
<ThemeProvider attribute="class">
<SkeletonTheme baseColor="#F0F0F0" enableAnimation={false}>
<AppState />
<JitsuAnalytics user={pageProps?.user} />
<ChatwootWidget />
<Component {...pageProps} />
</SkeletonTheme>
</ThemeProvider>
Expand Down

0 comments on commit 749c7c9

Please sign in to comment.