1 | |
2 | type Kustomer = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Create work item |
7 | * Creates a new work item. |
8 | */ |
9 | export async function main( |
10 | auth: Kustomer, |
11 | body: { |
12 | resource: { |
13 | id: string; |
14 | type: "conversation"; |
15 | rev?: number; |
16 | createdAt?: string; |
17 | direction?: "in" | "out"; |
18 | }; |
19 | channel?: string; |
20 | createdAt?: string; |
21 | queue?: { |
22 | id?: string; |
23 | external?: "amazon-connect" | "aircall"; |
24 | enteredAt?: string; |
25 | }; |
26 | assignedTo?: string; |
27 | }, |
28 | ) { |
29 | const url = new URL(`https://api.kustomerapp.com/v1/routing/work-items`); |
30 |
|
31 | const response = await fetch(url, { |
32 | method: "POST", |
33 | headers: { |
34 | "Content-Type": "application/json", |
35 | Authorization: "Bearer " + auth.apiKey, |
36 | }, |
37 | body: JSON.stringify(body), |
38 | }); |
39 | if (!response.ok) { |
40 | const text = await response.text(); |
41 | throw new Error(`${response.status} ${text}`); |
42 | } |
43 | return await response.json(); |
44 | } |
45 |
|