@meet-im/meet-bot-jssdk 0.0.1

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.
@@ -0,0 +1,188 @@
1
+ type SessionType = 1 | 3;
2
+ interface SessionInfo {
3
+ firstID: number;
4
+ secondID: number;
5
+ sessionType: SessionType;
6
+ companyID?: number;
7
+ }
8
+ type MsgType = 'NORMAL' | 'RECALL' | 'QUOTE';
9
+ interface ExtraInfo {
10
+ msgType?: MsgType;
11
+ [key: string]: unknown;
12
+ }
13
+ interface MsgContent {
14
+ content: string;
15
+ seqId?: number;
16
+ timestamp?: number;
17
+ fromUid?: number;
18
+ atIds?: number[];
19
+ extraInfo?: ExtraInfo;
20
+ sessionInfo?: SessionInfo;
21
+ }
22
+ interface BotUpdate {
23
+ message?: MsgContent;
24
+ }
25
+ interface BotUser {
26
+ id: number;
27
+ name: string;
28
+ }
29
+ type ChatType = 'private' | 'group' | 'sub_group';
30
+ interface BotChat {
31
+ id: number;
32
+ type: ChatType;
33
+ title?: string;
34
+ }
35
+ interface BotFile {
36
+ file_id: string;
37
+ file_type: string;
38
+ file_name?: string;
39
+ file_size?: number;
40
+ }
41
+ interface BotMsg {
42
+ msg_id: number;
43
+ from: BotUser;
44
+ chat: BotChat;
45
+ text?: string;
46
+ attaches?: BotFile[];
47
+ quote?: BotMsg;
48
+ timestamp: number;
49
+ }
50
+
51
+ type ErrorCode = 'INVALID_TOKEN' | 'UNAUTHORIZED' | 'CHAT_NOT_FOUND' | 'RATE_LIMIT' | 'INTERNAL_ERROR' | 'NETWORK_ERROR' | 'TIMEOUT_ERROR' | 'VALIDATION_ERROR' | 'EMPTY_MESSAGE';
52
+ interface ApiErrorResponse {
53
+ ok: false;
54
+ error_code: number;
55
+ description: string;
56
+ retry_after?: number;
57
+ }
58
+ interface ApiResponse<T> {
59
+ ok: boolean;
60
+ result?: T;
61
+ error_code?: number;
62
+ description?: string;
63
+ }
64
+
65
+ interface MeetBotConfig {
66
+ token?: string;
67
+ botId?: string | number;
68
+ botToken?: string;
69
+ baseUrl?: string;
70
+ pollingLimit?: number;
71
+ pollingInterval?: number;
72
+ }
73
+ interface GetUpdatesOptions {
74
+ token: string;
75
+ baseUrl?: string;
76
+ timeout?: number;
77
+ offset?: number;
78
+ limit?: number;
79
+ }
80
+ interface SendMessageOptions {
81
+ token: string;
82
+ baseUrl?: string;
83
+ sessionInfo: SessionInfo;
84
+ msgContent: MsgContent;
85
+ }
86
+ interface SendMessageResult {
87
+ msgContent: MsgContent;
88
+ quoteMsg: unknown;
89
+ userProfileMap: Record<number, unknown>;
90
+ }
91
+ interface PollingOptions {
92
+ getUpdatesTimeout?: number;
93
+ limit?: number;
94
+ interval?: number;
95
+ retryDelay?: number;
96
+ maxRetries?: number;
97
+ onOffsetUpdate?: (offset: number) => void;
98
+ }
99
+
100
+ declare class MeetBotError extends Error {
101
+ readonly code: ErrorCode;
102
+ constructor(message: string, code: ErrorCode);
103
+ }
104
+ declare class ApiError extends MeetBotError {
105
+ readonly statusCode: number;
106
+ readonly retryAfter?: number;
107
+ constructor(message: string, statusCode: number, code: ErrorCode, retryAfter?: number);
108
+ }
109
+ declare class NetworkError extends MeetBotError {
110
+ readonly cause?: Error;
111
+ constructor(message: string, cause?: Error);
112
+ }
113
+ declare class TimeoutError extends MeetBotError {
114
+ constructor(message: string);
115
+ }
116
+ declare class ValidationError extends MeetBotError {
117
+ readonly field: string;
118
+ readonly value: unknown;
119
+ constructor(message: string, field: string, value: unknown);
120
+ }
121
+
122
+ type EventHandler<T = unknown> = (data: T) => void;
123
+ interface Events {
124
+ message: BotUpdate['message'];
125
+ error: Error;
126
+ polling_start: void;
127
+ polling_stop: void;
128
+ }
129
+ declare class MeetBot {
130
+ private readonly token;
131
+ private readonly baseUrl;
132
+ private readonly pollingLimit;
133
+ private readonly pollingInterval;
134
+ private readonly eventHandlers;
135
+ private polling;
136
+ private offset;
137
+ private retryCount;
138
+ private abortController;
139
+ constructor(config: MeetBotConfig);
140
+ on<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): this;
141
+ off<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): this;
142
+ private emit;
143
+ isPolling(): boolean;
144
+ startPolling(options?: PollingOptions): Promise<void>;
145
+ stopPolling(): void;
146
+ getUpdates(options?: {
147
+ timeout?: number;
148
+ offset?: number;
149
+ limit?: number;
150
+ }): Promise<BotUpdate[]>;
151
+ sendMessage(sessionInfo: SessionInfo, msgContent: MsgContent): Promise<SendMessageResult>;
152
+ private sleep;
153
+ }
154
+
155
+ interface GetUpdatesParams {
156
+ token: string;
157
+ baseUrl?: string;
158
+ timeout?: number;
159
+ offset?: number;
160
+ limit?: number;
161
+ }
162
+ declare function getUpdates(params: GetUpdatesParams): Promise<BotUpdate[]>;
163
+ interface SendMessageParams {
164
+ token: string;
165
+ baseUrl?: string;
166
+ sessionInfo: SessionInfo;
167
+ msgContent: MsgContent;
168
+ }
169
+ declare function sendMessage(params: SendMessageParams): Promise<SendMessageResult>;
170
+
171
+ declare const DEFAULT_BASE_URL = "https://staging-meet-api.miyachat.com";
172
+ declare const POLLING: {
173
+ readonly DEFAULT_LIMIT: 100;
174
+ readonly DEFAULT_INTERVAL: number;
175
+ readonly DEFAULT_RETRY_DELAY: 1000;
176
+ readonly MAX_RETRY_DELAY: 30000;
177
+ readonly DEFAULT_MAX_RETRIES: 3;
178
+ };
179
+ declare const HTTP: {
180
+ readonly DEFAULT_TIMEOUT: 60000;
181
+ readonly POLLING_TIMEOUT_BUFFER: 10000;
182
+ };
183
+ declare const API: {
184
+ readonly DEFAULT_TIMEOUT: 0;
185
+ readonly DEFAULT_LIMIT: 100;
186
+ };
187
+
188
+ export { API, ApiError, type ApiErrorResponse, type ApiResponse, type BotChat, type BotFile, type BotMsg, type BotUpdate, type BotUser, type ChatType, DEFAULT_BASE_URL, type ErrorCode, type ExtraInfo, type GetUpdatesOptions, HTTP, MeetBot, type MeetBotConfig, MeetBotError, type MsgContent, type MsgType, NetworkError, POLLING, type PollingOptions, type SendMessageOptions, type SendMessageResult, type SessionInfo, type SessionType, TimeoutError, ValidationError, getUpdates, sendMessage };
@@ -0,0 +1,188 @@
1
+ type SessionType = 1 | 3;
2
+ interface SessionInfo {
3
+ firstID: number;
4
+ secondID: number;
5
+ sessionType: SessionType;
6
+ companyID?: number;
7
+ }
8
+ type MsgType = 'NORMAL' | 'RECALL' | 'QUOTE';
9
+ interface ExtraInfo {
10
+ msgType?: MsgType;
11
+ [key: string]: unknown;
12
+ }
13
+ interface MsgContent {
14
+ content: string;
15
+ seqId?: number;
16
+ timestamp?: number;
17
+ fromUid?: number;
18
+ atIds?: number[];
19
+ extraInfo?: ExtraInfo;
20
+ sessionInfo?: SessionInfo;
21
+ }
22
+ interface BotUpdate {
23
+ message?: MsgContent;
24
+ }
25
+ interface BotUser {
26
+ id: number;
27
+ name: string;
28
+ }
29
+ type ChatType = 'private' | 'group' | 'sub_group';
30
+ interface BotChat {
31
+ id: number;
32
+ type: ChatType;
33
+ title?: string;
34
+ }
35
+ interface BotFile {
36
+ file_id: string;
37
+ file_type: string;
38
+ file_name?: string;
39
+ file_size?: number;
40
+ }
41
+ interface BotMsg {
42
+ msg_id: number;
43
+ from: BotUser;
44
+ chat: BotChat;
45
+ text?: string;
46
+ attaches?: BotFile[];
47
+ quote?: BotMsg;
48
+ timestamp: number;
49
+ }
50
+
51
+ type ErrorCode = 'INVALID_TOKEN' | 'UNAUTHORIZED' | 'CHAT_NOT_FOUND' | 'RATE_LIMIT' | 'INTERNAL_ERROR' | 'NETWORK_ERROR' | 'TIMEOUT_ERROR' | 'VALIDATION_ERROR' | 'EMPTY_MESSAGE';
52
+ interface ApiErrorResponse {
53
+ ok: false;
54
+ error_code: number;
55
+ description: string;
56
+ retry_after?: number;
57
+ }
58
+ interface ApiResponse<T> {
59
+ ok: boolean;
60
+ result?: T;
61
+ error_code?: number;
62
+ description?: string;
63
+ }
64
+
65
+ interface MeetBotConfig {
66
+ token?: string;
67
+ botId?: string | number;
68
+ botToken?: string;
69
+ baseUrl?: string;
70
+ pollingLimit?: number;
71
+ pollingInterval?: number;
72
+ }
73
+ interface GetUpdatesOptions {
74
+ token: string;
75
+ baseUrl?: string;
76
+ timeout?: number;
77
+ offset?: number;
78
+ limit?: number;
79
+ }
80
+ interface SendMessageOptions {
81
+ token: string;
82
+ baseUrl?: string;
83
+ sessionInfo: SessionInfo;
84
+ msgContent: MsgContent;
85
+ }
86
+ interface SendMessageResult {
87
+ msgContent: MsgContent;
88
+ quoteMsg: unknown;
89
+ userProfileMap: Record<number, unknown>;
90
+ }
91
+ interface PollingOptions {
92
+ getUpdatesTimeout?: number;
93
+ limit?: number;
94
+ interval?: number;
95
+ retryDelay?: number;
96
+ maxRetries?: number;
97
+ onOffsetUpdate?: (offset: number) => void;
98
+ }
99
+
100
+ declare class MeetBotError extends Error {
101
+ readonly code: ErrorCode;
102
+ constructor(message: string, code: ErrorCode);
103
+ }
104
+ declare class ApiError extends MeetBotError {
105
+ readonly statusCode: number;
106
+ readonly retryAfter?: number;
107
+ constructor(message: string, statusCode: number, code: ErrorCode, retryAfter?: number);
108
+ }
109
+ declare class NetworkError extends MeetBotError {
110
+ readonly cause?: Error;
111
+ constructor(message: string, cause?: Error);
112
+ }
113
+ declare class TimeoutError extends MeetBotError {
114
+ constructor(message: string);
115
+ }
116
+ declare class ValidationError extends MeetBotError {
117
+ readonly field: string;
118
+ readonly value: unknown;
119
+ constructor(message: string, field: string, value: unknown);
120
+ }
121
+
122
+ type EventHandler<T = unknown> = (data: T) => void;
123
+ interface Events {
124
+ message: BotUpdate['message'];
125
+ error: Error;
126
+ polling_start: void;
127
+ polling_stop: void;
128
+ }
129
+ declare class MeetBot {
130
+ private readonly token;
131
+ private readonly baseUrl;
132
+ private readonly pollingLimit;
133
+ private readonly pollingInterval;
134
+ private readonly eventHandlers;
135
+ private polling;
136
+ private offset;
137
+ private retryCount;
138
+ private abortController;
139
+ constructor(config: MeetBotConfig);
140
+ on<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): this;
141
+ off<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): this;
142
+ private emit;
143
+ isPolling(): boolean;
144
+ startPolling(options?: PollingOptions): Promise<void>;
145
+ stopPolling(): void;
146
+ getUpdates(options?: {
147
+ timeout?: number;
148
+ offset?: number;
149
+ limit?: number;
150
+ }): Promise<BotUpdate[]>;
151
+ sendMessage(sessionInfo: SessionInfo, msgContent: MsgContent): Promise<SendMessageResult>;
152
+ private sleep;
153
+ }
154
+
155
+ interface GetUpdatesParams {
156
+ token: string;
157
+ baseUrl?: string;
158
+ timeout?: number;
159
+ offset?: number;
160
+ limit?: number;
161
+ }
162
+ declare function getUpdates(params: GetUpdatesParams): Promise<BotUpdate[]>;
163
+ interface SendMessageParams {
164
+ token: string;
165
+ baseUrl?: string;
166
+ sessionInfo: SessionInfo;
167
+ msgContent: MsgContent;
168
+ }
169
+ declare function sendMessage(params: SendMessageParams): Promise<SendMessageResult>;
170
+
171
+ declare const DEFAULT_BASE_URL = "https://staging-meet-api.miyachat.com";
172
+ declare const POLLING: {
173
+ readonly DEFAULT_LIMIT: 100;
174
+ readonly DEFAULT_INTERVAL: number;
175
+ readonly DEFAULT_RETRY_DELAY: 1000;
176
+ readonly MAX_RETRY_DELAY: 30000;
177
+ readonly DEFAULT_MAX_RETRIES: 3;
178
+ };
179
+ declare const HTTP: {
180
+ readonly DEFAULT_TIMEOUT: 60000;
181
+ readonly POLLING_TIMEOUT_BUFFER: 10000;
182
+ };
183
+ declare const API: {
184
+ readonly DEFAULT_TIMEOUT: 0;
185
+ readonly DEFAULT_LIMIT: 100;
186
+ };
187
+
188
+ export { API, ApiError, type ApiErrorResponse, type ApiResponse, type BotChat, type BotFile, type BotMsg, type BotUpdate, type BotUser, type ChatType, DEFAULT_BASE_URL, type ErrorCode, type ExtraInfo, type GetUpdatesOptions, HTTP, MeetBot, type MeetBotConfig, MeetBotError, type MsgContent, type MsgType, NetworkError, POLLING, type PollingOptions, type SendMessageOptions, type SendMessageResult, type SessionInfo, type SessionType, TimeoutError, ValidationError, getUpdates, sendMessage };