1 | |
2 | type Motimate = { |
3 | token: string |
4 | } |
5 |
|
6 | export async function main( |
7 | auth: Motimate, |
8 | body: { |
9 | text: string |
10 | group_id: number |
11 | group_external_id: string |
12 | user_id: number |
13 | user_external_id: string |
14 | file_ids?: string[] |
15 | } |
16 | ) { |
17 | const url = new URL(`https://motimateapp.com/public_api/posts`) |
18 |
|
19 | const response = await fetch(url, { |
20 | method: 'POST', |
21 | headers: { |
22 | 'Content-Type': 'application/json', |
23 | Authorization: 'Bearer ' + auth.token |
24 | }, |
25 | body: JSON.stringify(body) |
26 | }) |
27 |
|
28 | if (!response.ok) { |
29 | const text = await response.text() |
30 | throw new Error(`${response.status} ${text}`) |
31 | } |
32 |
|
33 | return await response.text() |
34 | } |
35 |
|