@todoist/comms-sdk 0.0.1 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +182 -39
  3. package/dist/esm/authentication.js +247 -0
  4. package/dist/esm/clients/add-comment-helper.js +41 -0
  5. package/dist/esm/clients/attachments-client.js +99 -0
  6. package/dist/esm/clients/base-client.js +30 -0
  7. package/dist/esm/clients/channels-client.js +209 -0
  8. package/dist/esm/clients/comments-client.js +177 -0
  9. package/dist/esm/clients/conversation-messages-client.js +167 -0
  10. package/dist/esm/clients/conversations-client.js +281 -0
  11. package/dist/esm/clients/groups-client.js +170 -0
  12. package/dist/esm/clients/hooks-client.js +50 -0
  13. package/dist/esm/clients/inbox-client.js +186 -0
  14. package/dist/esm/clients/notify-audience.js +43 -0
  15. package/dist/esm/clients/reactions-client.js +96 -0
  16. package/dist/esm/clients/search-client.js +140 -0
  17. package/dist/esm/clients/threads-client.js +363 -0
  18. package/dist/esm/clients/users-client.js +368 -0
  19. package/dist/esm/clients/workspace-users-client.js +299 -0
  20. package/dist/esm/clients/workspaces-client.js +177 -0
  21. package/dist/esm/comms-api.js +67 -0
  22. package/dist/esm/consts/endpoints.js +31 -0
  23. package/dist/esm/index.js +20 -0
  24. package/dist/esm/migration.js +92 -0
  25. package/dist/esm/testUtils/msw-handlers.js +45 -0
  26. package/dist/esm/testUtils/msw-setup.js +32 -0
  27. package/dist/esm/testUtils/obsidian-fetch-adapter.js +50 -0
  28. package/dist/esm/testUtils/test-defaults.js +103 -0
  29. package/dist/esm/transport/fetch-with-retry.js +240 -0
  30. package/dist/esm/transport/http-client.js +53 -0
  31. package/dist/esm/transport/http-dispatcher.js +149 -0
  32. package/dist/esm/types/api-version.js +5 -0
  33. package/dist/esm/types/entities.js +508 -0
  34. package/dist/esm/types/enums.js +34 -0
  35. package/dist/esm/types/errors.js +82 -0
  36. package/dist/esm/types/http.js +1 -0
  37. package/dist/esm/types/index.js +6 -0
  38. package/dist/esm/types/requests.js +184 -0
  39. package/dist/esm/utils/case-conversion.js +47 -0
  40. package/dist/esm/utils/conversation-title.js +110 -0
  41. package/dist/esm/utils/headers.js +29 -0
  42. package/dist/esm/utils/index.js +5 -0
  43. package/dist/esm/utils/multipart-upload.js +198 -0
  44. package/dist/esm/utils/reply-recipients.js +111 -0
  45. package/dist/esm/utils/timestamp-conversion.js +54 -0
  46. package/dist/esm/utils/url-helpers.js +202 -0
  47. package/dist/esm/utils/uuidv7.js +170 -0
  48. package/dist/types/authentication.d.ts +183 -0
  49. package/dist/types/clients/add-comment-helper.d.ts +32 -0
  50. package/dist/types/clients/attachments-client.d.ts +55 -0
  51. package/dist/types/clients/base-client.d.ts +37 -0
  52. package/dist/types/clients/channels-client.d.ts +211 -0
  53. package/dist/types/clients/comments-client.d.ts +228 -0
  54. package/dist/types/clients/conversation-messages-client.d.ts +201 -0
  55. package/dist/types/clients/conversations-client.d.ts +366 -0
  56. package/dist/types/clients/groups-client.d.ts +148 -0
  57. package/dist/types/clients/hooks-client.d.ts +29 -0
  58. package/dist/types/clients/inbox-client.d.ts +478 -0
  59. package/dist/types/clients/notify-audience.d.ts +22 -0
  60. package/dist/types/clients/reactions-client.d.ts +57 -0
  61. package/dist/types/clients/search-client.d.ts +71 -0
  62. package/dist/types/clients/threads-client.d.ts +547 -0
  63. package/dist/types/clients/users-client.d.ts +280 -0
  64. package/dist/types/clients/workspace-users-client.d.ts +172 -0
  65. package/dist/types/clients/workspaces-client.d.ts +154 -0
  66. package/dist/types/comms-api.d.ts +73 -0
  67. package/dist/types/consts/endpoints.d.ts +27 -0
  68. package/dist/types/index.d.ts +21 -0
  69. package/dist/types/migration.d.ts +78 -0
  70. package/dist/types/testUtils/msw-handlers.d.ts +28 -0
  71. package/dist/types/testUtils/msw-setup.d.ts +1 -0
  72. package/dist/types/testUtils/obsidian-fetch-adapter.d.ts +29 -0
  73. package/dist/types/testUtils/test-defaults.d.ts +17 -0
  74. package/dist/types/transport/fetch-with-retry.d.ts +4 -0
  75. package/dist/types/transport/http-client.d.ts +14 -0
  76. package/dist/types/transport/http-dispatcher.d.ts +46 -0
  77. package/dist/types/types/api-version.d.ts +6 -0
  78. package/dist/types/types/entities.d.ts +3081 -0
  79. package/dist/types/types/enums.d.ts +55 -0
  80. package/dist/types/types/errors.d.ts +57 -0
  81. package/dist/types/types/http.d.ts +60 -0
  82. package/dist/types/types/index.d.ts +6 -0
  83. package/dist/types/types/requests.d.ts +604 -0
  84. package/dist/types/utils/case-conversion.d.ts +8 -0
  85. package/dist/types/utils/conversation-title.d.ts +84 -0
  86. package/dist/types/utils/headers.d.ts +13 -0
  87. package/dist/types/utils/index.d.ts +6 -0
  88. package/dist/types/utils/multipart-upload.d.ts +59 -0
  89. package/dist/types/utils/reply-recipients.d.ts +60 -0
  90. package/dist/types/utils/timestamp-conversion.d.ts +13 -0
  91. package/dist/types/utils/url-helpers.d.ts +129 -0
  92. package/dist/types/utils/uuidv7.d.ts +42 -0
  93. package/package.json +80 -8
@@ -0,0 +1,209 @@
1
+ import { z } from 'zod';
2
+ import { ENDPOINT_CHANNELS } from '../consts/endpoints.js';
3
+ import { request } from '../transport/http-client.js';
4
+ import { ChannelSchema, createChannelSchema, StatusOkSchema, } from '../types/entities.js';
5
+ import { resolveCreateId } from '../utils/uuidv7.js';
6
+ import { BaseClient } from './base-client.js';
7
+ export const ChannelListSchema = z.array(ChannelSchema);
8
+ /**
9
+ * Client for `/api/v1.0/channels/`. The SDK auto-generates an `id` on
10
+ * `createChannel` when the caller doesn't supply one — pass your own `id`
11
+ * to keep an optimistic-UI ID stable through the round-trip.
12
+ */
13
+ export class ChannelsClient extends BaseClient {
14
+ constructor() {
15
+ super(...arguments);
16
+ this.linkBaseUrl = this.getLinkBaseUrl();
17
+ // Reuse the shared singletons when no custom base is configured.
18
+ this.channelSchema = this.linkBaseUrl
19
+ ? createChannelSchema(this.linkBaseUrl)
20
+ : ChannelSchema;
21
+ this.channelListSchema = this.linkBaseUrl
22
+ ? z.array(this.channelSchema)
23
+ : ChannelListSchema;
24
+ }
25
+ /**
26
+ * Gets all channels for a given workspace.
27
+ *
28
+ * @param args - The arguments for getting channels.
29
+ * @param args.workspaceId - The workspace ID.
30
+ * @param args.archived - Optional flag to include archived channels.
31
+ * @returns An array of channel objects.
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * const channels = await api.channels.getChannels({ workspaceId: 123 })
36
+ * channels.forEach(ch => console.log(ch.name))
37
+ * ```
38
+ */
39
+ getChannels(args) {
40
+ return request({
41
+ httpMethod: 'GET',
42
+ baseUri: this.getBaseUri(),
43
+ relativePath: `${ENDPOINT_CHANNELS}/get`,
44
+ apiToken: this.apiToken,
45
+ payload: args,
46
+ headers: this.headers,
47
+ customFetch: this.customFetch,
48
+ }).then((response) => this.channelListSchema.parse(response.data));
49
+ }
50
+ /**
51
+ * Gets a single channel object by id.
52
+ *
53
+ * @param id - The channel ID.
54
+ * @returns The channel object.
55
+ */
56
+ getChannel(id) {
57
+ return this.simple('GET', 'getone', { id }, this.channelSchema);
58
+ }
59
+ /**
60
+ * Creates a new channel. `id` is auto-generated if not supplied — pass your
61
+ * own `id` to keep an optimistic-UI ID stable through the round-trip.
62
+ *
63
+ * @param args - The arguments for creating a channel.
64
+ * @param args.workspaceId - The workspace ID.
65
+ * @param args.name - The channel name.
66
+ * @param args.description - Optional channel description.
67
+ * @param args.color - Optional channel color.
68
+ * @param args.userIds - Optional array of user IDs to add to the channel.
69
+ * @param args.public - Optional flag to make the channel public.
70
+ * @returns The created channel object.
71
+ *
72
+ * @example
73
+ * ```typescript
74
+ * const channel = await api.channels.createChannel({
75
+ * workspaceId: 123,
76
+ * name: 'Engineering',
77
+ * description: 'Engineering team channel',
78
+ * })
79
+ * ```
80
+ */
81
+ createChannel(args) {
82
+ return this.simple('POST', 'add', { ...args, id: resolveCreateId(args.id) }, this.channelSchema);
83
+ }
84
+ /**
85
+ * Partial update of an existing channel.
86
+ *
87
+ * @param args - The arguments for updating a channel.
88
+ * @param args.id - The channel ID.
89
+ * @param args.name - Optional new channel name.
90
+ * @param args.description - Optional new channel description.
91
+ * @param args.color - Optional new channel color.
92
+ * @param args.public - Optional flag to change channel visibility.
93
+ * @returns The updated channel object.
94
+ */
95
+ updateChannel(args) {
96
+ return this.simple('POST', 'update', { ...args }, this.channelSchema);
97
+ }
98
+ /**
99
+ * Updates the channel's view filter (`only_open` / `all` / `only_closed`).
100
+ *
101
+ * @param args - The arguments for updating the channel filter.
102
+ * @param args.id - The channel ID.
103
+ * @param args.filterClosed - The new filter value.
104
+ */
105
+ updateFilters(args) {
106
+ return this.simple('POST', 'update_filters', { ...args }, StatusOkSchema);
107
+ }
108
+ /**
109
+ * Permanently deletes a channel.
110
+ *
111
+ * @param id - The channel ID.
112
+ */
113
+ deleteChannel(id) {
114
+ return this.simple('POST', 'remove', { id }, StatusOkSchema);
115
+ }
116
+ /**
117
+ * Archives a channel.
118
+ *
119
+ * @param id - The channel ID.
120
+ */
121
+ archiveChannel(id) {
122
+ return this.simple('POST', 'archive', { id }, StatusOkSchema);
123
+ }
124
+ /**
125
+ * Unarchives a channel.
126
+ *
127
+ * @param id - The channel ID.
128
+ */
129
+ unarchiveChannel(id) {
130
+ return this.simple('POST', 'unarchive', { id }, StatusOkSchema);
131
+ }
132
+ /**
133
+ * Favorites a channel.
134
+ *
135
+ * @param id - The channel ID.
136
+ */
137
+ favoriteChannel(id) {
138
+ return this.simple('POST', 'favorite', { id }, StatusOkSchema);
139
+ }
140
+ /**
141
+ * Unfavorites a channel.
142
+ *
143
+ * @param id - The channel ID.
144
+ */
145
+ unfavoriteChannel(id) {
146
+ return this.simple('POST', 'unfavorite', { id }, StatusOkSchema);
147
+ }
148
+ /**
149
+ * Adds a user to a channel.
150
+ *
151
+ * @param args - The arguments for adding a user.
152
+ * @param args.id - The channel ID.
153
+ * @param args.userId - The user ID to add.
154
+ *
155
+ * @example
156
+ * ```typescript
157
+ * await api.channels.addUser({ id: '7YpL3oZ4kZ9vP7Q1tR2sX44', userId: 101 })
158
+ * ```
159
+ */
160
+ addUser(args) {
161
+ return this.simple('POST', 'add_user', { ...args }, this.channelSchema);
162
+ }
163
+ /**
164
+ * Adds multiple users to a channel.
165
+ *
166
+ * @param args - The arguments for adding users.
167
+ * @param args.id - The channel ID.
168
+ * @param args.userIds - Array of user IDs to add.
169
+ *
170
+ * @example
171
+ * ```typescript
172
+ * await api.channels.addUsers({ id: '7YpL3oZ4kZ9vP7Q1tR2sX44', userIds: [101, 202] })
173
+ * ```
174
+ */
175
+ addUsers(args) {
176
+ return this.simple('POST', 'add_users', { ...args }, this.channelSchema);
177
+ }
178
+ /**
179
+ * Removes a user from a channel.
180
+ *
181
+ * @param args - The arguments for removing a user.
182
+ * @param args.id - The channel ID.
183
+ * @param args.userId - The user ID to remove.
184
+ */
185
+ removeUser(args) {
186
+ return this.simple('POST', 'remove_user', { ...args }, this.channelSchema);
187
+ }
188
+ /**
189
+ * Removes multiple users from a channel.
190
+ *
191
+ * @param args - The arguments for removing users.
192
+ * @param args.id - The channel ID.
193
+ * @param args.userIds - Array of user IDs to remove.
194
+ */
195
+ removeUsers(args) {
196
+ return this.simple('POST', 'remove_users', { ...args }, this.channelSchema);
197
+ }
198
+ simple(httpMethod, suffix, params, schema) {
199
+ return request({
200
+ httpMethod,
201
+ baseUri: this.getBaseUri(),
202
+ relativePath: `${ENDPOINT_CHANNELS}/${suffix}`,
203
+ apiToken: this.apiToken,
204
+ payload: params,
205
+ headers: this.headers,
206
+ customFetch: this.customFetch,
207
+ }).then((response) => schema.parse(response.data));
208
+ }
209
+ }
@@ -0,0 +1,177 @@
1
+ import { z } from 'zod';
2
+ import { ENDPOINT_COMMENTS } from '../consts/endpoints.js';
3
+ import { request } from '../transport/http-client.js';
4
+ import { CommentSchema, createCommentSchema, StatusOkSchema, } from '../types/entities.js';
5
+ import { addCommentRequest } from './add-comment-helper.js';
6
+ import { BaseClient } from './base-client.js';
7
+ export const CommentListSchema = z.array(CommentSchema);
8
+ /**
9
+ * Client for `/api/v1.0/comments/`. The SDK auto-generates the comment `id`
10
+ * on `createComment` when the caller doesn't supply one.
11
+ */
12
+ export class CommentsClient extends BaseClient {
13
+ constructor() {
14
+ super(...arguments);
15
+ this.linkBaseUrl = this.getLinkBaseUrl();
16
+ // Reuse the shared singletons when no custom base is configured.
17
+ this.commentSchema = this.linkBaseUrl
18
+ ? createCommentSchema(this.linkBaseUrl)
19
+ : CommentSchema;
20
+ this.commentListSchema = this.linkBaseUrl
21
+ ? z.array(this.commentSchema)
22
+ : CommentListSchema;
23
+ }
24
+ /**
25
+ * Gets all comments for a thread. `newerThan` / `olderThan` (`Date`) are
26
+ * converted to `newer_than_ts` / `older_than_ts` epoch seconds on the
27
+ * wire.
28
+ *
29
+ * @param args - The arguments for getting comments.
30
+ * @param args.threadId - The thread ID.
31
+ * @param args.newerThan - Optional date to get comments newer than.
32
+ * @param args.olderThan - Optional date to get comments older than.
33
+ * @param args.limit - Optional limit on number of comments returned.
34
+ * @returns An array of comment objects.
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * const comments = await api.comments.getComments({
39
+ * threadId: '7YpL3oZ4kZ9vP7Q1tR2sX3z',
40
+ * newerThan: new Date('2024-01-01'),
41
+ * })
42
+ * comments.forEach(c => console.log(c.content))
43
+ * ```
44
+ */
45
+ getComments(args) {
46
+ const params = { threadId: args.threadId };
47
+ if (args.newerThan)
48
+ params.newerThanTs = Math.floor(args.newerThan.getTime() / 1000);
49
+ if (args.olderThan)
50
+ params.olderThanTs = Math.floor(args.olderThan.getTime() / 1000);
51
+ if (args.limit)
52
+ params.limit = args.limit;
53
+ return request({
54
+ httpMethod: 'GET',
55
+ baseUri: this.getBaseUri(),
56
+ relativePath: `${ENDPOINT_COMMENTS}/get`,
57
+ apiToken: this.apiToken,
58
+ payload: params,
59
+ headers: this.headers,
60
+ customFetch: this.customFetch,
61
+ }).then((response) => this.commentListSchema.parse(response.data));
62
+ }
63
+ /**
64
+ * Gets a single comment object by id. The `getone` endpoint returns the
65
+ * comment object directly (the same shape as `add`), not wrapped.
66
+ *
67
+ * @param id - The comment ID.
68
+ * @returns The comment object.
69
+ */
70
+ getComment(id) {
71
+ return request({
72
+ httpMethod: 'GET',
73
+ baseUri: this.getBaseUri(),
74
+ relativePath: `${ENDPOINT_COMMENTS}/getone`,
75
+ apiToken: this.apiToken,
76
+ payload: { id },
77
+ headers: this.headers,
78
+ customFetch: this.customFetch,
79
+ }).then((response) => this.commentSchema.parse(response.data));
80
+ }
81
+ /**
82
+ * Creates a new comment on a thread. `id` is auto-generated if not supplied.
83
+ *
84
+ * @param args - The arguments for creating a comment.
85
+ * @param args.threadId - The thread ID.
86
+ * @param args.content - The comment content.
87
+ * @param args.recipients - Optional array of user IDs to notify directly.
88
+ * @param args.groups - Optional array of custom group IDs to notify.
89
+ * @param args.directMentions - Optional array of user IDs that were @-mentioned in
90
+ * `content`.
91
+ * @param args.notifyAudience - Optional broader audience to notify in addition to
92
+ * `recipients` and `groups`. `'channel'` notifies everyone in the channel;
93
+ * `'thread'` notifies everyone who has interacted with the thread.
94
+ * @param args.attachments - Optional array of {@link Attachment} objects.
95
+ * @returns The created comment object.
96
+ *
97
+ * @example
98
+ * ```typescript
99
+ * // Notify everyone who has interacted with the thread, plus two extra users.
100
+ * const comment = await api.comments.createComment({
101
+ * threadId: '7YpL3oZ4kZ9vP7Q1tR2sX3z',
102
+ * content: 'Great idea! Let\'s proceed.',
103
+ * notifyAudience: 'thread',
104
+ * recipients: [101, 202],
105
+ * })
106
+ * ```
107
+ */
108
+ createComment(args) {
109
+ return addCommentRequest({
110
+ baseUri: this.getBaseUri(),
111
+ apiToken: this.apiToken,
112
+ headers: this.headers,
113
+ customFetch: this.customFetch,
114
+ schema: this.commentSchema,
115
+ }, args);
116
+ }
117
+ /**
118
+ * Updates a comment's properties.
119
+ *
120
+ * @param args - The arguments for updating a comment.
121
+ * @param args.id - The comment ID.
122
+ * @param args.content - The new comment content.
123
+ * @returns The updated comment object.
124
+ */
125
+ updateComment(args) {
126
+ return request({
127
+ httpMethod: 'POST',
128
+ baseUri: this.getBaseUri(),
129
+ relativePath: `${ENDPOINT_COMMENTS}/update`,
130
+ apiToken: this.apiToken,
131
+ payload: { ...args },
132
+ headers: this.headers,
133
+ customFetch: this.customFetch,
134
+ }).then((response) => this.commentSchema.parse(response.data));
135
+ }
136
+ /**
137
+ * Permanently deletes a comment.
138
+ *
139
+ * @param id - The comment ID.
140
+ */
141
+ deleteComment(id) {
142
+ return request({
143
+ httpMethod: 'POST',
144
+ baseUri: this.getBaseUri(),
145
+ relativePath: `${ENDPOINT_COMMENTS}/remove`,
146
+ apiToken: this.apiToken,
147
+ payload: { id },
148
+ headers: this.headers,
149
+ customFetch: this.customFetch,
150
+ }).then((response) => StatusOkSchema.parse(response.data));
151
+ }
152
+ /**
153
+ * Marks the user's read position in a thread. Used to track where the user has read up to,
154
+ * so clients can scroll to this position and show a visual indicator (blue line).
155
+ * Comment IDs are strings.
156
+ *
157
+ * @param args - The arguments for marking read position.
158
+ * @param args.threadId - The thread ID.
159
+ * @param args.commentId - The comment ID to mark as the last read position.
160
+ *
161
+ * @example
162
+ * ```typescript
163
+ * await api.comments.markPosition({ threadId: '7YpL3oZ4kZ9vP7Q1tR2sX3z', commentId: '7YpL3oZ4kZ9vP7Q1tR2sX41' })
164
+ * ```
165
+ */
166
+ markPosition(args) {
167
+ return request({
168
+ httpMethod: 'POST',
169
+ baseUri: this.getBaseUri(),
170
+ relativePath: `${ENDPOINT_COMMENTS}/mark_position`,
171
+ apiToken: this.apiToken,
172
+ payload: { threadId: args.threadId, commentId: args.commentId },
173
+ headers: this.headers,
174
+ customFetch: this.customFetch,
175
+ }).then((response) => StatusOkSchema.parse(response.data));
176
+ }
177
+ }
@@ -0,0 +1,167 @@
1
+ import { z } from 'zod';
2
+ import { ENDPOINT_CONVERSATION_MESSAGES } from '../consts/endpoints.js';
3
+ import { request } from '../transport/http-client.js';
4
+ import { ConversationMessageSchema, createConversationMessageSchema, StatusOkSchema, } from '../types/entities.js';
5
+ import { resolveCreateId } from '../utils/uuidv7.js';
6
+ import { BaseClient } from './base-client.js';
7
+ export const ConversationMessageListSchema = z.array(ConversationMessageSchema);
8
+ /**
9
+ * Client for `/api/v1.0/conversation_messages/`. The SDK auto-generates the
10
+ * message `id` on `createMessage` when the caller doesn't supply one.
11
+ */
12
+ export class ConversationMessagesClient extends BaseClient {
13
+ constructor() {
14
+ super(...arguments);
15
+ this.linkBaseUrl = this.getLinkBaseUrl();
16
+ // Reuse the shared singletons when no custom base is configured.
17
+ this.messageSchema = this.linkBaseUrl
18
+ ? createConversationMessageSchema(this.linkBaseUrl)
19
+ : ConversationMessageSchema;
20
+ this.messageListSchema = this.linkBaseUrl
21
+ ? z.array(this.messageSchema)
22
+ : ConversationMessageListSchema;
23
+ }
24
+ /**
25
+ * Gets all messages in a conversation.
26
+ *
27
+ * @param args - The arguments for getting messages.
28
+ * @param args.conversationId - The conversation ID.
29
+ * @param args.newerThan - Optional date to get messages newer than.
30
+ * @param args.olderThan - Optional date to get messages older than.
31
+ * @param args.limit - Optional limit on number of messages returned.
32
+ * @param args.cursor - Optional cursor for pagination.
33
+ * @returns An array of message objects.
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * const messages = await api.conversationMessages.getMessages({
38
+ * conversationId: '7YpL3oZ4kZ9vP7Q1tR2sX42',
39
+ * newerThan: new Date('2024-01-01'),
40
+ * })
41
+ * ```
42
+ */
43
+ getMessages(args) {
44
+ const params = { conversationId: args.conversationId };
45
+ if (args.newerThan)
46
+ params.newerThanTs = Math.floor(args.newerThan.getTime() / 1000);
47
+ if (args.olderThan)
48
+ params.olderThanTs = Math.floor(args.olderThan.getTime() / 1000);
49
+ if (args.limit)
50
+ params.limit = args.limit;
51
+ if (args.cursor)
52
+ params.cursor = args.cursor;
53
+ return request({
54
+ httpMethod: 'GET',
55
+ baseUri: this.getBaseUri(),
56
+ relativePath: `${ENDPOINT_CONVERSATION_MESSAGES}/get`,
57
+ apiToken: this.apiToken,
58
+ payload: params,
59
+ headers: this.headers,
60
+ customFetch: this.customFetch,
61
+ }).then((response) => this.messageListSchema.parse(response.data));
62
+ }
63
+ /**
64
+ * Gets a single conversation message by id.
65
+ *
66
+ * @param id - The message ID.
67
+ * @returns The conversation message object.
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * const message = await api.conversationMessages.getMessage('7YpL3oZ4kZ9vP7Q1tR2sX43')
72
+ * ```
73
+ */
74
+ getMessage(id) {
75
+ return this.simple('GET', 'getone', { id }, this.messageSchema);
76
+ }
77
+ /**
78
+ * Creates a new message in a conversation. `id` is auto-generated if not
79
+ * supplied.
80
+ *
81
+ * @param args - The arguments for creating a message.
82
+ * @param args.conversationId - The conversation ID.
83
+ * @param args.content - The message content.
84
+ * @param args.attachments - Optional array of {@link Attachment} objects.
85
+ * @param args.actions - Optional array of action objects.
86
+ * @returns The created message object.
87
+ *
88
+ * @example
89
+ * ```typescript
90
+ * const message = await api.conversationMessages.createMessage({
91
+ * conversationId: '7YpL3oZ4kZ9vP7Q1tR2sX42',
92
+ * content: 'Thanks for the update!',
93
+ * })
94
+ * ```
95
+ */
96
+ createMessage(args) {
97
+ const params = {
98
+ conversationId: args.conversationId,
99
+ content: args.content,
100
+ id: resolveCreateId(args.id),
101
+ };
102
+ if (args.attachments)
103
+ params.attachments = args.attachments;
104
+ if (args.actions)
105
+ params.actions = args.actions;
106
+ if (args.directMentions)
107
+ params.directMentions = args.directMentions;
108
+ if (args.directGroupMentions)
109
+ params.directGroupMentions = args.directGroupMentions;
110
+ if (args.notify !== undefined)
111
+ params.notify = args.notify;
112
+ return this.simple('POST', 'add', params, this.messageSchema);
113
+ }
114
+ /**
115
+ * Updates a conversation message.
116
+ *
117
+ * @param args - The arguments for updating a message.
118
+ * @param args.id - The message ID.
119
+ * @param args.content - The new message content.
120
+ * @param args.attachments - Optional array of {@link Attachment} objects.
121
+ * @returns The updated message object.
122
+ *
123
+ * @example
124
+ * ```typescript
125
+ * const message = await api.conversationMessages.updateMessage({
126
+ * id: '7YpL3oZ4kZ9vP7Q1tR2sX43',
127
+ * content: 'Updated message content',
128
+ * })
129
+ * ```
130
+ */
131
+ updateMessage(args) {
132
+ const params = { id: args.id, content: args.content };
133
+ if (args.attachments)
134
+ params.attachments = args.attachments;
135
+ if (args.actions)
136
+ params.actions = args.actions;
137
+ if (args.directMentions)
138
+ params.directMentions = args.directMentions;
139
+ if (args.directGroupMentions)
140
+ params.directGroupMentions = args.directGroupMentions;
141
+ return this.simple('POST', 'update', params, this.messageSchema);
142
+ }
143
+ /**
144
+ * Permanently deletes a conversation message.
145
+ *
146
+ * @param id - The message ID.
147
+ *
148
+ * @example
149
+ * ```typescript
150
+ * await api.conversationMessages.deleteMessage('7YpL3oZ4kZ9vP7Q1tR2sX43')
151
+ * ```
152
+ */
153
+ deleteMessage(id) {
154
+ return this.simple('POST', 'remove', { id }, StatusOkSchema);
155
+ }
156
+ simple(httpMethod, suffix, params, schema) {
157
+ return request({
158
+ httpMethod,
159
+ baseUri: this.getBaseUri(),
160
+ relativePath: `${ENDPOINT_CONVERSATION_MESSAGES}/${suffix}`,
161
+ apiToken: this.apiToken,
162
+ payload: params,
163
+ headers: this.headers,
164
+ customFetch: this.customFetch,
165
+ }).then((response) => schema.parse(response.data));
166
+ }
167
+ }