1 | |
2 | type Gorgias = { |
3 | username: string; |
4 | apiKey: string; |
5 | domain: string; |
6 | }; |
7 | |
8 | * Update a ticket |
9 | * |
10 | */ |
11 | export async function main( |
12 | auth: Gorgias, |
13 | id: string, |
14 | body: { |
15 | assignee_team?: { id?: number }; |
16 | assignee_user?: { id?: number }; |
17 | channel?: |
18 | | "aircall" |
19 | | "api" |
20 | | "chat" |
21 | | "email" |
22 | | "facebook" |
23 | | "facebook-mention" |
24 | | "facebook-messenger" |
25 | | "facebook-recommendations" |
26 | | "help-center" |
27 | | "instagram-ad-comment" |
28 | | "instagram-comment" |
29 | | "instagram-mention" |
30 | | "instagram-direct-message" |
31 | | "internal-note" |
32 | | "phone" |
33 | | "sms" |
34 | | "twitter" |
35 | | "twitter-direct-message" |
36 | | "yotpo-review"; |
37 | closed_datetime?: string; |
38 | customer?: { id?: number; email?: string }; |
39 | external_id?: string; |
40 | from_agent?: false | true; |
41 | is_unread?: false | true; |
42 | language?: string; |
43 | last_message_datetime?: string; |
44 | last_received_message_datetime?: string; |
45 | meta?: {}; |
46 | opened_datetime?: string; |
47 | snooze_datetime?: string; |
48 | spam?: false | true; |
49 | status?: "open" | "closed"; |
50 | subject?: string; |
51 | tags?: { name?: string }[]; |
52 | trashed_datetime?: string; |
53 | updated_datetime?: string; |
54 | via?: |
55 | | "aircall" |
56 | | "api" |
57 | | "chat" |
58 | | "email" |
59 | | "facebook" |
60 | | "facebook-mention" |
61 | | "facebook-messenger" |
62 | | "facebook-recommendations" |
63 | | "help-center" |
64 | | "instagram-ad-comment" |
65 | | "instagram-comment" |
66 | | "instagram-mention" |
67 | | "instagram-direct-message" |
68 | | "internal-note" |
69 | | "phone" |
70 | | "sms" |
71 | | "twitter" |
72 | | "twitter-direct-message" |
73 | | "yotpo-review" |
74 | | "twilio" |
75 | | "zendesk" |
76 | | "form" |
77 | | "self_service" |
78 | | "yotpo" |
79 | | "instagram" |
80 | | "shopify" |
81 | | "gorgias_chat" |
82 | | "rule" |
83 | | "helpdesk"; |
84 | }, |
85 | ) { |
86 | const url = new URL(`https://${auth.domain}.gorgias.com/api/tickets/${id}/`); |
87 |
|
88 | const response = await fetch(url, { |
89 | method: "PUT", |
90 | headers: { |
91 | "Content-Type": "application/json", |
92 | Authorization: "Basic " + btoa(`${auth.username}:${auth.apiKey}`), |
93 | }, |
94 | body: JSON.stringify(body), |
95 | }); |
96 | if (!response.ok) { |
97 | const text = await response.text(); |
98 | throw new Error(`${response.status} ${text}`); |
99 | } |
100 | return await response.json(); |
101 | } |
102 |
|