-
Notifications
You must be signed in to change notification settings - Fork 13
Fix/fix crisp #1393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Fix/fix crisp #1393
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fae636e
fix crisp
Hugo0 89b1c92
fix formatting
Hugo0 141d76f
fix crisp metadata
Hugo0 e16c032
fixes
Hugo0 413d721
FINALLY
Hugo0 c2fffb3
format
Hugo0 60dedbd
refactor: address PR review comments for Crisp integration
Hugo0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,159 @@ | ||
| 'use client' | ||
|
|
||
| import Script from 'next/script' | ||
| import { useEffect, Suspense } from 'react' | ||
| import { useSearchParams } from 'next/navigation' | ||
| import { CRISP_WEBSITE_ID } from '@/constants/crisp' | ||
|
|
||
| /** | ||
| * Crisp Proxy Page - Same-origin iframe solution for embedded Crisp chat | ||
| * | ||
| * This page loads the Crisp widget in full-screen mode and is embedded as an iframe | ||
| * from SupportDrawer and SupportPage. By being same-origin, we avoid CORS issues | ||
| * and can fully control the Crisp instance via JavaScript. | ||
| * | ||
| * User data flows via URL parameters and is set during Crisp initialization, | ||
| * following Crisp's recommended pattern for iframe embedding with JS SDK control. | ||
| */ | ||
| function CrispProxyContent() { | ||
| const searchParams = useSearchParams() | ||
|
|
||
| useEffect(() => { | ||
| if (typeof window !== 'undefined') { | ||
| ;(window as any).CRISP_RUNTIME_CONFIG = { | ||
| lock_maximized: true, | ||
| lock_full_view: true, | ||
| cross_origin_cookies: true, // Essential for session persistence in iframes | ||
| } | ||
| } | ||
| }, []) | ||
|
|
||
| useEffect(() => { | ||
| if (typeof window === 'undefined') return | ||
|
|
||
| const email = searchParams.get('user_email') | ||
| const nickname = searchParams.get('user_nickname') | ||
| const avatar = searchParams.get('user_avatar') | ||
| const sessionDataJson = searchParams.get('session_data') | ||
| const prefilledMessage = searchParams.get('prefilled_message') | ||
|
|
||
| const notifyParentReady = () => { | ||
| if (window.parent !== window) { | ||
| window.parent.postMessage( | ||
| { | ||
| type: 'CRISP_READY', | ||
| }, | ||
| window.location.origin | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| const setAllData = () => { | ||
| if (!window.$crisp) return false | ||
|
|
||
| // Check sessionStorage for reset flag (set during logout) | ||
| const needsReset = sessionStorage.getItem('crisp_needs_reset') | ||
| if (needsReset === 'true') { | ||
| window.$crisp.push(['do', 'session:reset']) | ||
| sessionStorage.removeItem('crisp_needs_reset') | ||
| } | ||
|
|
||
| // Set user identification | ||
| if (email) { | ||
| window.$crisp.push(['set', 'user:email', [email]]) | ||
| } | ||
| if (nickname) { | ||
| window.$crisp.push(['set', 'user:nickname', [nickname]]) | ||
| } | ||
| if (avatar) { | ||
| window.$crisp.push(['set', 'user:avatar', [avatar]]) | ||
| } | ||
|
|
||
| // Set session metadata for support agents | ||
| if (sessionDataJson) { | ||
| try { | ||
| const data = JSON.parse(sessionDataJson) | ||
| const sessionDataArray = [ | ||
| [ | ||
| ['username', data.username || ''], | ||
| ['user_id', data.user_id || ''], | ||
| ['full_name', data.full_name || ''], | ||
| ['grafana_dashboard', data.grafana_dashboard || ''], | ||
| ['wallet_address', data.wallet_address || ''], | ||
| ['bridge_user_id', data.bridge_user_id || ''], | ||
| ['manteca_user_id', data.manteca_user_id || ''], | ||
| ], | ||
| ] | ||
| window.$crisp.push(['set', 'session:data', sessionDataArray]) | ||
| } catch (e) { | ||
| console.error('[Crisp] Failed to parse session_data:', e) | ||
| } | ||
| } | ||
|
|
||
| if (prefilledMessage) { | ||
| window.$crisp.push(['set', 'message:text', [prefilledMessage]]) | ||
| } | ||
|
|
||
| // Wait for Crisp to be fully ready (session loaded and UI rendered) | ||
| window.$crisp.push(['on', 'session:loaded', notifyParentReady]) | ||
|
|
||
| // Fallback: notify after a delay if session:loaded doesn't fire | ||
| setTimeout(notifyParentReady, 1500) | ||
|
|
||
| return true | ||
| } | ||
|
|
||
| // Initialize data once Crisp loads | ||
| if (window.$crisp) { | ||
| setAllData() | ||
| } else { | ||
| const checkCrisp = setInterval(() => { | ||
| if (window.$crisp) { | ||
| setAllData() | ||
| clearInterval(checkCrisp) | ||
| } | ||
| }, 100) | ||
|
|
||
| setTimeout(() => clearInterval(checkCrisp), 5000) | ||
| } | ||
|
|
||
| // Listen for reset messages from parent window | ||
| const handleMessage = (event: MessageEvent) => { | ||
| if (event.origin !== window.location.origin) return | ||
|
|
||
| if (event.data.type === 'CRISP_RESET_SESSION' && window.$crisp) { | ||
| window.$crisp.push(['do', 'session:reset']) | ||
| } | ||
| } | ||
|
|
||
| window.addEventListener('message', handleMessage) | ||
| return () => window.removeEventListener('message', handleMessage) | ||
| }, [searchParams]) | ||
|
|
||
| return ( | ||
| <div className="h-full w-full"> | ||
| <Script strategy="afterInteractive" id="crisp-proxy-widget"> | ||
| {` | ||
| window.$crisp=[]; | ||
| window.CRISP_WEBSITE_ID="${CRISP_WEBSITE_ID}"; | ||
| (function(){ | ||
| d=document; | ||
| s=d.createElement("script"); | ||
| s.src="https://client.crisp.chat/l.js"; | ||
| s.async=1; | ||
| d.getElementsByTagName("head")[0].appendChild(s); | ||
| })(); | ||
| window.$crisp.push(["safe", true]); | ||
| `} | ||
| </Script> | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| export default function CrispProxyPage() { | ||
| return ( | ||
| <Suspense fallback={<div className="h-full w-full" />}> | ||
| <CrispProxyContent /> | ||
| </Suspense> | ||
| ) | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,6 @@ | ||
| /** | ||
| * Crisp chat integration configuration | ||
| */ | ||
|
|
||
| /** Crisp website ID for Peanut's support chat */ | ||
| export const CRISP_WEBSITE_ID = '916078be-a6af-4696-82cb-bc08d43d9125' |
This file contains hidden or 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,10 @@ | ||
| /** | ||
| * Support and debugging tool URLs | ||
| */ | ||
|
|
||
| /** Grafana dashboard for exploring user wallet activity */ | ||
| export const GRAFANA_DASHBOARD_BASE_URL = | ||
| 'https://teampeanut.grafana.net/d/ad31f645-81ca-4779-bfb2-bff8e03d9057/explore-peanut-wallet-user' | ||
|
|
||
| /** Arbiscan block explorer for viewing wallet addresses on Arbitrum */ | ||
| export const ARBISCAN_ADDRESS_BASE_URL = 'https://arbiscan.io/address' |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.