-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathwindow.ts
42 lines (36 loc) · 1.01 KB
/
window.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/* eslint-disable solid/reactivity */
type BotProps = {
chatflowid: string
apiHost?: string
authToken?: string
chatflowConfig?: Record<string, unknown>
}
export const initFull = (props: BotProps & { id?: string }) => {
const fullElement = props.id
? document.getElementById(props.id)
: document.querySelector('flowise-fullchatbot')
if (!fullElement) throw new Error('<flowise-fullchatbot> element not found.')
Object.assign(fullElement, props)
}
export const init = (props: BotProps) => {
const element = document.createElement('flowise-chatbot')
Object.assign(element, props)
document.body.appendChild(element)
}
type Chatbot = {
initFull: typeof initFull
init: typeof init
}
declare const window:
| {
Chatbot: Chatbot | undefined
}
| undefined
export const parseChatbot = () => ({
initFull,
init
})
export const injectChatbotInWindow = (bot: Chatbot) => {
if (typeof window === 'undefined') return
window.Chatbot = { ...bot }
}