From 32810e6618b87e66fec023f8029b1b636eaae943 Mon Sep 17 00:00:00 2001 From: Kilian <19181985+kilrau@users.noreply.github.com> Date: Thu, 28 Nov 2024 08:44:23 +0100 Subject: [PATCH] feat: add Chatwoot (#745) * feat: add chatwoot, replace discord as main help link * chore: linting and tsc * chore: address review * chore: check chatwoot env variable in build script --------- Co-authored-by: jackstar12 Co-authored-by: jackstar12 <62219658+jackstar12@users.noreply.github.com> Co-authored-by: michael1011 --- README.md | 2 +- build.py | 4 +++ src/chatwoot.ts | 51 +++++++++++++++++++++++++++++++++++++++ src/components/Footer.tsx | 14 +++-------- src/components/Nav.tsx | 2 +- src/config.ts | 2 ++ src/i18n/i18n.ts | 12 ++++----- src/index.tsx | 2 ++ 8 files changed, 71 insertions(+), 18 deletions(-) create mode 100644 src/chatwoot.ts diff --git a/README.md b/README.md index f6f0628d4..39fac208e 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ We encourage our technical users to check the code and run the web app locally f ## Resources -* Get Help: [Discord](https://discord.gg/QBvZGcW) | [Telegram](https://t.me/boltzhq) +* Get Help: [Support Center](https://support.boltz.exchange/hc/center/) | [Discord](https://discord.gg/QBvZGcW) | [Telegram](https://t.me/boltzhq) * Read the Docs: [Docs Home](https://docs.boltz.exchange/) * Read our Blog: [Substack](https://blog.boltz.exchange/) * Follow us: [X/Twitter](https://twitter.com/Boltzhq) | [Nostr](https://snort.social/p/npub1psm37hke2pmxzdzraqe3cjmqs28dv77da74pdx8mtn5a0vegtlas9q8970) diff --git a/build.py b/build.py index c7574788b..5e9224f4c 100755 --- a/build.py +++ b/build.py @@ -35,3 +35,7 @@ def handle_coop_disabled(): if var not in data: print(f"{var} not in .env file") sys.exit(1) + + for var in ["VITE_CHATWOOT_TOKEN"]: + if var not in data: + print(f"WARN: {var} not in .env file") diff --git a/src/chatwoot.ts b/src/chatwoot.ts new file mode 100644 index 000000000..d6fe2a52e --- /dev/null +++ b/src/chatwoot.ts @@ -0,0 +1,51 @@ +import log from "loglevel"; +import { onMount } from "solid-js"; + +import { config } from "./config"; + +declare global { + interface Window { + chatwootSettings: { + darkMode: string; + }; + chatwootSDK: { + run: (config: { websiteToken: string; baseUrl: string }) => void; + }; + $chatwoot: { + setCustomAttributes: (attributes: { swapId: string }) => void; + }; + } +} + +const Chatwoot = () => { + onMount(() => { + const token = import.meta.env.VITE_CHATWOOT_TOKEN; + const url = config.chatwootUrl; + + if (token === undefined || url === undefined) { + log.warn("Chatwoot URL or token not set"); + return; + } + + const tag = "script"; + const script = document.createElement(tag); + const parent = document.getElementsByTagName(tag)[0]; + script.src = url + "/packs/js/sdk.js"; + script.defer = true; + script.async = true; + parent.parentNode.insertBefore(script, parent); + script.onload = function () { + window.chatwootSettings = { + darkMode: "auto", + }; + window.chatwootSDK.run({ + websiteToken: token, + baseUrl: url, + }); + }; + }); + + return ""; +}; + +export default Chatwoot; diff --git a/src/components/Footer.tsx b/src/components/Footer.tsx index 6c53beabd..6abdbd583 100644 --- a/src/components/Footer.tsx +++ b/src/components/Footer.tsx @@ -17,16 +17,6 @@ const Footer = () => { return (