1 | |
2 |
|
3 | |
4 | * List Messages |
5 | * List the messages of a conversation thread. Requires conversations.read. |
6 | */ |
7 | export async function main( |
8 | auth: RT.Hubspot, |
9 | thread_id: string, |
10 | limit: number | undefined, |
11 | after: string | undefined, |
12 | sort: string | undefined, |
13 | archived: boolean | undefined |
14 | ) { |
15 | const url = new URL( |
16 | `https://api.hubapi.com/conversations/v3/conversations/threads/${thread_id}/messages` |
17 | ) |
18 | if (limit != null) url.searchParams.append("limit", String(limit)) |
19 | if (after != null && after !== "") url.searchParams.append("after", after) |
20 | if (sort != null && sort !== "") url.searchParams.append("sort", sort) |
21 | if (archived) url.searchParams.append("archived", String(archived)) |
22 |
|
23 | const response = await fetch(url, { |
24 | headers: { |
25 | Authorization: `Bearer ${auth.token}`, |
26 | Accept: "application/json", |
27 | }, |
28 | }) |
29 |
|
30 | if (!response.ok) { |
31 | throw new Error(`${response.status} ${await response.text()}`) |
32 | } |
33 |
|
34 | return await response.json() |
35 | } |
36 |
|