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