dify/web/app/components/base/zendesk/utils.ts
Stephen Zhou eb71e47f3b
chore: migrate linting to vp lint with ESLint fallback (#38834)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-07-13 06:41:53 +00:00

55 lines
1.2 KiB
TypeScript

import { IS_CE_EDITION } from '@/config'
type ConversationField = {
id: string
value: unknown
}
declare global {
// oxlint-disable-next-line typescript/consistent-type-definitions
interface Window {
zE?: (
command: string,
value: string,
payload?: ConversationField[] | string | string[] | (() => unknown),
callback?: () => unknown,
) => void
}
}
export const setZendeskConversationFields = (
fields: ConversationField[],
callback?: () => unknown,
) => {
if (!IS_CE_EDITION && window.zE)
window.zE('messenger:set', 'conversationFields', fields, callback)
}
type OpenZendeskWindowOptions = {
interval?: number
retries?: number
}
const openZendeskWindowOnce = () => {
if (IS_CE_EDITION || !window.zE) return false
window.zE('messenger', 'show')
window.zE('messenger', 'open')
return true
}
export const openZendeskWindow = ({
interval = 100,
retries = 20,
}: OpenZendeskWindowOptions = {}) => {
if (IS_CE_EDITION) return
if (openZendeskWindowOnce()) return
let attempts = 0
const timer = window.setInterval(() => {
attempts += 1
if (openZendeskWindowOnce() || attempts >= retries) window.clearInterval(timer)
}, interval)
}