Skip to content

Commit

Permalink
fix: ensure chatwoot is available before interacting with the API
Browse files Browse the repository at this point in the history
  • Loading branch information
simenandre committed Jun 26, 2023
1 parent a4c52cc commit 837da9b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/components/chatwoot.svelte
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<script lang="ts">
import { onMount } from 'svelte';
onMount(() => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(window as any).chatwootSDK.run({
websiteToken: 'm94Z8YzguKbGc1XnowaNjHfM',
baseUrl: 'https://app.chatwoot.com'
});
const chatwoot = window.chatwootSDK;
if (chatwoot) {
chatwoot.run({
websiteToken: 'm94Z8YzguKbGc1XnowaNjHfM',
baseUrl: 'https://app.chatwoot.com'
});
}
});
</script>

Expand Down
3 changes: 3 additions & 0 deletions src/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
declare interface Window {
chatwootSDK?: {
run: (config: Record<string, string>) => void;
};
$chatwoot: {
toggle: (state?: 'open' | 'close') => void;
};
Expand Down

0 comments on commit 837da9b

Please sign in to comment.