-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from shapeshift/add-chatwoot
feat: add chatwoot
- Loading branch information
Showing
4 changed files
with
51 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,9 @@ | ||
VITE_FOO=bar | ||
# Feature flags | ||
VITE_FEATURE_MIXPANEL=true | ||
VITE_FEATURE_CHATWOOT=false | ||
|
||
VITE_FOO=bar | ||
|
||
# chat woot | ||
VITE_CHATWOOT_TOKEN=jmoXp9BPMSPEYHeJX5YKT15Q | ||
VITE_CHATWOOT_URL=https://app.chatwoot.com |
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,38 @@ | ||
import { Button } from '@chakra-ui/react' | ||
import { useCallback, useEffect } from 'react' | ||
|
||
export const ChatwootButton: React.FC = () => { | ||
const chatWootEnabled = import.meta.env.VITE_FEATURE_CHATWOOT | ||
useEffect(() => { | ||
if (!chatWootEnabled) return // Add Chatwoot Settings | ||
;(window as any).chatwootSettings = { | ||
hideMessageBubble: true, | ||
position: 'left', // This can be left or right | ||
locale: 'en', // Language to be set | ||
type: 'standard', // [standard, expanded_bubble] | ||
} | ||
|
||
// Paste the script from inbox settings except the <script> tag | ||
;(function (d: Document) { | ||
const BASE_URL = import.meta.env.VITE_CHATWOOT_URL | ||
const g = d.createElement('script') | ||
const s = d.getElementsByTagName('script')[0] | ||
g.src = BASE_URL + '/packs/js/sdk.js' | ||
s.parentNode?.insertBefore(g, s) | ||
g.async = true | ||
g.onload = function () { | ||
;(window as any).chatwootSDK.run({ | ||
websiteToken: import.meta.env.VITE_CHATWOOT_TOKEN, | ||
baseUrl: BASE_URL, | ||
}) | ||
} | ||
})(document) | ||
}, [chatWootEnabled]) | ||
|
||
const handleChatWoot = useCallback(() => { | ||
// @ts-ignore | ||
if (window.$chatwoot) window.$chatwoot.toggle() | ||
}, []) | ||
|
||
return chatWootEnabled ? <Button onClick={handleChatWoot}>Get support</Button> : null | ||
} |
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