1 | |
2 |
|
3 | |
4 | * List Task Stories |
5 | * List a task's stories: its comments plus the activity log (assignments, completions, field changes). Set `comments_only` to keep only comments; the filter applies to the returned page. Pass `next_page.offset` from a response as `offset` to get the next page. |
6 | */ |
7 | export async function main( |
8 | auth: RT.Asana, |
9 | task_gid: string, |
10 | comments_only: boolean | undefined, |
11 | opt_fields: string | undefined, |
12 | limit: number | undefined, |
13 | offset: string | undefined |
14 | ) { |
15 | const url = new URL(`https://app.asana.com/api/1.0/tasks/${task_gid}/stories`) |
16 | url.searchParams.append("limit", String(limit ?? 100)) |
17 | if (offset != null && offset !== "") { |
18 | url.searchParams.append("offset", offset) |
19 | } |
20 | if (opt_fields != null && opt_fields !== "") { |
21 | |
22 | url.searchParams.append("opt_fields", `${opt_fields},resource_subtype`) |
23 | } |
24 |
|
25 | const response = await fetch(url, { |
26 | headers: { |
27 | Authorization: `Bearer ${auth.token}`, |
28 | Accept: "application/json", |
29 | }, |
30 | }) |
31 |
|
32 | if (!response.ok) { |
33 | throw new Error(`${response.status} ${await response.text()}`) |
34 | } |
35 |
|
36 | const result = await response.json() |
37 | if (comments_only) { |
38 | result.data = result.data.filter( |
39 | (story: { resource_subtype: string }) => |
40 | story.resource_subtype === "comment_added" |
41 | ) |
42 | } |
43 | return result |
44 | } |
45 |
|