@dinghy-chat/sdk 0.0.0-stage → 0.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +135 -2
- package/dist/events.d.ts +25 -0
- package/dist/identity.d.ts +11 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.js +402 -0
- package/dist/openapi.d.ts +5946 -0
- package/dist/request.d.ts +95 -0
- package/dist/resources.d.ts +525 -0
- package/dist/webhooks.d.ts +52 -0
- package/package.json +32 -4
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { components, paths } from "./openapi.ts";
|
|
2
|
+
type Method = "get" | "post" | "put" | "patch" | "delete";
|
|
3
|
+
type Schemas = components["schemas"];
|
|
4
|
+
export type ErrorCode = Schemas["Error"]["error"]["code"] | "unexpected_response";
|
|
5
|
+
/** Anything that answers like `fetch`, such as `app.request` in a test. */
|
|
6
|
+
export type Fetch = (input: string, init: RequestInit) => Response | Promise<Response>;
|
|
7
|
+
/** Every route of a workspace. The SDK fills `{workspaceId}` from the API key. */
|
|
8
|
+
export type WorkspacePath = Extract<keyof paths, `/v1/operator/workspaces/{workspaceId}${string}`>;
|
|
9
|
+
/** The methods a path has. */
|
|
10
|
+
export type MethodOf<P extends WorkspacePath> = {
|
|
11
|
+
[M in Method]: [NonNullable<paths[P][M]>] extends [never] ? never : M;
|
|
12
|
+
}[Method];
|
|
13
|
+
type Operation<P extends WorkspacePath, M extends Method> = NonNullable<paths[P][M]>;
|
|
14
|
+
type PathParams<O> = O extends {
|
|
15
|
+
parameters: {
|
|
16
|
+
path: infer T;
|
|
17
|
+
};
|
|
18
|
+
} ? Omit<T, "workspaceId"> : never;
|
|
19
|
+
type Query<O> = O extends {
|
|
20
|
+
parameters: {
|
|
21
|
+
query?: infer Q;
|
|
22
|
+
};
|
|
23
|
+
} ? Q : never;
|
|
24
|
+
type JsonBody<O> = O extends {
|
|
25
|
+
requestBody: {
|
|
26
|
+
content: {
|
|
27
|
+
"application/json": infer B;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
} ? B : O extends {
|
|
31
|
+
requestBody?: {
|
|
32
|
+
content: {
|
|
33
|
+
"application/json": infer B;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
} ? B | undefined : never;
|
|
37
|
+
type SuccessStatus = 200 | 201 | 202;
|
|
38
|
+
type Success<O> = O extends {
|
|
39
|
+
responses: infer R;
|
|
40
|
+
} ? {
|
|
41
|
+
[S in keyof R]: S extends SuccessStatus ? R[S] extends {
|
|
42
|
+
content: {
|
|
43
|
+
"application/json": infer J;
|
|
44
|
+
};
|
|
45
|
+
} ? J : never : never;
|
|
46
|
+
}[keyof R] : never;
|
|
47
|
+
/** A field that is required when its type has a required key, optional when not, gone if never. */
|
|
48
|
+
type Field<K extends string, T> = [T] extends [never] ? unknown : Partial<T> extends T ? {
|
|
49
|
+
[Key in K]?: T;
|
|
50
|
+
} : {
|
|
51
|
+
[Key in K]: T;
|
|
52
|
+
};
|
|
53
|
+
type RequestOptions<O> = Field<"path", PathParams<O>> & Field<"query", Query<O>> & Field<"body", JsonBody<O>> & {
|
|
54
|
+
/** Raw bytes for an upload, sent instead of a JSON body. */
|
|
55
|
+
bytes?: Blob | Uint8Array<ArrayBuffer>;
|
|
56
|
+
};
|
|
57
|
+
export type RequestArgs<P extends WorkspacePath, M extends MethodOf<P>> = Partial<RequestOptions<Operation<P, M>>> extends RequestOptions<Operation<P, M>> ? [options?: RequestOptions<Operation<P, M>>] : [options: RequestOptions<Operation<P, M>>];
|
|
58
|
+
export type Answer<P extends WorkspacePath, M extends MethodOf<P>> = Success<Operation<P, M>>;
|
|
59
|
+
/** A request the server refused, with its `{ error: { code, message } }`. */
|
|
60
|
+
export declare class DinghyError extends Error {
|
|
61
|
+
readonly status: number;
|
|
62
|
+
readonly code: ErrorCode;
|
|
63
|
+
constructor(status: number, code: ErrorCode, message: string);
|
|
64
|
+
}
|
|
65
|
+
export declare const RETRY_STATUSES: Set<number>;
|
|
66
|
+
export declare const wait: (ms: number) => Promise<unknown>;
|
|
67
|
+
/** The server's error, or a generic one when the body is not the API's error shape. */
|
|
68
|
+
export declare function errorOf(response: Response): Promise<DinghyError>;
|
|
69
|
+
interface Raw {
|
|
70
|
+
method: Method;
|
|
71
|
+
url: string;
|
|
72
|
+
headers: Record<string, string>;
|
|
73
|
+
body?: string | Blob | Uint8Array<ArrayBuffer>;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Sends with retries for 429, 503 and network errors. A network error is retried only when a
|
|
77
|
+
* repeat cannot do the work twice: any method but POST, or a POST that carries a `clientId`.
|
|
78
|
+
*/
|
|
79
|
+
export declare function withRetries(fetch: Fetch, raw: Raw, isRepeatable: boolean): Promise<Response>;
|
|
80
|
+
interface Target {
|
|
81
|
+
baseUrl: string;
|
|
82
|
+
workspaceId: string;
|
|
83
|
+
}
|
|
84
|
+
interface LooseOptions {
|
|
85
|
+
path?: object;
|
|
86
|
+
query?: object;
|
|
87
|
+
body?: object;
|
|
88
|
+
bytes?: Blob | Uint8Array<ArrayBuffer>;
|
|
89
|
+
}
|
|
90
|
+
/** One API call: the URL, the bearer token, JSON in and out, retries and errors. */
|
|
91
|
+
export declare function call(client: Target & {
|
|
92
|
+
apiKey: string;
|
|
93
|
+
fetch: Fetch;
|
|
94
|
+
}, method: Method, template: string, options: LooseOptions): Promise<unknown>;
|
|
95
|
+
export {};
|
|
@@ -0,0 +1,525 @@
|
|
|
1
|
+
import type { components, paths } from "./openapi.ts";
|
|
2
|
+
import type { Answer, MethodOf, RequestArgs, WorkspacePath } from "./request.ts";
|
|
3
|
+
/** The typed request that every resource group calls. */
|
|
4
|
+
export type Request = <P extends WorkspacePath, M extends MethodOf<P>>(method: M, path: P, ...args: RequestArgs<P, M>) => Promise<Answer<P, M>>;
|
|
5
|
+
type JsonOf<T> = T extends {
|
|
6
|
+
content: {
|
|
7
|
+
"application/json": infer B;
|
|
8
|
+
};
|
|
9
|
+
} ? B : never;
|
|
10
|
+
type Body<P extends WorkspacePath, M extends MethodOf<P>> = JsonOf<NonNullable<NonNullable<paths[P][M]>["requestBody"]>>;
|
|
11
|
+
type QueryOf<P extends WorkspacePath, M extends MethodOf<P>> = NonNullable<NonNullable<paths[P][M]>["parameters"]["query"]>;
|
|
12
|
+
/** A send's body, where `clientId` is optional: the SDK makes one. */
|
|
13
|
+
type Send<T> = Omit<T, "clientId"> & {
|
|
14
|
+
clientId?: string;
|
|
15
|
+
};
|
|
16
|
+
declare const IN_WORKSPACE = "/v1/operator/workspaces/{workspaceId}";
|
|
17
|
+
declare const CONVERSATIONS: "/v1/operator/workspaces/{workspaceId}/conversations";
|
|
18
|
+
declare const CONVERSATION: "/v1/operator/workspaces/{workspaceId}/conversations/{conversationId}";
|
|
19
|
+
declare const MESSAGES: "/v1/operator/workspaces/{workspaceId}/conversations/{conversationId}/messages";
|
|
20
|
+
declare const CONTACT_BY_USER: "/v1/operator/workspaces/{workspaceId}/contacts/by-user/{userId}";
|
|
21
|
+
declare const OUTBOUND: "/v1/operator/workspaces/{workspaceId}/outbound-messages";
|
|
22
|
+
declare const WEBHOOKS: "/v1/operator/workspaces/{workspaceId}/webhooks";
|
|
23
|
+
declare const WEBHOOK: "/v1/operator/workspaces/{workspaceId}/webhooks/{webhookId}";
|
|
24
|
+
type Reply = Send<Omit<Body<typeof MESSAGES, "post">, "note" | "mentions">>;
|
|
25
|
+
type Note = Send<Omit<Body<typeof MESSAGES, "post">, "note">>;
|
|
26
|
+
type Upload = {
|
|
27
|
+
file: Blob | Uint8Array<ArrayBuffer>;
|
|
28
|
+
} & Send<QueryOf<`${typeof CONVERSATION}/uploads`, "post">>;
|
|
29
|
+
type Handoff = Send<Body<`${typeof CONVERSATION}/handoff`, "post">>;
|
|
30
|
+
export declare function conversations(request: Request): {
|
|
31
|
+
list: (query?: QueryOf<typeof CONVERSATIONS, "get">) => Promise<{
|
|
32
|
+
conversations: components["schemas"]["Conversation"][];
|
|
33
|
+
hasMore: boolean;
|
|
34
|
+
waiting: number;
|
|
35
|
+
snoozeEndsInMs: number | null;
|
|
36
|
+
openBy: {
|
|
37
|
+
all: number;
|
|
38
|
+
mine: number;
|
|
39
|
+
unassigned: number;
|
|
40
|
+
};
|
|
41
|
+
}>;
|
|
42
|
+
search: (q: string) => Promise<{
|
|
43
|
+
conversations: components["schemas"]["Conversation"][];
|
|
44
|
+
}>;
|
|
45
|
+
messages: (conversationId: string, query?: QueryOf<typeof MESSAGES, "get">) => Promise<{
|
|
46
|
+
conversation: components["schemas"]["Conversation"];
|
|
47
|
+
messages: components["schemas"]["InboxMessage"][];
|
|
48
|
+
hasMore: boolean;
|
|
49
|
+
visitorOnline: boolean | null;
|
|
50
|
+
visitorPages: components["schemas"]["PageView"][];
|
|
51
|
+
welcome: components["schemas"]["WelcomeChat"];
|
|
52
|
+
receipts: components["schemas"]["ReplyReceipts"];
|
|
53
|
+
}>;
|
|
54
|
+
reply: (conversationId: string, input: Reply) => Promise<({
|
|
55
|
+
id: string;
|
|
56
|
+
conversationId: string;
|
|
57
|
+
seq: string;
|
|
58
|
+
kind: "text" | "image" | "closed" | "reopened" | "file" | "note";
|
|
59
|
+
fromVisitor: boolean;
|
|
60
|
+
authorOperatorId: string | null;
|
|
61
|
+
authorApiKeyId: string | null;
|
|
62
|
+
authorName: string | null;
|
|
63
|
+
clientId: string;
|
|
64
|
+
body: string | null;
|
|
65
|
+
attachment: components["schemas"]["Attachment"];
|
|
66
|
+
replyTo: components["schemas"]["Quote"];
|
|
67
|
+
editedAt: string | null;
|
|
68
|
+
deleted: boolean;
|
|
69
|
+
readAt: string | null;
|
|
70
|
+
handoff: {
|
|
71
|
+
operatorId: string | null;
|
|
72
|
+
} | null;
|
|
73
|
+
mentions: string[];
|
|
74
|
+
outboundId: string | null;
|
|
75
|
+
sender: "team" | {
|
|
76
|
+
operatorId: string;
|
|
77
|
+
name: string | null;
|
|
78
|
+
} | null;
|
|
79
|
+
button: components["schemas"]["ChosenButton"];
|
|
80
|
+
createdAt: string;
|
|
81
|
+
} & ({
|
|
82
|
+
via: "api" | "mcp" | "draft" | null;
|
|
83
|
+
} | {
|
|
84
|
+
via: "email";
|
|
85
|
+
fromAddress: string | null;
|
|
86
|
+
})) | {
|
|
87
|
+
draft: components["schemas"]["Draft"];
|
|
88
|
+
}>;
|
|
89
|
+
note: (conversationId: string, input: Note) => Promise<({
|
|
90
|
+
id: string;
|
|
91
|
+
conversationId: string;
|
|
92
|
+
seq: string;
|
|
93
|
+
kind: "text" | "image" | "closed" | "reopened" | "file" | "note";
|
|
94
|
+
fromVisitor: boolean;
|
|
95
|
+
authorOperatorId: string | null;
|
|
96
|
+
authorApiKeyId: string | null;
|
|
97
|
+
authorName: string | null;
|
|
98
|
+
clientId: string;
|
|
99
|
+
body: string | null;
|
|
100
|
+
attachment: components["schemas"]["Attachment"];
|
|
101
|
+
replyTo: components["schemas"]["Quote"];
|
|
102
|
+
editedAt: string | null;
|
|
103
|
+
deleted: boolean;
|
|
104
|
+
readAt: string | null;
|
|
105
|
+
handoff: {
|
|
106
|
+
operatorId: string | null;
|
|
107
|
+
} | null;
|
|
108
|
+
mentions: string[];
|
|
109
|
+
outboundId: string | null;
|
|
110
|
+
sender: "team" | {
|
|
111
|
+
operatorId: string;
|
|
112
|
+
name: string | null;
|
|
113
|
+
} | null;
|
|
114
|
+
button: components["schemas"]["ChosenButton"];
|
|
115
|
+
createdAt: string;
|
|
116
|
+
} & ({
|
|
117
|
+
via: "api" | "mcp" | "draft" | null;
|
|
118
|
+
} | {
|
|
119
|
+
via: "email";
|
|
120
|
+
fromAddress: string | null;
|
|
121
|
+
})) | {
|
|
122
|
+
draft: components["schemas"]["Draft"];
|
|
123
|
+
}>;
|
|
124
|
+
upload: (conversationId: string, { file, ...query }: Upload) => Promise<{
|
|
125
|
+
id: string;
|
|
126
|
+
conversationId: string;
|
|
127
|
+
seq: string;
|
|
128
|
+
kind: "text" | "image" | "closed" | "reopened" | "file" | "note";
|
|
129
|
+
fromVisitor: boolean;
|
|
130
|
+
authorOperatorId: string | null;
|
|
131
|
+
authorApiKeyId: string | null;
|
|
132
|
+
authorName: string | null;
|
|
133
|
+
clientId: string;
|
|
134
|
+
body: string | null;
|
|
135
|
+
attachment: components["schemas"]["Attachment"];
|
|
136
|
+
replyTo: components["schemas"]["Quote"];
|
|
137
|
+
editedAt: string | null;
|
|
138
|
+
deleted: boolean;
|
|
139
|
+
readAt: string | null;
|
|
140
|
+
handoff: {
|
|
141
|
+
operatorId: string | null;
|
|
142
|
+
} | null;
|
|
143
|
+
mentions: string[];
|
|
144
|
+
outboundId: string | null;
|
|
145
|
+
sender: "team" | {
|
|
146
|
+
operatorId: string;
|
|
147
|
+
name: string | null;
|
|
148
|
+
} | null;
|
|
149
|
+
button: components["schemas"]["ChosenButton"];
|
|
150
|
+
createdAt: string;
|
|
151
|
+
} & ({
|
|
152
|
+
via: "api" | "mcp" | "draft" | null;
|
|
153
|
+
} | {
|
|
154
|
+
via: "email";
|
|
155
|
+
fromAddress: string | null;
|
|
156
|
+
})>;
|
|
157
|
+
receipt: (conversationId: string, messageId: string) => Promise<{
|
|
158
|
+
readAt: string | null;
|
|
159
|
+
emailedAt: string | null;
|
|
160
|
+
}>;
|
|
161
|
+
close: (conversationId: string) => Promise<{
|
|
162
|
+
ok: true;
|
|
163
|
+
}>;
|
|
164
|
+
reopen: (conversationId: string) => Promise<{
|
|
165
|
+
ok: true;
|
|
166
|
+
}>;
|
|
167
|
+
snooze: (conversationId: string, snooze: components["schemas"]["Snooze"]) => Promise<{
|
|
168
|
+
ok: true;
|
|
169
|
+
}>;
|
|
170
|
+
/** Assigns a member by operator ID, or unassigns with null. */
|
|
171
|
+
assign: (conversationId: string, operatorId: string | null) => Promise<{
|
|
172
|
+
ok: true;
|
|
173
|
+
}>;
|
|
174
|
+
addLabel: (conversationId: string, labelId: string) => Promise<{
|
|
175
|
+
ok: true;
|
|
176
|
+
}>;
|
|
177
|
+
removeLabel: (conversationId: string, labelId: string) => Promise<{
|
|
178
|
+
ok: true;
|
|
179
|
+
}>;
|
|
180
|
+
handoff: (conversationId: string, input: Handoff) => Promise<{
|
|
181
|
+
visitorMessage: components["schemas"]["HandoffMessage"];
|
|
182
|
+
} | {
|
|
183
|
+
visitorMessage: components["schemas"]["HandoffMessage"];
|
|
184
|
+
}>;
|
|
185
|
+
typing: (conversationId: string, typing?: boolean) => Promise<{
|
|
186
|
+
ok: true;
|
|
187
|
+
}>;
|
|
188
|
+
};
|
|
189
|
+
type Upsert = {
|
|
190
|
+
userId: string;
|
|
191
|
+
} & Body<typeof CONTACT_BY_USER, "put">;
|
|
192
|
+
export declare function contacts(request: Request): {
|
|
193
|
+
/** Creates or updates the contact with this user ID, as a host token would. */
|
|
194
|
+
upsert: ({ userId, ...body }: Upsert) => Promise<{
|
|
195
|
+
id: string;
|
|
196
|
+
name: string | null;
|
|
197
|
+
email: string | null;
|
|
198
|
+
userId: string | null;
|
|
199
|
+
signedIn: boolean;
|
|
200
|
+
company: string | null;
|
|
201
|
+
country: string | null;
|
|
202
|
+
timeZone: string | null;
|
|
203
|
+
device: string | null;
|
|
204
|
+
lastPage: string | null;
|
|
205
|
+
lastSeenAt: string | null;
|
|
206
|
+
createdAt: string;
|
|
207
|
+
conversationCount: number;
|
|
208
|
+
blocked: boolean;
|
|
209
|
+
} & {
|
|
210
|
+
online: boolean | null;
|
|
211
|
+
attributes: {
|
|
212
|
+
[key: string]: unknown;
|
|
213
|
+
} | null;
|
|
214
|
+
pageContext: components["schemas"]["PageContext"] & (Record<string, never> | null);
|
|
215
|
+
note: string | null;
|
|
216
|
+
conversations: {
|
|
217
|
+
id: string;
|
|
218
|
+
status: "open" | "closed";
|
|
219
|
+
createdAt: string;
|
|
220
|
+
updatedAt: string;
|
|
221
|
+
lastBody: string | null;
|
|
222
|
+
lastKind: "text" | "image" | "file" | null;
|
|
223
|
+
messageCount: number;
|
|
224
|
+
assigneeName: string | null;
|
|
225
|
+
closedBy: string | null;
|
|
226
|
+
firstReplySeconds: number | null;
|
|
227
|
+
}[];
|
|
228
|
+
pages: {
|
|
229
|
+
path: string;
|
|
230
|
+
title: string | null;
|
|
231
|
+
viewedAt: string;
|
|
232
|
+
}[];
|
|
233
|
+
}>;
|
|
234
|
+
};
|
|
235
|
+
type Cancel = {
|
|
236
|
+
id: string;
|
|
237
|
+
} | Body<`${typeof OUTBOUND}/cancel`, "post">;
|
|
238
|
+
export declare function outboundMessages(request: Request): {
|
|
239
|
+
send: (input: Send<Body<typeof OUTBOUND, "post">>) => Promise<{
|
|
240
|
+
outboundMessage: components["schemas"]["OutboundMessage"];
|
|
241
|
+
} | {
|
|
242
|
+
outboundMessage: components["schemas"]["OutboundMessage"];
|
|
243
|
+
}>;
|
|
244
|
+
get: (id: string) => Promise<{
|
|
245
|
+
outboundMessage: components["schemas"]["OutboundMessage"];
|
|
246
|
+
}>;
|
|
247
|
+
list: (query?: QueryOf<typeof OUTBOUND, "get">) => Promise<{
|
|
248
|
+
outboundMessages: components["schemas"]["OutboundMessage"][];
|
|
249
|
+
next: string | null;
|
|
250
|
+
}>;
|
|
251
|
+
/** Cancels by ID, or by the visitor and the `dedupeKey` it was sent with. */
|
|
252
|
+
cancel: (input: Cancel) => Promise<{
|
|
253
|
+
outboundMessage: components["schemas"]["OutboundMessage"];
|
|
254
|
+
}>;
|
|
255
|
+
};
|
|
256
|
+
type NewWebhook = Body<typeof WEBHOOKS, "post">;
|
|
257
|
+
/** The webhook routes, which need a Full access (setup) key. */
|
|
258
|
+
export declare function webhookRoutes(request: Request): {
|
|
259
|
+
list: () => Promise<{
|
|
260
|
+
webhooks: components["schemas"]["Webhook"][];
|
|
261
|
+
}>;
|
|
262
|
+
create: (body: NewWebhook) => Promise<{
|
|
263
|
+
id: string;
|
|
264
|
+
url: string;
|
|
265
|
+
events: ("conversation.created" | "message.created" | "message.updated" | "message.deleted" | "conversation.closed" | "conversation.reopened" | "conversation.assigned" | "conversation.handoff" | "conversation.given_back" | "conversation.labeled" | "outbound_message.sent" | "outbound_message.delivered" | "outbound_message.read" | "outbound_message.clicked" | "outbound_message.replied" | "outbound_message.dismissed" | "outbound_message.cancelled" | "outbound_message.expired")[];
|
|
266
|
+
enabled: boolean;
|
|
267
|
+
createdBy: {
|
|
268
|
+
kind: "operator" | "key";
|
|
269
|
+
name: string;
|
|
270
|
+
} | null;
|
|
271
|
+
createdAt: string;
|
|
272
|
+
} & {
|
|
273
|
+
secret: string;
|
|
274
|
+
}>;
|
|
275
|
+
update: (webhookId: string, body: Body<typeof WEBHOOK, "patch">) => Promise<{
|
|
276
|
+
id: string;
|
|
277
|
+
url: string;
|
|
278
|
+
events: ("conversation.created" | "message.created" | "message.updated" | "message.deleted" | "conversation.closed" | "conversation.reopened" | "conversation.assigned" | "conversation.handoff" | "conversation.given_back" | "conversation.labeled" | "outbound_message.sent" | "outbound_message.delivered" | "outbound_message.read" | "outbound_message.clicked" | "outbound_message.replied" | "outbound_message.dismissed" | "outbound_message.cancelled" | "outbound_message.expired")[];
|
|
279
|
+
enabled: boolean;
|
|
280
|
+
createdBy: {
|
|
281
|
+
kind: "operator" | "key";
|
|
282
|
+
name: string;
|
|
283
|
+
} | null;
|
|
284
|
+
createdAt: string;
|
|
285
|
+
}>;
|
|
286
|
+
delete: (webhookId: string) => Promise<{
|
|
287
|
+
ok: true;
|
|
288
|
+
}>;
|
|
289
|
+
rotateSecret: (webhookId: string) => Promise<{
|
|
290
|
+
id: string;
|
|
291
|
+
url: string;
|
|
292
|
+
events: ("conversation.created" | "message.created" | "message.updated" | "message.deleted" | "conversation.closed" | "conversation.reopened" | "conversation.assigned" | "conversation.handoff" | "conversation.given_back" | "conversation.labeled" | "outbound_message.sent" | "outbound_message.delivered" | "outbound_message.read" | "outbound_message.clicked" | "outbound_message.replied" | "outbound_message.dismissed" | "outbound_message.cancelled" | "outbound_message.expired")[];
|
|
293
|
+
enabled: boolean;
|
|
294
|
+
createdBy: {
|
|
295
|
+
kind: "operator" | "key";
|
|
296
|
+
name: string;
|
|
297
|
+
} | null;
|
|
298
|
+
createdAt: string;
|
|
299
|
+
} & {
|
|
300
|
+
secret: string;
|
|
301
|
+
}>;
|
|
302
|
+
test: (webhookId: string) => Promise<{
|
|
303
|
+
delivered: boolean;
|
|
304
|
+
status: number | null;
|
|
305
|
+
error: string | null;
|
|
306
|
+
}>;
|
|
307
|
+
deliveries: (webhookId: string) => Promise<{
|
|
308
|
+
deliveries: components["schemas"]["WebhookDelivery"][];
|
|
309
|
+
}>;
|
|
310
|
+
replay: (webhookId: string, deliveryId: string) => Promise<{
|
|
311
|
+
delivery: components["schemas"]["WebhookDelivery"];
|
|
312
|
+
}>;
|
|
313
|
+
};
|
|
314
|
+
/** The install, sites, widget, business hours and test visitor routes, for a setup key. */
|
|
315
|
+
export declare function setup(request: Request): {
|
|
316
|
+
snippet: (query: QueryOf<`${typeof IN_WORKSPACE}/install/snippet`, "get">) => Promise<{
|
|
317
|
+
framework: "html" | "nextjs" | "react" | "vue" | "rails" | "laravel" | "wordpress";
|
|
318
|
+
code: string;
|
|
319
|
+
file: string;
|
|
320
|
+
placement: string;
|
|
321
|
+
notes: string[];
|
|
322
|
+
publicKey: string;
|
|
323
|
+
serverUrl: string;
|
|
324
|
+
}>;
|
|
325
|
+
checkInstall: (query: QueryOf<`${typeof IN_WORKSPACE}/install/check`, "get">) => Promise<{
|
|
326
|
+
allowed: boolean | null;
|
|
327
|
+
widgetSeenAt: string | null;
|
|
328
|
+
sites: {
|
|
329
|
+
origin: string;
|
|
330
|
+
allowed: boolean;
|
|
331
|
+
firstSeenAt: string | null;
|
|
332
|
+
lastSeenAt: string | null;
|
|
333
|
+
}[];
|
|
334
|
+
refused: {
|
|
335
|
+
origin: string;
|
|
336
|
+
lastSeenAt: string;
|
|
337
|
+
}[];
|
|
338
|
+
liveTabs: number | null;
|
|
339
|
+
nextStep: string;
|
|
340
|
+
}>;
|
|
341
|
+
identitySetup: (query: QueryOf<`${typeof IN_WORKSPACE}/install/identity`, "get">) => Promise<{
|
|
342
|
+
language: "typescript" | "python" | "ruby" | "php" | "go";
|
|
343
|
+
explanation: string[];
|
|
344
|
+
serverFile: string;
|
|
345
|
+
serverCode: string;
|
|
346
|
+
browserCode: string;
|
|
347
|
+
secretNote: string;
|
|
348
|
+
publicKey: string;
|
|
349
|
+
}>;
|
|
350
|
+
sites: () => Promise<{
|
|
351
|
+
sites: string[];
|
|
352
|
+
}>;
|
|
353
|
+
addSite: (origin: string) => Promise<{
|
|
354
|
+
sites: string[];
|
|
355
|
+
}>;
|
|
356
|
+
removeSite: (origin: string) => Promise<{
|
|
357
|
+
sites: string[];
|
|
358
|
+
}>;
|
|
359
|
+
widget: () => Promise<{
|
|
360
|
+
title: string | null;
|
|
361
|
+
greeting: string | null;
|
|
362
|
+
away: string | null;
|
|
363
|
+
primary: string | null;
|
|
364
|
+
accent: string | null;
|
|
365
|
+
position: "left" | "right";
|
|
366
|
+
theme: "light" | "dark" | "auto";
|
|
367
|
+
launcher: "boat" | "bubble" | "hidden" | "label" | "square";
|
|
368
|
+
mascot: boolean;
|
|
369
|
+
radius: number;
|
|
370
|
+
emailAsk: "off" | "after_first" | "before_first";
|
|
371
|
+
branding: boolean;
|
|
372
|
+
sound: boolean;
|
|
373
|
+
transcript: boolean;
|
|
374
|
+
visitorFiles: boolean;
|
|
375
|
+
headerFaces: "online" | "repliers" | "chosen" | "none";
|
|
376
|
+
headerFaceCount: number;
|
|
377
|
+
headerDot: boolean;
|
|
378
|
+
headerStatus: "presence" | "reply_time";
|
|
379
|
+
language: "visitor" | "en" | "fr" | "es";
|
|
380
|
+
headerMembers: string[];
|
|
381
|
+
} & {
|
|
382
|
+
typingPreview: boolean;
|
|
383
|
+
logoUrl: string | null;
|
|
384
|
+
team: {
|
|
385
|
+
id: string;
|
|
386
|
+
name: string;
|
|
387
|
+
pictureUrl: string | null;
|
|
388
|
+
}[];
|
|
389
|
+
faces: {
|
|
390
|
+
id: string;
|
|
391
|
+
name: string;
|
|
392
|
+
pictureUrl: string | null;
|
|
393
|
+
}[];
|
|
394
|
+
hours: {
|
|
395
|
+
timeZone: string;
|
|
396
|
+
week: components["schemas"]["BusinessWeek"];
|
|
397
|
+
} | null;
|
|
398
|
+
}>;
|
|
399
|
+
updateWidget: (body: Body<`${typeof IN_WORKSPACE}/widget`, "put">) => Promise<{
|
|
400
|
+
title: string | null;
|
|
401
|
+
greeting: string | null;
|
|
402
|
+
away: string | null;
|
|
403
|
+
primary: string | null;
|
|
404
|
+
accent: string | null;
|
|
405
|
+
position: "left" | "right";
|
|
406
|
+
theme: "light" | "dark" | "auto";
|
|
407
|
+
launcher: "boat" | "bubble" | "hidden" | "label" | "square";
|
|
408
|
+
mascot: boolean;
|
|
409
|
+
radius: number;
|
|
410
|
+
emailAsk: "off" | "after_first" | "before_first";
|
|
411
|
+
branding: boolean;
|
|
412
|
+
sound: boolean;
|
|
413
|
+
transcript: boolean;
|
|
414
|
+
visitorFiles: boolean;
|
|
415
|
+
headerFaces: "online" | "repliers" | "chosen" | "none";
|
|
416
|
+
headerFaceCount: number;
|
|
417
|
+
headerDot: boolean;
|
|
418
|
+
headerStatus: "presence" | "reply_time";
|
|
419
|
+
language: "visitor" | "en" | "fr" | "es";
|
|
420
|
+
headerMembers: string[];
|
|
421
|
+
} & {
|
|
422
|
+
typingPreview: boolean;
|
|
423
|
+
logoUrl: string | null;
|
|
424
|
+
team: {
|
|
425
|
+
id: string;
|
|
426
|
+
name: string;
|
|
427
|
+
pictureUrl: string | null;
|
|
428
|
+
}[];
|
|
429
|
+
faces: {
|
|
430
|
+
id: string;
|
|
431
|
+
name: string;
|
|
432
|
+
pictureUrl: string | null;
|
|
433
|
+
}[];
|
|
434
|
+
hours: {
|
|
435
|
+
timeZone: string;
|
|
436
|
+
week: components["schemas"]["BusinessWeek"];
|
|
437
|
+
} | null;
|
|
438
|
+
}>;
|
|
439
|
+
businessHours: () => Promise<{
|
|
440
|
+
enabled: boolean;
|
|
441
|
+
timeZone: string;
|
|
442
|
+
week: components["schemas"]["BusinessWeek"];
|
|
443
|
+
} | null>;
|
|
444
|
+
updateBusinessHours: (body: Body<`${typeof IN_WORKSPACE}/business-hours`, "put">) => Promise<{
|
|
445
|
+
enabled: boolean;
|
|
446
|
+
timeZone: string;
|
|
447
|
+
week: components["schemas"]["BusinessWeek"];
|
|
448
|
+
} | null>;
|
|
449
|
+
testVisitorMessage: (body: Body<`${typeof IN_WORKSPACE}/test-visitors/messages`, "post">) => Promise<{
|
|
450
|
+
visitorId: string;
|
|
451
|
+
conversationId: string;
|
|
452
|
+
message: components["schemas"]["InboxMessage"];
|
|
453
|
+
}>;
|
|
454
|
+
clearTestVisitors: () => Promise<{
|
|
455
|
+
deleted: number;
|
|
456
|
+
}>;
|
|
457
|
+
};
|
|
458
|
+
export declare function workspace(request: Request): {
|
|
459
|
+
get: () => Promise<{
|
|
460
|
+
id: string;
|
|
461
|
+
name: string;
|
|
462
|
+
logoUrl: string | null;
|
|
463
|
+
botsPaused: boolean;
|
|
464
|
+
botsPausedBy: string | null;
|
|
465
|
+
botsPausedAt: string | null;
|
|
466
|
+
}>;
|
|
467
|
+
};
|
|
468
|
+
export declare function labels(request: Request): {
|
|
469
|
+
list: () => Promise<{
|
|
470
|
+
labels: components["schemas"]["Label"][];
|
|
471
|
+
}>;
|
|
472
|
+
};
|
|
473
|
+
export declare function savedReplies(request: Request): {
|
|
474
|
+
list: () => Promise<{
|
|
475
|
+
savedReplies: components["schemas"]["SavedReply"][];
|
|
476
|
+
}>;
|
|
477
|
+
};
|
|
478
|
+
export declare function analytics(request: Request): {
|
|
479
|
+
get: (query?: QueryOf<`${typeof IN_WORKSPACE}/analytics`, "get">) => Promise<{
|
|
480
|
+
days: number;
|
|
481
|
+
timeZone: string;
|
|
482
|
+
started: number;
|
|
483
|
+
startedByTeam: number;
|
|
484
|
+
closed: number;
|
|
485
|
+
answered: number;
|
|
486
|
+
firstReply: {
|
|
487
|
+
medianSeconds: number | null;
|
|
488
|
+
p90Seconds: number | null;
|
|
489
|
+
fast: number;
|
|
490
|
+
};
|
|
491
|
+
previous: {
|
|
492
|
+
started: number;
|
|
493
|
+
firstReply: {
|
|
494
|
+
medianSeconds: number | null;
|
|
495
|
+
fast: number;
|
|
496
|
+
};
|
|
497
|
+
};
|
|
498
|
+
perDay: {
|
|
499
|
+
date: string;
|
|
500
|
+
conversations: number;
|
|
501
|
+
}[];
|
|
502
|
+
repliers: ({
|
|
503
|
+
kind: "operator";
|
|
504
|
+
operatorId: string;
|
|
505
|
+
name: string;
|
|
506
|
+
conversations: number;
|
|
507
|
+
} | {
|
|
508
|
+
kind: "api_key";
|
|
509
|
+
apiKeyId: string;
|
|
510
|
+
name: string;
|
|
511
|
+
conversations: number;
|
|
512
|
+
} | {
|
|
513
|
+
kind: "former";
|
|
514
|
+
conversations: number;
|
|
515
|
+
})[];
|
|
516
|
+
hours: number[][];
|
|
517
|
+
labels: {
|
|
518
|
+
labelId: string;
|
|
519
|
+
name: string;
|
|
520
|
+
color: "gray" | "red" | "orange" | "yellow" | "green" | "teal" | "blue" | "purple";
|
|
521
|
+
conversations: number;
|
|
522
|
+
}[];
|
|
523
|
+
}>;
|
|
524
|
+
};
|
|
525
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { components, paths } from "./openapi.ts";
|
|
2
|
+
type Schemas = components["schemas"];
|
|
3
|
+
/** Every webhook type, from the API's own list. */
|
|
4
|
+
export type WebhookType = NonNullable<paths["/v1/operator/workspaces/{workspaceId}/webhooks"]["post"]["requestBody"]>["content"]["application/json"]["events"][number];
|
|
5
|
+
type MessageType = Extract<WebhookType, `message.${string}`>;
|
|
6
|
+
type OutboundType = Extract<WebhookType, `outbound_message.${string}`>;
|
|
7
|
+
type ConversationType = Exclude<WebhookType, MessageType | OutboundType | "conversation.labeled">;
|
|
8
|
+
interface ConversationData {
|
|
9
|
+
conversation: Schemas["Conversation"];
|
|
10
|
+
}
|
|
11
|
+
/** The `data` of each webhook type, in the same shapes as the operator API. */
|
|
12
|
+
type DataOf<T extends WebhookType> = T extends MessageType ? ConversationData & {
|
|
13
|
+
message: Schemas["InboxMessage"];
|
|
14
|
+
} : T extends OutboundType ? {
|
|
15
|
+
outboundMessage: Schemas["OutboundMessage"];
|
|
16
|
+
} : T extends "conversation.labeled" ? ConversationData & {
|
|
17
|
+
label: Schemas["Label"];
|
|
18
|
+
action: "added" | "removed";
|
|
19
|
+
} : T extends ConversationType ? ConversationData : never;
|
|
20
|
+
/** One event, as the events stream yields it. */
|
|
21
|
+
export type StreamEvent = {
|
|
22
|
+
[T in WebhookType]: {
|
|
23
|
+
id: string;
|
|
24
|
+
type: T;
|
|
25
|
+
data: DataOf<T>;
|
|
26
|
+
};
|
|
27
|
+
}[WebhookType];
|
|
28
|
+
/** One webhook request's body. `webhook.test` is the body that Settings' test sends. */
|
|
29
|
+
export type WebhookEvent = {
|
|
30
|
+
[T in WebhookType]: {
|
|
31
|
+
id: string;
|
|
32
|
+
type: T;
|
|
33
|
+
createdAt: string;
|
|
34
|
+
workspaceId: string;
|
|
35
|
+
data: DataOf<T>;
|
|
36
|
+
};
|
|
37
|
+
}[WebhookType] | {
|
|
38
|
+
id: string;
|
|
39
|
+
type: "webhook.test";
|
|
40
|
+
createdAt: string;
|
|
41
|
+
workspaceId: string;
|
|
42
|
+
data: Record<string, never>;
|
|
43
|
+
};
|
|
44
|
+
type Headers = globalThis.Headers | Record<string, string | string[] | undefined>;
|
|
45
|
+
/** A received webhook: a fetch `Request`, or its raw body and headers, as Node gives them. */
|
|
46
|
+
export type Received = Request | {
|
|
47
|
+
body: string | Uint8Array;
|
|
48
|
+
headers: Headers;
|
|
49
|
+
};
|
|
50
|
+
/** Checks `Dinghy-Signature` with the webhook's secret, and returns the parsed body. */
|
|
51
|
+
export declare function verifyWebhook(received: Received, secret: string): Promise<WebhookEvent>;
|
|
52
|
+
export {};
|