Skip to content

Commit

Permalink
fix: add chatwood component
Browse files Browse the repository at this point in the history
  • Loading branch information
0xApotheosis committed Jan 9, 2024
1 parent 448f08e commit b417721
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/components/Chatwoot.tsx
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
}

0 comments on commit b417721

Please sign in to comment.