-
Notifications
You must be signed in to change notification settings - Fork 3
/
v1.js
162 lines (145 loc) · 4.91 KB
/
v1.js
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/**
* @typedef {import('../../client.js').ChatBotKitClient} ChatBotKitClient
*/
/**
* @template T
* @template U
* @typedef {import('../../client.js').ResponsePromise<T,U>} ResponsePromise
*/
/**
* @typedef {{
* name?: string,
* description?: string,
* theme?: string,
* layout?: string,
* title?: string,
* intro?: string,
* initial?: string,
* placeholder?: string,
* language?: string,
* origin?: string,
* stream?: boolean,
* verbose?: boolean,
* tools?: boolean,
* unfurl?: boolean,
* autoScroll?: boolean,
* startFirst?: boolean,
* contactCollection?: boolean,
* exportConversation?: boolean,
* restartConversation?: boolean,
* maxsimize?: boolean,
* messagePeek?: boolean,
* poweredBy?: boolean,
* sessionDuration?: number,
* meta?: Record<string,any>
* }} WidgetIntegrationOptions
*
* @typedef {WidgetIntegrationOptions & {
* id: string,
* createdAt: number,
* updatedAt: number
* }} WidgetInegrationInstance
*/
/**
* @typedef {{cursor?: string, order?: 'desc'|'asc', take?: number, meta?: Record<string,string>}} WidgetIntegrationListRequest
*
* @typedef {{items: WidgetInegrationInstance[]}} WidgetIntegrationListResponse
*
* @typedef {{
* type: 'item',
* data: WidgetInegrationInstance
* }} WidgetIntegrationListStreamItem
*
* @typedef {WidgetIntegrationListStreamItem} WidgetIntegrationListStreamType
*
* @param {ChatBotKitClient} client
* @param {WidgetIntegrationListRequest} [request]
* @returns {ResponsePromise<WidgetIntegrationListResponse,WidgetIntegrationListStreamType>}
*/
export function listWidgetIntegrations(client, request) {
let url = `/api/v1/integration/widget/list`
/** @typedef {import('../../types/api/v1.js').operations['listWidgetIntegrations']['responses']['200']['content']['application/json']} T */
/** @typedef {import('../../types/api/v1.js').operations['listWidgetIntegrations']['responses']['200']['content']['application/jsonl']} U */
/** @type {ResponsePromise<T,U>} */
const response = client.clientFetch(url, { query: request })
return response
}
/**
* @typedef {WidgetInegrationInstance & {
* }} WidgetIntegrationFetchResponse
*
* @param {ChatBotKitClient} client
* @param {string} widgetId
* @returns {Promise<WidgetIntegrationFetchResponse>}
*/
export async function fetchWidgetIntegration(client, widgetId) {
const url = `/api/v1/integration/widget/${widgetId}/fetch`
/** @type {import('../../types/api/v1.js').operations['fetchWidgetIntegration']['responses']['200']['content']['application/json']} */
const response = await client.clientFetch(url)
return response
}
/**
* @typedef {WidgetIntegrationOptions & {
* }} WidgetIntegrationCreateRequest
*
* @typedef {{
* id: string
* }} WidgetIntegrationCreateResponse
*
* @param {ChatBotKitClient} client
* @param {WidgetIntegrationCreateRequest} request
* @returns {Promise<WidgetIntegrationCreateResponse>}
*/
export async function createWidgetIntegration(client, request) {
const url = `/api/v1/integration/widget/create`
/** @type {import('../../types/api/v1.js').operations['createWidgetIntegration']['responses']['200']['content']['application/json']} */
const response = await client.clientFetch(url, {
/** @type {import('../../types/api/v1.js').operations['createWidgetIntegration']['requestBody']['content']['application/json']} */
record: {
...request,
},
})
return response
}
/**
* @typedef {WidgetIntegrationOptions & {
* }} WidgetIntegrationUpdateRequest
*
* @typedef {{
* id: string
* }} WidgetIntegrationUpdateResponse
*
* @param {ChatBotKitClient} client
* @param {string} widgetId
* @param {WidgetIntegrationUpdateRequest} request
* @returns {Promise<WidgetIntegrationUpdateResponse>}
*/
export async function updateWidgetIntegration(client, widgetId, request) {
const url = `/api/v1/integration/widget/${widgetId}/update`
/** @type {import('../../types/api/v1.js').operations['updateWidgetIntegration']['responses']['200']['content']['application/json']} */
const response = await client.clientFetch(url, {
/** @type {import('../../types/api/v1.js').operations['updateWidgetIntegration']['requestBody']['content']['application/json']} */
record: {
...request,
},
})
return response
}
/**
* @typedef {{
* id: string
* }} WidgetIntegrationDeleteResponse
*
* @param {ChatBotKitClient} client
* @param {string} widgetId
* @returns {Promise<WidgetIntegrationDeleteResponse>}
*/
export async function deleteWidgetIntegration(client, widgetId) {
const url = `/api/v1/integration/widget/${widgetId}/delete`
/** @type {import('../../types/api/v1.js').operations['deleteWidgetIntegration']['responses']['200']['content']['application/json']} */
const response = await client.clientFetch(url, {
/** @type {import('../../types/api/v1.js').operations['deleteWidgetIntegration']['requestBody']['content']['application/json']} */
record: {},
})
return response
}