1 | |
2 | type Kustomer = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Update draft |
7 | * Updates a draft. |
8 |
|
9 | You can use this endpoint to update any available properties for a channel. |
10 |
|
11 | ## `sendAt` property options |
12 |
|
13 | * If the `sendAt` property is set to a valid timestamp, the draft will be scheduled to be sent. |
14 | * If the `sendAt` property is empty, the draft will be unscheduled. |
15 | * If the `sendAt` property is omitted, the draft status won't change. |
16 | */ |
17 | export async function main( |
18 | auth: Kustomer, |
19 | id: string, |
20 | body: |
21 | | { |
22 | channel: "email"; |
23 | conversation?: string; |
24 | app?: "gmail" | "postmark"; |
25 | customer?: string; |
26 | auto?: false | true; |
27 | scheduled?: false | true; |
28 | sendAt?: string; |
29 | source?: "bulk" | "satisfaction" | "biz-rules"; |
30 | lang?: string; |
31 | shortcuts?: string[]; |
32 | kbArticles?: string[]; |
33 | to?: |
34 | | { email: string; name?: string }[] |
35 | | { email: string; name?: string }; |
36 | from?: { email: string; name?: string }; |
37 | body?: string; |
38 | htmlBody?: string; |
39 | cc?: { email: string; name?: string }[]; |
40 | bcc?: { email: string; name?: string }[]; |
41 | subject?: string; |
42 | replyTo?: string; |
43 | headers?: { name: string; value?: string }[]; |
44 | templateType?: |
45 | | "email-reply" |
46 | | "email-autoresponse" |
47 | | "email-satisfaction"; |
48 | template?: string; |
49 | payload?: {}; |
50 | } |
51 | | { |
52 | channel: "sms"; |
53 | app?: "twilio" | "zipwhip" | "messagebird"; |
54 | conversation?: string; |
55 | customer?: string; |
56 | auto?: false | true; |
57 | scheduled?: false | true; |
58 | sendAt?: string; |
59 | source?: "bulk" | "satisfaction" | "biz-rules"; |
60 | lang?: string; |
61 | shortcuts?: string[]; |
62 | kbArticles?: string[]; |
63 | to?: string; |
64 | from?: string; |
65 | body?: string; |
66 | payload?: {}; |
67 | } |
68 | | { |
69 | channel: "whatsapp"; |
70 | app: "messagebird" | "whatsapp" | "twilio_whatsapp"; |
71 | conversation?: string; |
72 | customer?: string; |
73 | auto?: false | true; |
74 | scheduled?: false | true; |
75 | sendAt?: string; |
76 | source?: "bulk" | "satisfaction" | "biz-rules"; |
77 | lang?: string; |
78 | shortcuts?: string[]; |
79 | kbArticles?: string[]; |
80 | to?: string; |
81 | from?: string; |
82 | body?: string; |
83 | payload?: {}; |
84 | } |
85 | | { |
86 | channel: "chat"; |
87 | app?: "chat" | "smooch"; |
88 | conversation?: string; |
89 | customer?: string; |
90 | auto?: false | true; |
91 | scheduled?: false | true; |
92 | sendAt?: string; |
93 | source?: "bulk" | "satisfaction" | "biz-rules"; |
94 | lang?: string; |
95 | shortcuts?: string[]; |
96 | kbArticles?: string[]; |
97 | to?: string; |
98 | from?: string; |
99 | body?: string; |
100 | payload?: {}; |
101 | responseButtons?: { label: string; value: string }[]; |
102 | messageTemplate?: |
103 | | { id?: string; templateType: "text"; body: string } |
104 | | { |
105 | id?: string; |
106 | templateType: "quick_replies"; |
107 | body?: string; |
108 | actions: { |
109 | displayText: string; |
110 | valueType: "text" | "url"; |
111 | value: string; |
112 | }[]; |
113 | } |
114 | | { |
115 | id?: string; |
116 | templateType: "deflection"; |
117 | body?: string; |
118 | actions: { |
119 | displayText: string; |
120 | valueType: "text" | "url"; |
121 | value: string; |
122 | }[]; |
123 | articles: { id: string; type?: string; attributes?: {} }[]; |
124 | followupText?: string; |
125 | } |
126 | | { |
127 | id?: string; |
128 | templateType: "mll"; |
129 | body?: string; |
130 | actions: { tree: {} }; |
131 | }; |
132 | attachments?: string[]; |
133 | } |
134 | | { |
135 | channel: "facebook"; |
136 | conversation?: string; |
137 | customer?: string; |
138 | auto?: false | true; |
139 | scheduled?: false | true; |
140 | sendAt?: string; |
141 | source?: "bulk" | "satisfaction" | "biz-rules"; |
142 | lang?: string; |
143 | shortcuts?: string[]; |
144 | kbArticles?: string[]; |
145 | to?: string; |
146 | from?: string; |
147 | body?: string; |
148 | payload?: {}; |
149 | } |
150 | | { |
151 | channel: "twitter-tweet"; |
152 | conversation?: string; |
153 | customer?: string; |
154 | auto?: false | true; |
155 | scheduled?: false | true; |
156 | sendAt?: string; |
157 | source?: "bulk" | "satisfaction" | "biz-rules"; |
158 | lang?: string; |
159 | shortcuts?: string[]; |
160 | kbArticles?: string[]; |
161 | to?: string; |
162 | from?: string; |
163 | body?: string; |
164 | payload?: {}; |
165 | } |
166 | | { |
167 | channel: "twitter-dm"; |
168 | conversation?: string; |
169 | customer?: string; |
170 | auto?: false | true; |
171 | scheduled?: false | true; |
172 | sendAt?: string; |
173 | source?: "bulk" | "satisfaction" | "biz-rules"; |
174 | lang?: string; |
175 | shortcuts?: string[]; |
176 | kbArticles?: string[]; |
177 | to?: string; |
178 | from?: string; |
179 | body?: string; |
180 | payload?: {}; |
181 | } |
182 | | { |
183 | channel: "note"; |
184 | conversation?: string; |
185 | customer?: string; |
186 | scheduled?: false | true; |
187 | sendAt?: string; |
188 | source?: "bulk" | "biz-rules"; |
189 | lang?: string; |
190 | shortcuts?: string[]; |
191 | kbArticles?: string[]; |
192 | body?: string; |
193 | payload?: {}; |
194 | userMentions?: { user?: string; team?: string }[]; |
195 | } |
196 | | { |
197 | channel: "instagram"; |
198 | conversation?: string; |
199 | customer?: string; |
200 | auto?: false | true; |
201 | scheduled?: false | true; |
202 | sendAt?: string; |
203 | source?: "bulk" | "satisfaction" | "biz-rules"; |
204 | lang?: string; |
205 | shortcuts?: string[]; |
206 | kbArticles?: string[]; |
207 | to?: string; |
208 | from?: string; |
209 | body?: string; |
210 | payload?: {}; |
211 | }, |
212 | ) { |
213 | const url = new URL(`https://api.kustomerapp.com/v1/drafts/${id}`); |
214 |
|
215 | const response = await fetch(url, { |
216 | method: "PUT", |
217 | headers: { |
218 | "Content-Type": "application/json", |
219 | Authorization: "Bearer " + auth.apiKey, |
220 | }, |
221 | body: JSON.stringify(body), |
222 | }); |
223 | if (!response.ok) { |
224 | const text = await response.text(); |
225 | throw new Error(`${response.status} ${text}`); |
226 | } |
227 | return await response.json(); |
228 | } |
229 |
|