1 | |
2 | type Gorgias = { |
3 | username: string; |
4 | apiKey: string; |
5 | domain: string; |
6 | }; |
7 | |
8 | * Create a ticket |
9 | * |
10 | */ |
11 | export async function main( |
12 | auth: Gorgias, |
13 | body: { |
14 | assignee_team?: { id?: number }; |
15 | assignee_user?: { id?: number }; |
16 | channel?: |
17 | | "aircall" |
18 | | "api" |
19 | | "chat" |
20 | | "email" |
21 | | "facebook" |
22 | | "facebook-mention" |
23 | | "facebook-messenger" |
24 | | "facebook-recommendations" |
25 | | "help-center" |
26 | | "instagram-ad-comment" |
27 | | "instagram-comment" |
28 | | "instagram-mention" |
29 | | "instagram-direct-message" |
30 | | "internal-note" |
31 | | "phone" |
32 | | "sms" |
33 | | "twitter" |
34 | | "twitter-direct-message" |
35 | | "yotpo-review"; |
36 | closed_datetime?: string; |
37 | created_datetime?: string; |
38 | customer?: { id?: number; email?: string }; |
39 | external_id?: string; |
40 | from_agent?: false | true; |
41 | language?: string; |
42 | last_message_datetime?: string; |
43 | last_received_message_datetime?: string; |
44 | messages: { |
45 | attachments?: { |
46 | content_type: string; |
47 | extra?: {}; |
48 | size: number; |
49 | name: string; |
50 | url: string; |
51 | public?: false | true; |
52 | }[]; |
53 | body_html?: string; |
54 | body_text?: string; |
55 | channel: |
56 | | "aircall" |
57 | | "api" |
58 | | "chat" |
59 | | "email" |
60 | | "facebook" |
61 | | "facebook-mention" |
62 | | "facebook-messenger" |
63 | | "facebook-recommendations" |
64 | | "help-center" |
65 | | "instagram-ad-comment" |
66 | | "instagram-comment" |
67 | | "instagram-mention" |
68 | | "instagram-direct-message" |
69 | | "internal-note" |
70 | | "phone" |
71 | | "sms" |
72 | | "twitter" |
73 | | "twitter-direct-message" |
74 | | "yotpo-review"; |
75 | created_datetime?: string; |
76 | external_id?: string; |
77 | failed_datetime?: string; |
78 | from_agent: false | true; |
79 | integration_id?: number; |
80 | last_sending_error?: {}; |
81 | message_id?: string; |
82 | receiver?: { id?: number; email?: string }; |
83 | rule_id?: number; |
84 | sender?: { id?: number; email?: string }; |
85 | sent_datetime?: string; |
86 | source?: { |
87 | from?: { name?: string; address?: string }; |
88 | bcc?: { name?: string; address?: string }[]; |
89 | type?: string; |
90 | to?: { name?: string; address?: string }[]; |
91 | cc?: { name?: string; address?: string }[]; |
92 | }; |
93 | stripped_html?: string; |
94 | stripped_text?: string; |
95 | subject?: string; |
96 | via: |
97 | | "aircall" |
98 | | "api" |
99 | | "chat" |
100 | | "email" |
101 | | "facebook" |
102 | | "facebook-mention" |
103 | | "facebook-messenger" |
104 | | "facebook-recommendations" |
105 | | "help-center" |
106 | | "instagram-ad-comment" |
107 | | "instagram-comment" |
108 | | "instagram-mention" |
109 | | "instagram-direct-message" |
110 | | "internal-note" |
111 | | "phone" |
112 | | "sms" |
113 | | "twitter" |
114 | | "twitter-direct-message" |
115 | | "yotpo-review" |
116 | | "twilio" |
117 | | "zendesk" |
118 | | "form" |
119 | | "self_service" |
120 | | "yotpo" |
121 | | "instagram" |
122 | | "shopify" |
123 | | "gorgias_chat" |
124 | | "rule" |
125 | | "helpdesk"; |
126 | }[]; |
127 | meta?: {}; |
128 | opened_datetime?: string; |
129 | snooze_datetime?: string; |
130 | spam?: false | true; |
131 | status?: "open" | "closed"; |
132 | subject?: string; |
133 | tags?: { name?: string }[]; |
134 | trashed_datetime?: string; |
135 | updated_datetime?: string; |
136 | via?: |
137 | | "aircall" |
138 | | "api" |
139 | | "chat" |
140 | | "email" |
141 | | "facebook" |
142 | | "facebook-mention" |
143 | | "facebook-messenger" |
144 | | "facebook-recommendations" |
145 | | "help-center" |
146 | | "instagram-ad-comment" |
147 | | "instagram-comment" |
148 | | "instagram-mention" |
149 | | "instagram-direct-message" |
150 | | "internal-note" |
151 | | "phone" |
152 | | "sms" |
153 | | "twitter" |
154 | | "twitter-direct-message" |
155 | | "yotpo-review" |
156 | | "twilio" |
157 | | "zendesk" |
158 | | "form" |
159 | | "self_service" |
160 | | "yotpo" |
161 | | "instagram" |
162 | | "shopify" |
163 | | "gorgias_chat" |
164 | | "rule" |
165 | | "helpdesk"; |
166 | }, |
167 | ) { |
168 | const url = new URL(`https://${auth.domain}.gorgias.com/api/tickets`); |
169 |
|
170 | const response = await fetch(url, { |
171 | method: "POST", |
172 | headers: { |
173 | "Content-Type": "application/json", |
174 | Authorization: "Basic " + btoa(`${auth.username}:${auth.apiKey}`), |
175 | }, |
176 | body: JSON.stringify(body), |
177 | }); |
178 | if (!response.ok) { |
179 | const text = await response.text(); |
180 | throw new Error(`${response.status} ${text}`); |
181 | } |
182 | return await response.json(); |
183 | } |
184 |
|