@cored-im/openapi-sdk 0.28.102
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 +201 -0
- package/README.md +114 -0
- package/dist/index.cjs +1493 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +387 -0
- package/dist/index.d.ts +387 -0
- package/dist/index.js +1463 -0
- package/dist/index.js.map +1 -0
- package/package.json +53 -0
- package/src/client.ts +85 -0
- package/src/core/api_client.ts +344 -0
- package/src/core/config.ts +25 -0
- package/src/core/consts.ts +8 -0
- package/src/core/crypto.ts +212 -0
- package/src/core/http_client.ts +25 -0
- package/src/core/logger.ts +37 -0
- package/src/core/time_manager.ts +28 -0
- package/src/core/types.ts +72 -0
- package/src/core/version.ts +5 -0
- package/src/core/ws_client.ts +423 -0
- package/src/index.ts +19 -0
- package/src/internal/transport.ts +507 -0
- package/src/service/im/index.ts +11 -0
- package/src/service/im/v1/chat.ts +41 -0
- package/src/service/im/v1/chat_model.ts +19 -0
- package/src/service/im/v1/index.ts +9 -0
- package/src/service/im/v1/message.ts +59 -0
- package/src/service/im/v1/message_enum.ts +20 -0
- package/src/service/im/v1/message_event.ts +40 -0
- package/src/service/im/v1/message_model.ts +259 -0
- package/src/service/im/v1/v1.ts +14 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Code generated by Cored SDK Generator. DO NOT EDIT.
|
|
2
|
+
import type { Config } from '@/core/config';
|
|
3
|
+
import type { EventHeader, WrappedEventHandler } from '@/core/types';
|
|
4
|
+
import type { EventMessageReceiveBody } from './message_model';
|
|
5
|
+
|
|
6
|
+
/** Message received */
|
|
7
|
+
export interface EventMessageReceive {
|
|
8
|
+
header: EventHeader;
|
|
9
|
+
body: EventMessageReceiveBody;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class MessageEvent {
|
|
13
|
+
private readonly config: Config;
|
|
14
|
+
private readonly handlerMap = new Map<Function, WrappedEventHandler>();
|
|
15
|
+
|
|
16
|
+
constructor(config: Config) {
|
|
17
|
+
this.config = config;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Message received */
|
|
21
|
+
onMessageReceive(handler: (event: EventMessageReceive) => void): void {
|
|
22
|
+
const wrappedHandler = (header: EventHeader, body: Uint8Array | string): void => {
|
|
23
|
+
const event: EventMessageReceive = {
|
|
24
|
+
header,
|
|
25
|
+
body: typeof body === 'string' ? JSON.parse(body) as EventMessageReceiveBody : JSON.parse(new TextDecoder().decode(body)) as EventMessageReceiveBody,
|
|
26
|
+
};
|
|
27
|
+
handler(event);
|
|
28
|
+
};
|
|
29
|
+
this.handlerMap.set(handler, wrappedHandler);
|
|
30
|
+
this.config.apiClient.onEvent('im.v1.message.receive', wrappedHandler);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
offMessageReceive(handler: (event: EventMessageReceive) => void): void {
|
|
34
|
+
const wrappedHandler = this.handlerMap.get(handler);
|
|
35
|
+
if (wrappedHandler) {
|
|
36
|
+
this.config.apiClient.offEvent('im.v1.message.receive', wrappedHandler);
|
|
37
|
+
this.handlerMap.delete(handler);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
// Code generated by Cored SDK Generator. DO NOT EDIT.
|
|
2
|
+
import type { Int64 } from '@/core/types';
|
|
3
|
+
|
|
4
|
+
/** Send a message (Request) */
|
|
5
|
+
export interface SendMessageReq {
|
|
6
|
+
message_type?: string; // Message type
|
|
7
|
+
message_content?: MessageContent; // Message content
|
|
8
|
+
chat_id?: string; // Chat ID
|
|
9
|
+
reply_message_id?: string; // ID of the message being replied to
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** Send a message (Response) */
|
|
13
|
+
export interface SendMessageResp {
|
|
14
|
+
message_id?: string; // Message ID
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Get a message (Request) */
|
|
18
|
+
export interface GetMessageReq {
|
|
19
|
+
message_id?: string; // Message ID
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Get a message (Response) */
|
|
23
|
+
export interface GetMessageResp {
|
|
24
|
+
message?: Message; // Message
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Recall a message (Request) */
|
|
28
|
+
export interface RecallMessageReq {
|
|
29
|
+
message_id?: string; // Message ID
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Recall a message (Response) */
|
|
33
|
+
export interface RecallMessageResp {
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Mark message as read (Request) */
|
|
37
|
+
export interface ReadMessageReq {
|
|
38
|
+
message_id?: string; // Message ID
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Mark message as read (Response) */
|
|
42
|
+
export interface ReadMessageResp {
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Message content */
|
|
46
|
+
export interface MessageContent {
|
|
47
|
+
text?: MessageText; // Text message
|
|
48
|
+
image?: MessageImage; // Image message
|
|
49
|
+
sticker?: MessageSticker; // Sticker message
|
|
50
|
+
video?: MessageVideo; // Video message
|
|
51
|
+
audio?: MessageAudio; // Audio message
|
|
52
|
+
file?: MessageFile; // File message
|
|
53
|
+
user_card?: MessageUserCard; // User card message
|
|
54
|
+
group_card?: MessageGroupCard; // Group card message
|
|
55
|
+
group_announcement?: MessageGroupAnnouncement; // Group announcement
|
|
56
|
+
card?: MessageCard; // Card message
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Text message */
|
|
60
|
+
export interface MessageText {
|
|
61
|
+
content?: string; // Content
|
|
62
|
+
attachment_list?: MessageTextAttachment[]; // Attachment list, referenced in content as {{attach:id}}
|
|
63
|
+
mention_user_list?: MessageTextMentionUser[]; // Mentioned user list, referenced in content as {{mention:user_id}}. Use user_id "all" to mention everyone
|
|
64
|
+
emoji_list?: MessageTextEmoji[]; // Emoji list, referenced in content as {{emoji:emoji_id}}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Attachment */
|
|
68
|
+
export interface MessageTextAttachment {
|
|
69
|
+
attachment_id?: string; // Attachment ID, referenced in content as {{id}}, defined by the client
|
|
70
|
+
attachment_type?: string; // Attachment type
|
|
71
|
+
attachment_content?: MessageTextAttachmentContent; // Attachment content
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Attachment content */
|
|
75
|
+
export interface MessageTextAttachmentContent {
|
|
76
|
+
image?: FileImage; // Image
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Image file */
|
|
80
|
+
export interface FileImage {
|
|
81
|
+
image?: File; // Image, max width/height 1024
|
|
82
|
+
image_width?: Int64; // Image width
|
|
83
|
+
image_height?: Int64; // Image height
|
|
84
|
+
image_origin?: File; // Original image
|
|
85
|
+
image_origin_width?: Int64; // Original image width
|
|
86
|
+
image_origin_height?: Int64; // Original image height
|
|
87
|
+
image_thumb_bytes?: Uint8Array; // Thumbnail data, max width/height 40
|
|
88
|
+
image_thumb_mime?: string; // Thumbnail MIME type
|
|
89
|
+
image_dominant_color?: string; // Dominant color of the image, in #ffffff format
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** File */
|
|
93
|
+
export interface File {
|
|
94
|
+
file_id?: string; // File ID
|
|
95
|
+
file_mime?: string; // File MIME type
|
|
96
|
+
file_size?: Int64; // File size
|
|
97
|
+
file_encryption?: Encryption; // File encryption
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Encryption */
|
|
101
|
+
export interface Encryption {
|
|
102
|
+
encryption_algorithm?: string; // Encryption algorithm
|
|
103
|
+
encryption_key?: Uint8Array; // Encryption key
|
|
104
|
+
encrypted_size?: Int64; // Encrypted size
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Mentioned user */
|
|
108
|
+
export interface MessageTextMentionUser {
|
|
109
|
+
user_id?: UserId; // User ID
|
|
110
|
+
user_name?: string; // Username at the time of mention
|
|
111
|
+
is_in_chat?: boolean; // Whether the user was in the chat at the time
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** User ID */
|
|
115
|
+
export interface UserId {
|
|
116
|
+
user_id?: string; // User ID in the platform. The same user has the same user_id across all apps
|
|
117
|
+
union_user_id?: string; // User ID within the same app group. The same user has the same union_user_id across different apps in the same group
|
|
118
|
+
open_user_id?: string; // User ID within an app. The same user has different open_user_id values in different apps
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export interface MessageTextEmoji {
|
|
122
|
+
emoji_id?: string; // Emoji ID
|
|
123
|
+
emoji_name?: string; // Emoji name at the time
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Image message */
|
|
127
|
+
export interface MessageImage {
|
|
128
|
+
image?: FileImage; // Image
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** Sticker message */
|
|
132
|
+
export interface MessageSticker {
|
|
133
|
+
sticker?: Sticker; // Sticker
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** Sticker */
|
|
137
|
+
export interface Sticker {
|
|
138
|
+
sticker_id?: string; // Sticker ID
|
|
139
|
+
sticker_name?: string; // Sticker name
|
|
140
|
+
sticker_name_i18n?: Record<string, string>; // Sticker internationalized name
|
|
141
|
+
sticker_image?: FileImage; // Sticker image
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Video message */
|
|
145
|
+
export interface MessageVideo {
|
|
146
|
+
video?: FileVideo; // Video
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Video file */
|
|
150
|
+
export interface FileVideo {
|
|
151
|
+
video?: File; // Video
|
|
152
|
+
video_width?: Int64; // Video width
|
|
153
|
+
video_height?: Int64; // Video height
|
|
154
|
+
video_duration?: number; // Video duration
|
|
155
|
+
video_preview?: FileImage; // Video preview image
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** Audio message */
|
|
159
|
+
export interface MessageAudio {
|
|
160
|
+
audio?: FileAudio; // Audio
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** Audio file */
|
|
164
|
+
export interface FileAudio {
|
|
165
|
+
audio?: File; // Audio
|
|
166
|
+
audio_duration?: number; // Audio duration
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** File message */
|
|
170
|
+
export interface MessageFile {
|
|
171
|
+
file?: File; // File
|
|
172
|
+
filename?: string; // Filename
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** User card message */
|
|
176
|
+
export interface MessageUserCard {
|
|
177
|
+
user_id?: UserId; // User ID
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** Group card message */
|
|
181
|
+
export interface MessageGroupCard {
|
|
182
|
+
chat_id?: string; // Chat ID
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** Group announcement */
|
|
186
|
+
export interface MessageGroupAnnouncement {
|
|
187
|
+
message_text?: MessageText; // Announcement content
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** Card message */
|
|
191
|
+
export interface MessageCard {
|
|
192
|
+
schema?: string; // Card schema version
|
|
193
|
+
v1?: MessageCardV1; // V1
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** V1 */
|
|
197
|
+
export interface MessageCardV1 {
|
|
198
|
+
header?: MessageCardV1Header; // Card header
|
|
199
|
+
body?: MessageCardV1Body; // Card body
|
|
200
|
+
footer?: MessageCardV1Footer; // Card footer
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** Card header */
|
|
204
|
+
export interface MessageCardV1Header {
|
|
205
|
+
title?: string; // Title text
|
|
206
|
+
title_i18n?: Record<string, string>; // Internationalized title text
|
|
207
|
+
template?: string; // Title color template
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** Card body */
|
|
211
|
+
export interface MessageCardV1Body {
|
|
212
|
+
message_text?: MessageText; // Card body text message
|
|
213
|
+
message_text_i18n?: Record<string, MessageText>; // Internationalized card body text message
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** Card footer */
|
|
217
|
+
export interface MessageCardV1Footer {
|
|
218
|
+
button_list?: MessageCardV1Button[]; // Button list
|
|
219
|
+
button_align?: string; // Button alignment
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** Card button */
|
|
223
|
+
export interface MessageCardV1Button {
|
|
224
|
+
button_text?: string; // Button text
|
|
225
|
+
button_text_i18n?: Record<string, string>; // Internationalized button text
|
|
226
|
+
template?: string; // Button style template, values: default, primary, danger, primary_text, danger_text, primary_filled, danger_filled
|
|
227
|
+
link?: MessageCardV1ButtonLink; // Button link
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** Link */
|
|
231
|
+
export interface MessageCardV1ButtonLink {
|
|
232
|
+
url?: string; // Default URL
|
|
233
|
+
android_url?: string; // Android URL
|
|
234
|
+
ios_url?: string; // iOS URL
|
|
235
|
+
pc_url?: string; // Desktop URL
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** Message */
|
|
239
|
+
export interface Message {
|
|
240
|
+
message_id?: string; // Message ID
|
|
241
|
+
message_type?: string; // Message type
|
|
242
|
+
message_status?: string; // Message status
|
|
243
|
+
message_content?: MessageContent; // Message content
|
|
244
|
+
message_created_at?: Int64; // Message creation time (milliseconds)
|
|
245
|
+
chat_id?: string; // Chat ID
|
|
246
|
+
chat_seq_id?: Int64; // Server-generated monotonically increasing ID at the chat level, used for ordering within a chat
|
|
247
|
+
sender_id?: UserId; // Sender ID
|
|
248
|
+
reply?: MessagePropReply; // Reply properties
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/** Message reply properties */
|
|
252
|
+
export interface MessagePropReply {
|
|
253
|
+
reply_message_id?: string; // ID of the message being replied to
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/** Message received */
|
|
257
|
+
export interface EventMessageReceiveBody {
|
|
258
|
+
message?: Message; // Message
|
|
259
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Code generated by Cored SDK Generator. DO NOT EDIT.
|
|
2
|
+
import type { Config } from '@/core/config';
|
|
3
|
+
import { Chat } from './chat';
|
|
4
|
+
import { Message } from './message';
|
|
5
|
+
|
|
6
|
+
export class V1 {
|
|
7
|
+
public readonly Chat: Chat;
|
|
8
|
+
public readonly Message: Message;
|
|
9
|
+
|
|
10
|
+
constructor(config: Config) {
|
|
11
|
+
this.Chat = new Chat(config);
|
|
12
|
+
this.Message = new Message(config);
|
|
13
|
+
}
|
|
14
|
+
}
|