lansenger-cli 1.0.0 → 1.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.
@@ -7,24 +7,27 @@ function registerMessageCommands(program) {
7
7
  cmd
8
8
  .command("send-text")
9
9
  .description("Send a text message")
10
- .requiredOption("-c, --chat-id <chatId>", "Chat ID (receiver)")
11
- .requiredOption("--content <content>", "Message content")
10
+ .argument("<chatId>", "Chat ID (user/group)")
11
+ .argument("<content>", "Text content")
12
+ .option("-f, --file <path>", "File path to attach", "")
13
+ .option("-t, --media-type <type>", "1=video, 2=image, 3=file (auto-detected if omitted)")
14
+ .option("--cover-image <path>", "Cover image path for video attachments", "")
12
15
  .option("-g, --group", "Send as group message", false)
13
- .option("--mention-all", "Mention all group members", false)
14
- .option("--mention <ids>", "Comma-separated user IDs to mention")
15
- .option("--user-token <token>", "User token for user-context sending")
16
- .option("--file-path <path>", "File path to attach")
17
- .option("--media-type <type>", "Media type (1=video,2=image,3=file)")
18
- .action(async (opts) => {
16
+ .option("--mention-all", "@all in group", false)
17
+ .option("--mention <ids...>", "User IDs to @mention (space-separated, e.g. --mention id1 id2)")
18
+ .option("--user-token <token>", "User token for private channel", "")
19
+ .option("--sender-id <senderId>", "Sender staff ID for group message", "")
20
+ .action(async (chatId, content, opts) => {
19
21
  const client = (0, utils_1.getClient)();
20
- const mentionUserIds = opts.mention ? (0, utils_1.commaList)(opts.mention) : undefined;
21
- const result = await client.sendText(opts.chatId, opts.content, {
22
+ const result = await client.sendText(chatId, content, {
23
+ file_path: opts.file || undefined,
24
+ media_type: opts.mediaType ? parseInt(opts.mediaType) : undefined,
25
+ cover_image_path: opts.coverImage || undefined,
22
26
  is_group: opts.group,
23
27
  reminder_all: opts.mentionAll,
24
- reminder_user_ids: mentionUserIds,
28
+ reminder_user_ids: opts.mention || undefined,
25
29
  user_token: opts.userToken || undefined,
26
- file_path: opts.filePath || undefined,
27
- media_type: opts.mediaType ? parseInt(opts.mediaType) : undefined,
30
+ sender_id: opts.senderId || undefined,
28
31
  });
29
32
  (0, utils_1.checkError)(result);
30
33
  (0, utils_1.outputResult)(result);
@@ -32,20 +35,21 @@ function registerMessageCommands(program) {
32
35
  cmd
33
36
  .command("send-markdown")
34
37
  .description("Send a markdown/formatted text message")
35
- .requiredOption("-c, --chat-id <chatId>", "Chat ID (receiver)")
36
- .requiredOption("--content <content>", "Markdown content")
38
+ .argument("<chatId>", "Chat ID")
39
+ .argument("<content>", "Markdown content")
40
+ .option("--mention-all", "@all in group", false)
41
+ .option("--mention <ids...>", "User IDs to @mention (space-separated, e.g. --mention id1 id2)")
37
42
  .option("-g, --group", "Send as group message", false)
38
- .option("--mention-all", "Mention all group members", false)
39
- .option("--mention <ids>", "Comma-separated user IDs to mention")
40
- .option("--user-token <token>", "User token for user-context sending")
41
- .action(async (opts) => {
43
+ .option("--user-token <token>", "User token for private channel", "")
44
+ .option("--sender-id <senderId>", "Sender staff ID for group message", "")
45
+ .action(async (chatId, content, opts) => {
42
46
  const client = (0, utils_1.getClient)();
43
- const mentionUserIds = opts.mention ? (0, utils_1.commaList)(opts.mention) : undefined;
44
- const result = await client.sendMarkdown(opts.chatId, opts.content, {
45
- is_group: opts.group,
47
+ const result = await client.sendMarkdown(chatId, content, {
46
48
  reminder_all: opts.mentionAll,
47
- reminder_user_ids: mentionUserIds,
49
+ reminder_user_ids: opts.mention || undefined,
50
+ is_group: opts.group,
48
51
  user_token: opts.userToken || undefined,
52
+ sender_id: opts.senderId || undefined,
49
53
  });
50
54
  (0, utils_1.checkError)(result);
51
55
  (0, utils_1.outputResult)(result);
@@ -53,104 +57,147 @@ function registerMessageCommands(program) {
53
57
  cmd
54
58
  .command("send-file")
55
59
  .description("Send a file message")
56
- .requiredOption("-c, --chat-id <chatId>", "Chat ID (receiver)")
57
- .requiredOption("--file-path <path>", "File path to send")
58
- .option("--caption <caption>", "Caption text")
59
- .option("--media-type <type>", "Media type (1=video,2=image,3=file)")
60
+ .argument("<chatId>", "Chat ID")
61
+ .argument("<filePath>", "Local file path")
62
+ .option("-c, --content <content>", "Content/caption text", "")
63
+ .option("--media-type <type>", "1=video, 2=image, 3=file")
64
+ .option("--cover-image <path>", "Cover image path for video attachments", "")
60
65
  .option("-g, --group", "Send as group message", false)
61
- .option("--user-token <token>", "User token for user-context sending")
62
- .action(async (opts) => {
66
+ .option("--user-token <token>", "User token for private channel", "")
67
+ .option("--sender-id <senderId>", "Sender staff ID for group message", "")
68
+ .action(async (chatId, filePath, opts) => {
63
69
  const client = (0, utils_1.getClient)();
64
- const result = await client.sendFile(opts.chatId, opts.filePath, {
65
- caption: opts.caption || undefined,
70
+ const result = await client.sendFile(chatId, filePath, {
71
+ caption: opts.content || undefined,
66
72
  media_type: opts.mediaType ? parseInt(opts.mediaType) : undefined,
73
+ cover_image_path: opts.coverImage || undefined,
67
74
  is_group: opts.group,
68
75
  user_token: opts.userToken || undefined,
76
+ sender_id: opts.senderId || undefined,
69
77
  });
70
78
  (0, utils_1.checkError)(result);
71
79
  (0, utils_1.outputResult)(result);
72
80
  });
73
81
  cmd
74
- .command("send-link-card")
75
- .description("Send a link card message")
76
- .requiredOption("-c, --chat-id <chatId>", "Chat ID (receiver)")
77
- .requiredOption("--title <title>", "Card title")
78
- .requiredOption("--link <link>", "Card link URL")
79
- .option("--description <desc>", "Card description")
82
+ .command("send-image-url")
83
+ .description("Send an image by URL")
84
+ .argument("<chatId>", "Chat ID")
85
+ .argument("<imageUrl>", "Image URL to send")
86
+ .option("-c, --content <content>", "Content/caption text", "")
80
87
  .option("-g, --group", "Send as group message", false)
81
- .option("--user-token <token>", "User token for user-context sending")
82
- .action(async (opts) => {
88
+ .option("--user-token <token>", "User token for private channel", "")
89
+ .option("--sender-id <senderId>", "Sender staff ID for group message", "")
90
+ .action(async (chatId, imageUrl, opts) => {
83
91
  const client = (0, utils_1.getClient)();
84
- const result = await client.sendLinkCard(opts.chatId, opts.title, opts.link, {
85
- description: opts.description || undefined,
92
+ const result = await client.sendImageUrl(chatId, imageUrl, {
93
+ caption: opts.content || undefined,
86
94
  is_group: opts.group,
87
95
  user_token: opts.userToken || undefined,
96
+ sender_id: opts.senderId || undefined,
88
97
  });
89
98
  (0, utils_1.checkError)(result);
90
99
  (0, utils_1.outputResult)(result);
91
100
  });
92
101
  cmd
93
- .command("send-app-articles")
94
- .description("Send app articles message")
95
- .requiredOption("-c, --chat-id <chatId>", "Chat ID (receiver)")
96
- .requiredOption("--articles <json>", "Articles JSON array")
102
+ .command("send-link-card")
103
+ .description("Send a link card message")
104
+ .argument("<chatId>", "Chat ID")
105
+ .argument("<title>", "Card title")
106
+ .argument("<link>", "Card link URL")
107
+ .option("-d, --desc <desc>", "Card description", "")
108
+ .option("--icon <url>", "Icon URL", "")
109
+ .option("--pc-link <url>", "PC link URL", "")
110
+ .option("--pad-link <url>", "Pad link URL", "")
111
+ .option("--from-name <name>", "Source name", "")
112
+ .option("--from-icon <url>", "Source icon URL", "")
97
113
  .option("-g, --group", "Send as group message", false)
98
- .option("--user-token <token>", "User token for user-context sending")
99
- .action(async (opts) => {
114
+ .option("--user-token <token>", "User token for private channel", "")
115
+ .option("--sender-id <senderId>", "Sender staff ID for group message", "")
116
+ .action(async (chatId, title, link, opts) => {
100
117
  const client = (0, utils_1.getClient)();
101
- const articles = (0, utils_1.parseJsonOption)(opts.articles);
102
- const result = await client.sendAppArticles(opts.chatId, articles, {
118
+ const result = await client.sendLinkCard(chatId, title, link, {
119
+ description: opts.desc || undefined,
120
+ icon_link: opts.icon || undefined,
121
+ pc_link: opts.pcLink || undefined,
122
+ pad_link: opts.padLink || undefined,
123
+ from_name: opts.fromName || undefined,
124
+ from_icon_link: opts.fromIcon || undefined,
103
125
  is_group: opts.group,
104
126
  user_token: opts.userToken || undefined,
127
+ sender_id: opts.senderId || undefined,
105
128
  });
106
129
  (0, utils_1.checkError)(result);
107
130
  (0, utils_1.outputResult)(result);
108
131
  });
109
132
  cmd
110
- .command("send-app-card")
111
- .description("Send an app card message")
112
- .requiredOption("-c, --chat-id <chatId>", "Chat ID (receiver)")
113
- .requiredOption("--body-title <title>", "Card body title")
114
- .option("--head-title <title>", "Card head title")
115
- .option("--body-content <content>", "Card body content")
116
- .option("--is-dynamic", "Mark as dynamic card", false)
117
- .option("--fields <json>", "Card fields JSON array")
118
- .option("--links <json>", "Card links JSON array")
133
+ .command("send-app-articles")
134
+ .description("Send app articles message")
135
+ .argument("<chatId>", "Chat ID")
136
+ .argument("<articles...>", "Articles as JSON dicts, e.g. '{\"title\":\"T\",\"url\":\"U\"}'")
119
137
  .option("-g, --group", "Send as group message", false)
120
- .option("--user-token <token>", "User token for user-context sending")
121
- .action(async (opts) => {
138
+ .option("--user-token <token>", "User token for private channel", "")
139
+ .option("--sender-id <senderId>", "Sender staff ID for group message", "")
140
+ .action(async (chatId, articles, opts) => {
122
141
  const client = (0, utils_1.getClient)();
123
- const fields = opts.fields ? (0, utils_1.parseJsonOption)(opts.fields) : undefined;
124
- const links = opts.links ? (0, utils_1.parseJsonOption)(opts.links) : undefined;
125
- const result = await client.sendAppCard(opts.chatId, opts.bodyTitle, {
126
- head_title: opts.headTitle || undefined,
127
- body_content: opts.bodyContent || undefined,
128
- is_dynamic: opts.isDynamic,
129
- fields,
130
- links,
142
+ const parsed = articles.map((a) => (0, utils_1.parseJsonOption)(a));
143
+ const result = await client.sendAppArticles(chatId, parsed, {
131
144
  is_group: opts.group,
132
145
  user_token: opts.userToken || undefined,
146
+ sender_id: opts.senderId || undefined,
133
147
  });
134
148
  (0, utils_1.checkError)(result);
135
149
  (0, utils_1.outputResult)(result);
136
150
  });
137
151
  cmd
138
- .command("send-oacard")
139
- .description("Send an OA card message")
140
- .requiredOption("-c, --chat-id <chatId>", "Chat ID (receiver)")
141
- .requiredOption("--title <title>", "OA card title")
142
- .option("--fields <json>", "OA card fields JSON array")
143
- .option("--link <link>", "OA card link URL")
152
+ .command("send-app-card")
153
+ .description("Send an app card message")
154
+ .argument("<chatId>", "Chat ID")
155
+ .argument("<bodyTitle>", "Card body title")
156
+ .option("--head-title <title>", "Card head title", "")
157
+ .option("--sub-title <sub>", "Card sub title", "")
158
+ .option("--content <content>", "Card body content (supports div-style HTML)", "")
159
+ .option("--signature <sig>", "Card signature", "")
160
+ .option("--card-link <url>", "Card link URL", "")
161
+ .option("--pc-card-link <url>", "PC card link URL", "")
162
+ .option("--pad-card-link <url>", "Pad card link URL", "")
163
+ .option("--dynamic", "Enable dynamic card updates", false)
164
+ .option("--staff-id <id>", "Staff ID", "")
165
+ .option("--head-icon <url>", "Head icon URL", "")
166
+ .option("--status-desc <desc>", "Head status description (div-style HTML, max 30 bytes)", "")
167
+ .option("--status-colour <colour>", "Head status DOT colour (hex, e.g. #FFB116)", "")
168
+ .option("--field <json...>", "Card field as JSON, space-separated, e.g. --field '{\"key\":\"k\",\"value\":\"v\"}' '{\"key\":\"k2\",\"value\":\"v2\"}'")
169
+ .option("--link <json...>", "Card link as JSON, space-separated, e.g. --link '{\"title\":\"T\",\"url\":\"U\"}' '{\"title\":\"T2\",\"url\":\"U2\"}'")
144
170
  .option("-g, --group", "Send as group message", false)
145
- .option("--user-token <token>", "User token for user-context sending")
146
- .action(async (opts) => {
171
+ .option("--user-token <token>", "User token for private channel", "")
172
+ .option("--sender-id <senderId>", "Sender staff ID for group message", "")
173
+ .action(async (chatId, bodyTitle, opts) => {
147
174
  const client = (0, utils_1.getClient)();
148
- const fields = opts.fields ? (0, utils_1.parseJsonOption)(opts.fields) : undefined;
149
- const result = await client.sendOacard(opts.chatId, opts.title, {
150
- fields,
151
- link: opts.link || undefined,
175
+ let headStatusInfo = undefined;
176
+ if (opts.statusDesc || opts.statusColour) {
177
+ headStatusInfo = {
178
+ description: opts.statusDesc || "",
179
+ colour: opts.statusColour || "",
180
+ };
181
+ }
182
+ const parsedFields = opts.field ? opts.field.map((f) => (0, utils_1.parseJsonOption)(f)) : undefined;
183
+ const parsedLinks = opts.link ? opts.link.map((l) => (0, utils_1.parseJsonOption)(l)) : undefined;
184
+ const result = await client.sendAppCard(chatId, bodyTitle, {
185
+ head_title: opts.headTitle || undefined,
186
+ body_sub_title: opts.subTitle || undefined,
187
+ body_content: opts.content || undefined,
188
+ signature: opts.signature || undefined,
189
+ card_link: opts.cardLink || undefined,
190
+ pc_card_link: opts.pcCardLink || undefined,
191
+ pad_card_link: opts.padCardLink || undefined,
192
+ is_dynamic: opts.dynamic,
193
+ staff_id: opts.staffId || undefined,
194
+ head_icon_url: opts.headIcon || undefined,
195
+ head_status_info: headStatusInfo,
196
+ fields: parsedFields,
197
+ links: parsedLinks,
152
198
  is_group: opts.group,
153
199
  user_token: opts.userToken || undefined,
200
+ sender_id: opts.senderId || undefined,
154
201
  });
155
202
  (0, utils_1.checkError)(result);
156
203
  (0, utils_1.outputResult)(result);
@@ -158,18 +205,25 @@ function registerMessageCommands(program) {
158
205
  cmd
159
206
  .command("update-dynamic-card")
160
207
  .description("Update a dynamic card message")
161
- .requiredOption("--msg-id <msgId>", "Message ID of the dynamic card")
162
- .option("--is-last-update", "Mark as last update", false)
163
- .option("--head-status-info <json>", "Head status info JSON")
164
- .option("--links <json>", "Updated links JSON array")
165
- .action(async (opts) => {
208
+ .argument("<msgId>", "Message ID of the dynamic card")
209
+ .option("--last", "Mark as last update", false)
210
+ .option("--status-desc <desc>", "New status description (div-style HTML, max 30 bytes)", "")
211
+ .option("--status-colour <colour>", "New status DOT colour (hex)", "")
212
+ .option("--link <json...>", "Updated link as JSON, space-separated")
213
+ .action(async (msgId, opts) => {
166
214
  const client = (0, utils_1.getClient)();
167
- const headStatusInfo = opts.headStatusInfo ? (0, utils_1.parseJsonOption)(opts.headStatusInfo) : undefined;
168
- const links = opts.links ? (0, utils_1.parseJsonOption)(opts.links) : undefined;
169
- const result = await client.updateDynamicCard(opts.msgId, {
170
- is_last_update: opts.isLastUpdate,
215
+ let headStatusInfo = undefined;
216
+ if (opts.statusDesc || opts.statusColour) {
217
+ headStatusInfo = {
218
+ description: opts.statusDesc || "",
219
+ colour: opts.statusColour || "",
220
+ };
221
+ }
222
+ const parsedLinks = opts.link ? opts.link.map((l) => (0, utils_1.parseJsonOption)(l)) : undefined;
223
+ const result = await client.updateDynamicCard(msgId, {
224
+ is_last_update: opts.last,
171
225
  head_status_info: headStatusInfo,
172
- links,
226
+ links: parsedLinks,
173
227
  });
174
228
  (0, utils_1.checkError)(result);
175
229
  (0, utils_1.outputResult)(result);
@@ -177,78 +231,170 @@ function registerMessageCommands(program) {
177
231
  cmd
178
232
  .command("revoke")
179
233
  .description("Revoke messages by IDs")
180
- .requiredOption("--message-ids <ids>", "Comma-separated message IDs to revoke")
181
- .action(async (opts) => {
234
+ .argument("<messageIds...>", "Message IDs to revoke")
235
+ .option("--chat-type <type>", "staff, group, notification, account, or bot", "bot")
236
+ .option("--sender-id <senderId>", "Sender staff ID (required for staff/group)", "")
237
+ .action(async (messageIds, opts) => {
182
238
  const client = (0, utils_1.getClient)();
183
- const messageIds = (0, utils_1.commaList)(opts.messageIds);
184
- const result = await client.revokeMessage(messageIds);
239
+ const result = await client.revokeMessage(messageIds, {
240
+ chat_type: opts.chatType,
241
+ sender_id: opts.senderId || undefined,
242
+ });
185
243
  (0, utils_1.checkError)(result);
186
244
  (0, utils_1.outputResult)(result);
187
245
  });
188
246
  cmd
189
- .command("send-account-message")
190
- .description("Send a public account message")
191
- .requiredOption("--msg-type <msgType>", "Message type")
192
- .requiredOption("--msg-data <json>", "Message data JSON")
193
- .requiredOption("--chat-ids <ids>", "Comma-separated chat IDs")
194
- .option("--dept-ids <ids>", "Comma-separated department IDs")
195
- .option("--account-id <id>", "Account ID")
196
- .option("--user-token <token>", "User token")
197
- .action(async (opts) => {
247
+ .command("send-bot-message")
248
+ .description("Send a bot notification message")
249
+ .argument("<msgType>", "Message type")
250
+ .argument("<msgData>", "Message data as JSON")
251
+ .option("--chat-id <ids...>", "Chat IDs, space-separated (or group IDs if --group)")
252
+ .option("--dept <ids...>", "Department IDs, space-separated (bot channel only)")
253
+ .option("--user-token <token>", "User token", "")
254
+ .option("--entry-id <entryId>", "App entry selector", "")
255
+ .option("-g, --group", "Send to groups instead of users", false)
256
+ .action(async (msgType, msgData, opts) => {
198
257
  const client = (0, utils_1.getClient)();
199
- const msgData = (0, utils_1.parseJsonOption)(opts.msgData);
200
- const chatIds = (0, utils_1.commaList)(opts.chatIds);
201
- const deptIds = opts.deptIds ? (0, utils_1.commaList)(opts.deptIds) : undefined;
202
- const result = await client.sendAccountMessage(opts.msgType, msgData, chatIds, deptIds, {
203
- account_id: opts.accountId || undefined,
258
+ const parsedData = (0, utils_1.parseJsonOption)(msgData);
259
+ const result = await client.sendBotMessage(msgType, parsedData, opts.chatId || undefined, opts.dept || undefined, {
204
260
  user_token: opts.userToken || undefined,
261
+ entry_id: opts.entryId || undefined,
262
+ is_group: opts.group,
205
263
  });
206
264
  (0, utils_1.checkError)(result);
207
265
  (0, utils_1.outputResult)(result);
208
266
  });
209
267
  cmd
210
- .command("send-user-message")
211
- .description("Send a user-to-user private message")
212
- .requiredOption("--receiver-id <receiverId>", "Receiver staff ID")
213
- .requiredOption("--msg-type <msgType>", "Message type")
214
- .requiredOption("--msg-data <json>", "Message data JSON")
215
- .option("--user-token <token>", "User token")
216
- .action(async (opts) => {
268
+ .command("send-group-message")
269
+ .description("Send a group message")
270
+ .argument("<groupId>", "Group ID")
271
+ .argument("<msgType>", "Message type")
272
+ .argument("<msgData>", "Message data as JSON")
273
+ .option("--user-token <token>", "User token", "")
274
+ .option("--sender-id <senderId>", "Sender staff ID", "")
275
+ .option("--mention-all", "@all (text/formatText only)", false)
276
+ .option("--mention <ids...>", "User IDs to @mention, space-separated (text/formatText only)")
277
+ .option("--outlines <outlines>", "Group notification digest", "")
278
+ .option("--entry-id <entryId>", "App entry selector", "")
279
+ .action(async (groupId, msgType, msgData, opts) => {
217
280
  const client = (0, utils_1.getClient)();
218
- const msgData = (0, utils_1.parseJsonOption)(opts.msgData);
219
- const result = await client.sendUserMessage(opts.receiverId, opts.msgType, msgData, {
281
+ const parsedData = (0, utils_1.parseJsonOption)(msgData);
282
+ const result = await client.sendGroupMessage(groupId, msgType, parsedData, {
220
283
  user_token: opts.userToken || undefined,
284
+ sender_id: opts.senderId || undefined,
285
+ reminder_all: opts.mentionAll,
286
+ reminder_user_ids: opts.mention || undefined,
287
+ outlines: opts.outlines || undefined,
288
+ entry_id: opts.entryId || undefined,
221
289
  });
222
290
  (0, utils_1.checkError)(result);
223
291
  (0, utils_1.outputResult)(result);
224
292
  });
225
293
  cmd
226
- .command("send-group-message")
227
- .description("Send a group message")
228
- .requiredOption("--group-id <groupId>", "Group ID")
229
- .requiredOption("--msg-type <msgType>", "Message type")
230
- .requiredOption("--msg-data <json>", "Message data JSON")
231
- .option("--user-token <token>", "User token")
294
+ .command("query-groups")
295
+ .description("Query group IDs with pagination")
296
+ .option("-p, --page <page>", "Page offset", "1")
297
+ .option("-s, --size <size>", "Page size", "100")
232
298
  .action(async (opts) => {
233
299
  const client = (0, utils_1.getClient)();
234
- const msgData = (0, utils_1.parseJsonOption)(opts.msgData);
235
- const result = await client.sendGroupMessage(opts.groupId, opts.msgType, msgData, {
300
+ const result = await client.queryGroups({
301
+ page_offset: parseInt(opts.page),
302
+ page_size: parseInt(opts.size),
303
+ });
304
+ (0, utils_1.checkError)(result);
305
+ (0, utils_1.outputResult)(result);
306
+ });
307
+ cmd
308
+ .command("send-oacard")
309
+ .description("Send an OA card message")
310
+ .argument("<chatId>", "Chat ID")
311
+ .argument("<title>", "OA card title")
312
+ .option("--head <head>", "OA card head title", "")
313
+ .option("--sub-title <sub>", "OA card sub title", "")
314
+ .option("--staff-id <id>", "Staff ID", "")
315
+ .option("--field <json...>", "Card field as JSON, space-separated, e.g. --field '{\"key\":\"k\",\"value\":\"v\"}'")
316
+ .option("--link <url>", "Card click link URL", "")
317
+ .option("--pc-link <url>", "PC link URL", "")
318
+ .option("--pad-link <url>", "Pad link URL", "")
319
+ .option("--card-action <json>", "Card action as JSON dict")
320
+ .option("-g, --group", "Send as group message", false)
321
+ .option("--user-token <token>", "User token for private channel", "")
322
+ .option("--sender-id <senderId>", "Sender staff ID for group message", "")
323
+ .action(async (chatId, title, opts) => {
324
+ const client = (0, utils_1.getClient)();
325
+ const parsedFields = opts.field ? opts.field.map((f) => (0, utils_1.parseJsonOption)(f)) : undefined;
326
+ const parsedAction = opts.cardAction ? (0, utils_1.parseJsonOption)(opts.cardAction) : undefined;
327
+ const result = await client.sendOacard(chatId, title, {
328
+ head: opts.head || undefined,
329
+ sub_title: opts.subTitle || undefined,
330
+ staff_id: opts.staffId || undefined,
331
+ fields: parsedFields,
332
+ link: opts.link || undefined,
333
+ pc_link: opts.pcLink || undefined,
334
+ pad_link: opts.padLink || undefined,
335
+ card_action: parsedAction,
336
+ is_group: opts.group,
337
+ user_token: opts.userToken || undefined,
338
+ sender_id: opts.senderId || undefined,
339
+ });
340
+ (0, utils_1.checkError)(result);
341
+ (0, utils_1.outputResult)(result);
342
+ });
343
+ cmd
344
+ .command("send-account-message")
345
+ .description("Send a public account message")
346
+ .argument("<msgType>", "Message type")
347
+ .argument("<msgData>", "Message data as JSON")
348
+ .option("--chat-id <ids...>", "Chat IDs, space-separated")
349
+ .option("--dept <ids...>", "Department IDs, space-separated")
350
+ .option("--account-id <id>", "Account ID", "")
351
+ .option("--entry-id <entryId>", "App entry selector", "")
352
+ .option("--attach <attach>", "Attach info", "")
353
+ .option("--user-token <token>", "User token", "")
354
+ .action(async (msgType, msgData, opts) => {
355
+ const client = (0, utils_1.getClient)();
356
+ const parsedData = (0, utils_1.parseJsonOption)(msgData);
357
+ const result = await client.sendAccountMessage(msgType, parsedData, opts.chatId || undefined, opts.dept || undefined, {
358
+ account_id: opts.accountId || undefined,
359
+ entry_id: opts.entryId || undefined,
360
+ attach: opts.attach || undefined,
236
361
  user_token: opts.userToken || undefined,
237
362
  });
238
363
  (0, utils_1.checkError)(result);
239
364
  (0, utils_1.outputResult)(result);
240
365
  });
366
+ cmd
367
+ .command("send-user-message")
368
+ .description("Send a user-to-user private message")
369
+ .argument("<receiverId>", "Receiver user ID")
370
+ .argument("<msgType>", "Message type")
371
+ .argument("<msgData>", "Message data as JSON")
372
+ .option("--user-token <token>", "User token", "")
373
+ .option("--common <json>", "Common data as JSON dict")
374
+ .option("--uuid <uuid>", "Deduplication UUID", "")
375
+ .action(async (receiverId, msgType, msgData, opts) => {
376
+ const client = (0, utils_1.getClient)();
377
+ const parsedData = (0, utils_1.parseJsonOption)(msgData);
378
+ const parsedCommon = opts.common ? (0, utils_1.parseJsonOption)(opts.common) : undefined;
379
+ const result = await client.sendUserMessage(receiverId, msgType, parsedData, {
380
+ user_token: opts.userToken || undefined,
381
+ common: parsedCommon,
382
+ uuid: opts.uuid || undefined,
383
+ });
384
+ (0, utils_1.checkError)(result);
385
+ (0, utils_1.outputResult)(result);
386
+ });
241
387
  cmd
242
388
  .command("send-reminder")
243
389
  .description("Send a reminder for a message")
244
- .requiredOption("--msg-id <msgId>", "Message ID")
245
- .requiredOption("--reminder-types <types>", "Comma-separated reminder types (0=none,1=popup,2=sms,3=phone)")
246
- .requiredOption("--user-ids <ids>", "Comma-separated user IDs to remind")
247
- .action(async (opts) => {
390
+ .argument("<msgId>", "Message ID to remind about")
391
+ .option("-t, --type <types...>", "Reminder types, space-separated: 1=popup, 2=SMS, 3=phone call")
392
+ .option("-u, --user <ids...>", "User IDs to remind, space-separated (staff openIds)")
393
+ .action(async (msgId, opts) => {
248
394
  const client = (0, utils_1.getClient)();
249
- const reminderTypes = (0, utils_1.commaList)(opts.reminderTypes).map(Number);
250
- const userIdList = (0, utils_1.commaList)(opts.userIds);
251
- const result = await client.sendReminderMsg(opts.msgId, reminderTypes, userIdList);
395
+ const reminderTypes = opts.type ? opts.type.map(Number) : [];
396
+ const userIdList = opts.user || [];
397
+ const result = await client.sendReminderMsg(msgId, reminderTypes, userIdList);
252
398
  (0, utils_1.checkError)(result);
253
399
  (0, utils_1.outputResult)(result);
254
400
  });
@@ -1,18 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.registerOauthCommands = registerOauthCommands;
4
+ const lansenger_sdk_ts_1 = require("lansenger-sdk-ts");
4
5
  const utils_1 = require("../utils");
5
6
  function registerOauthCommands(program) {
6
7
  const cmd = program.command("oauth").description("OAuth2 user authorization operations");
7
8
  cmd
8
9
  .command("authorize-url")
9
10
  .description("Build an OAuth2 authorize URL")
10
- .requiredOption("--redirect-uri <uri>", "Redirect URI")
11
- .option("--scope <scope>", "OAuth2 scope")
12
- .option("--state <state>", "State parameter for CSRF protection")
13
- .action(async (opts) => {
11
+ .argument("<redirectUri>", "Redirect URI after auth")
12
+ .option("-s, --scope <scope>", "OAuth2 scope", "basic_userinfor")
13
+ .option("--state <state>", "State parameter for CSRF protection", "")
14
+ .action(async (redirectUri, opts) => {
14
15
  const client = (0, utils_1.getClient)();
15
- const url = client.buildAuthorizeUrl(opts.redirectUri, {
16
+ const url = client.buildAuthorizeUrl(redirectUri, {
16
17
  scope: opts.scope || undefined,
17
18
  state: opts.state || undefined,
18
19
  });
@@ -21,11 +22,11 @@ function registerOauthCommands(program) {
21
22
  cmd
22
23
  .command("exchange-code")
23
24
  .description("Exchange an authorization code for a user token")
24
- .requiredOption("--code <code>", "Authorization code")
25
- .option("--redirect-uri <uri>", "Redirect URI (must match authorize call)")
26
- .action(async (opts) => {
25
+ .argument("<code>", "Authorization code from callback")
26
+ .option("--redirect-uri <uri>", "Redirect URI used in authorize", "")
27
+ .action(async (code, opts) => {
27
28
  const client = (0, utils_1.getClient)();
28
- const result = await client.exchangeCode(opts.code, {
29
+ const result = await client.exchangeCode(code, {
29
30
  redirect_uri: opts.redirectUri || undefined,
30
31
  });
31
32
  (0, utils_1.checkError)(result);
@@ -38,10 +39,13 @@ function registerOauthCommands(program) {
38
39
  cmd
39
40
  .command("refresh-token")
40
41
  .description("Refresh a user token")
41
- .requiredOption("--refresh-token <token>", "Refresh token")
42
- .action(async (opts) => {
42
+ .argument("<refreshToken>", "Refresh token")
43
+ .option("-s, --scope <scope>", "Scope", "")
44
+ .action(async (refreshToken, opts) => {
43
45
  const client = (0, utils_1.getClient)();
44
- const result = await client.refreshUserToken(opts.refreshToken);
46
+ const result = await client.refreshUserToken(refreshToken, {
47
+ scope: opts.scope || undefined,
48
+ });
45
49
  (0, utils_1.checkError)(result);
46
50
  if (result.success && result.user_token) {
47
51
  const store = (0, utils_1.getStore)();
@@ -52,11 +56,28 @@ function registerOauthCommands(program) {
52
56
  cmd
53
57
  .command("user-info")
54
58
  .description("Fetch user info using a user token")
55
- .requiredOption("--user-token <token>", "User token")
56
- .action(async (opts) => {
59
+ .argument("<userToken>", "User token")
60
+ .action(async (userToken) => {
57
61
  const client = (0, utils_1.getClient)();
58
- const result = await client.fetchUserInfoByToken(opts.userToken);
62
+ const result = await client.fetchUserInfoByToken(userToken);
59
63
  (0, utils_1.checkError)(result);
60
64
  (0, utils_1.outputResult)(result);
61
65
  });
66
+ cmd
67
+ .command("parse-callback")
68
+ .description("Parse the query string from an OAuth2 callback URL")
69
+ .argument("<queryString>", "Query string from callback URL")
70
+ .action(async (queryString) => {
71
+ const params = lansenger_sdk_ts_1.LansengerClient.parseAuthorizeCallback(queryString);
72
+ (0, utils_1.outputResult)(params);
73
+ });
74
+ cmd
75
+ .command("validate-state")
76
+ .description("Validate the state parameter from an OAuth2 callback")
77
+ .argument("<callbackState>", "State from callback")
78
+ .argument("<expectedState>", "Expected state you set")
79
+ .action(async (callbackState, expectedState) => {
80
+ const valid = lansenger_sdk_ts_1.LansengerClient.validateCallbackState(callbackState, expectedState);
81
+ (0, utils_1.outputResult)({ valid });
82
+ });
62
83
  }