larkmate 0.0.0-stage → 0.1.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/INSTALL.md +52 -0
- package/README.md +121 -2
- package/bin/larkmate.js +219 -0
- package/package.json +36 -4
- package/proto/lark.proto +547 -0
- package/skills/larkmate/SKILL.md +18 -0
- package/skills/larkmate/references/chats.md +30 -0
- package/skills/larkmate/references/minutes.md +13 -0
- package/skills/larkmate/references/writes.md +23 -0
- package/src/client.js +445 -0
- package/src/credentials.js +23 -0
- package/src/errors.js +22 -0
- package/src/gateway.js +184 -0
- package/src/minutes.js +92 -0
- package/src/session-controls.js +266 -0
- package/src/upload.js +61 -0
- package/third_party/NOTICE.md +6 -0
- package/third_party/feishu-user-plugin-LICENSE +21 -0
package/INSTALL.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# LarkMate 快速安装
|
|
2
|
+
|
|
3
|
+
LarkMate 使用当前用户的飞书网页 Cookie,要求 Node.js 版本为 20 或更高。运行时无需安装 Lark CLI,也无需启动 Agent 服务。
|
|
4
|
+
|
|
5
|
+
## 1. 安装命令
|
|
6
|
+
|
|
7
|
+
从公共 npm 安装后检查命令:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
node --version
|
|
11
|
+
npm install -g larkmate --registry=https://registry.npmjs.org/
|
|
12
|
+
larkmate --help
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
也可以在源码目录执行 `npm ci`,通过 `node bin/larkmate.js --help` 使用 CLI;开发时执行 `npm link` 可将全局命令链接到该源码目录。
|
|
16
|
+
|
|
17
|
+
## 2. 配置登录态
|
|
18
|
+
|
|
19
|
+
登录飞书网页版后,在浏览器开发者工具中查找当前登录会话的飞书网页请求,并复制完整的 `Cookie` 请求头。Cookie 可以代表你的账号操作,请仅在本机保存,不要发给其他人、粘贴到聊天或写进终端命令。
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
umask 077
|
|
23
|
+
mkdir -p ~/.larkmate
|
|
24
|
+
chmod 700 ~/.larkmate
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
用本机编辑器新建或更新 `~/.larkmate/credentials.json`,内容为如下 JSON,将占位文字替换为 Cookie 请求头的值:
|
|
28
|
+
|
|
29
|
+
```json
|
|
30
|
+
{"cookie": "在此填写完整 Cookie 请求头的值"}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
保存后设置文件权限并检查登录:
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
chmod 600 ~/.larkmate/credentials.json
|
|
37
|
+
larkmate status
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
如果已有可用的凭据文件,直接执行 `larkmate status`,不必覆盖它。Cookie 失效时更新文件后重试。也可以通过 `LARKMATE_HOME` 选择配置目录、`LARKMATE_COOKIE` 提供 Cookie,或使用全局选项 `--credentials-file` 指定同格式文件;读取优先级依次为:指定文件、环境变量、配置目录。
|
|
41
|
+
|
|
42
|
+
## 3. 安装 Agent Skill
|
|
43
|
+
|
|
44
|
+
使用 [skills](https://github.com/vercel-labs/skills) 从项目仓库安装 Skill,按提示选择 Agent:
|
|
45
|
+
|
|
46
|
+
```sh
|
|
47
|
+
npx --registry=https://registry.npmjs.org/ skills add NWYLZW/larkmate --skill larkmate -g
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
`-g` 表示为当前用户全局安装;去掉 `-g` 可只安装到当前项目。npm 包中也包含 `skills/larkmate`,支持从已安装的包复制 Skill。新会话中可以使用 `$larkmate`,也可由 Agent 根据任务自动选择。
|
|
51
|
+
|
|
52
|
+
更多命令和能力边界见 [README](README.md);Agent 的使用指引见 [SKILL.md](skills/larkmate/SKILL.md)。
|
package/README.md
CHANGED
|
@@ -1,3 +1,122 @@
|
|
|
1
|
-
#
|
|
1
|
+
# LarkMate
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
LarkMate 是一个独立的飞书用户身份命令行工具,可以查询会话、读取消息、发送文本和文件,以及管理群组。它使用已登录用户的 Cookie,通过飞书网页客户端接口工作,不需要启动 Agent 服务。
|
|
4
|
+
|
|
5
|
+
## 安装与登录
|
|
6
|
+
|
|
7
|
+
需要 Node.js 20 或更新版本。安装 CLI 和 Agent Skill:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install -g larkmate --registry=https://registry.npmjs.org/
|
|
11
|
+
npx --registry=https://registry.npmjs.org/ skills add NWYLZW/larkmate --skill larkmate -g
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
完整步骤及源码安装方式见 [快速安装](INSTALL.md),Agent 使用指引见 [LarkMate Skill](skills/larkmate/SKILL.md)。
|
|
15
|
+
|
|
16
|
+
默认从 `~/.larkmate/credentials.json` 读取登录信息,格式为 `{ "cookie": "..." }`。将目录和文件分别设为仅当前用户可访问(权限 `700` 和 `600`)。也可以通过 `LARKMATE_HOME` 指定配置目录,或通过 `LARKMATE_COOKIE` 提供 Cookie;`--credentials-file` 可指定其他相同格式的文件。读取顺序为指定文件、环境变量、配置目录。不要把真实 Cookie 写进命令参数、聊天记录或代码仓库。Cookie 过期后需更新,再用 `larkmate status` 检查。
|
|
17
|
+
|
|
18
|
+
## 查询会话与消息
|
|
19
|
+
|
|
20
|
+
命令输出 JSON。会话使用飞书网页客户端的数字 ID,与开放平台的 `open_id` 和 `chat_id` 不同。
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
larkmate chats --limit 50
|
|
24
|
+
larkmate chats --type group --cursor "$NEXT_CURSOR"
|
|
25
|
+
larkmate chats --state unread
|
|
26
|
+
larkmate chats --scope done --state read
|
|
27
|
+
larkmate chats --parent "$BOX_ID"
|
|
28
|
+
larkmate search --query '机器人名称'
|
|
29
|
+
larkmate chat-open --id "$MEMBER_ID"
|
|
30
|
+
larkmate chat-info --chat "$CHAT_ID"
|
|
31
|
+
larkmate history --chat "$CHAT_ID" --limit 50 --pages 3
|
|
32
|
+
larkmate history --chat "$CHAT_ID" --pages 3 --query '关键词' --sender "$MEMBER_ID"
|
|
33
|
+
larkmate history --chat "$CHAT_ID" --after 1700000000 --before 1800000000
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
`chats` 默认只读收件箱,`--scope done` 可读已完成分组,每次最多取 100 张卡片,`nextCursor` 用于继续翻页。返回的 `boxes` 是折叠会话盒子,使用 `--parent` 单独读取;`--type` 仅筛选当前页,其他类型的卡片不会计入结果。`--state read|unread` 也仅筛选当前页;无法判断状态的会话不列入结果,并计入 `unknownReadState`。它不是所有历史会话的完整清单。`chat-open` 会打开或创建私聊,不是只读操作。
|
|
37
|
+
|
|
38
|
+
`history` 默认从最新消息位置向前读取,每页最多 100 个位置,`--pages` 最多扫描 100 页。结果按位置从旧到新排列;`nextStart` 和 `nextLimit` 可用于续读更早的位置。位置可能不存在、已删除或不可见,`omittedPositions` 表示未返回的位置数,不能当作消息数量。关键词、发送者及 Unix 秒级时间筛选只作用于本次扫描的范围,不代表全量搜索;按时间筛选时,`missingTimestamps` 统计因缺少时间而无法判断的消息数。部分会话没有返回最新位置时,需通过 `--start` 指定位置。
|
|
39
|
+
|
|
40
|
+
文本和富文本会返回可解析文本,文件和图片尽可能返回资源元数据;卡片等未支持解析的类型保留类型和消息 ID,正文可能为空。
|
|
41
|
+
|
|
42
|
+
## 会话管理
|
|
43
|
+
|
|
44
|
+
`pinned` 和 `marked` 分别查询置顶会话和旗帜标记的会话;`chat-state` 读取单个会话的置顶、标记、免打扰、未读、已完成及收纳状态。
|
|
45
|
+
|
|
46
|
+
```sh
|
|
47
|
+
larkmate pinned
|
|
48
|
+
larkmate marked
|
|
49
|
+
larkmate chat-state --chat "$CHAT_ID"
|
|
50
|
+
larkmate pin --chat "$CHAT_ID"
|
|
51
|
+
larkmate unpin --chat "$CHAT_ID"
|
|
52
|
+
larkmate mark --chat "$CHAT_ID"
|
|
53
|
+
larkmate unmark --chat "$CHAT_ID"
|
|
54
|
+
larkmate unread --chat "$CHAT_ID"
|
|
55
|
+
larkmate read --chat "$CHAT_ID"
|
|
56
|
+
larkmate mute --chat "$CHAT_ID"
|
|
57
|
+
larkmate unmute --chat "$CHAT_ID"
|
|
58
|
+
larkmate done --chat "$CHAT_ID"
|
|
59
|
+
larkmate inbox --chat "$CHAT_ID"
|
|
60
|
+
larkmate box --chat "$CHAT_ID"
|
|
61
|
+
larkmate unbox --chat "$CHAT_ID"
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
`mark` 是会话右键菜单中的旗帜“标记”。`read` 会将阅读位置推进到调用时的最新可见消息,并清除手动未读标记;`unread` 可能把已完成会话重新放回收件箱。`done` / `inbox` 管理已完成状态,`box` / `unbox` 管理会话收纳。状态更改后会读回核验;`submitted_unconfirmed` 表示已提交但未能确认,应先查状态再决定是否重试。
|
|
65
|
+
|
|
66
|
+
## 会话标签
|
|
67
|
+
|
|
68
|
+
```sh
|
|
69
|
+
larkmate labels
|
|
70
|
+
larkmate label-chats --label "$LABEL_ID"
|
|
71
|
+
larkmate label-create --name '项目协作'
|
|
72
|
+
larkmate label-rename --label "$LABEL_ID" --name '项目讨论'
|
|
73
|
+
larkmate label-add --label "$LABEL_ID" --chat "$CHAT_ID"
|
|
74
|
+
larkmate label-remove --label "$LABEL_ID" --chat "$CHAT_ID"
|
|
75
|
+
larkmate label-delete --label "$LABEL_ID"
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
标签 ID 取自 `labels` 或 `label-create`。会话添加和移除目前只支持手动管理的标签;自动规则标签不支持修改成员。删除标签会删除整个个人标签,请使用准确的标签 ID。
|
|
79
|
+
|
|
80
|
+
## 录制妙记与文字记录
|
|
81
|
+
|
|
82
|
+
使用 LarkMate 的 Cookie 查询当前用户可访问的录制妙记,并导出完整的文字记录。妙记列表按飞书返回的分页进行展示,导出时可直接传入妙记链接或列表中的 `object_token`。
|
|
83
|
+
|
|
84
|
+
```sh
|
|
85
|
+
larkmate minutes-list --limit 20
|
|
86
|
+
larkmate minutes-list --cursor "$CURSOR"
|
|
87
|
+
larkmate minutes-access-info --minute "$MINUTES_URL"
|
|
88
|
+
larkmate minutes-export --minute "$MINUTES_URL" --output transcript.txt
|
|
89
|
+
larkmate minutes-export --minute "$MINUTES_URL" --format markdown --no-speakers --no-timestamps --output transcript.md
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
导出内容默认包含说话人与时间戳,可通过 `--no-speakers` 和 `--no-timestamps` 分别关闭。支持导出为本地 TXT 或 Markdown 文件;若未指定 `--output`,文本内容将输出至 JSON 结果的 `content` 字段中。为防止意外覆盖现有文件,指定的输出路径必须尚不存在。当字幕超过 10000 段或飞书返回的数据不完整时,程序将直接报错并终止,不会写入残缺记录。
|
|
93
|
+
|
|
94
|
+
`minutes-access-info` 仅用于查询妙记所有者及是否允许申请权限,不会实际发起申请。当前版本尚不支持创建飞书文档、申请访问权限,或查询没有录制妙记的历史会议。
|
|
95
|
+
|
|
96
|
+
## 发送消息和文件
|
|
97
|
+
|
|
98
|
+
```sh
|
|
99
|
+
larkmate send --chat "$CHAT_ID" --text '你好'
|
|
100
|
+
larkmate send --chat "$CHAT_ID" --text '@机器人名称 你好' --mention "$MEMBER_ID:机器人名称"
|
|
101
|
+
larkmate send-file --chat "$CHAT_ID" --file ./report.pdf
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
文件须为非空普通文件,大小不超过 100 MiB;上传按块校验,成功后发送一条文件消息。`accepted` 表示服务器返回了消息 ID,`submitted_unconfirmed` 表示请求已提交但没有可靠的接收确认;都不代表对方已经阅读。遇到不确定结果时,先查看会话历史,避免重复发送。
|
|
105
|
+
|
|
106
|
+
## 群组与机器人
|
|
107
|
+
|
|
108
|
+
```sh
|
|
109
|
+
larkmate group-create --name '群名称' --description '群介绍' --member "$MEMBER_ID"
|
|
110
|
+
larkmate group-invite --chat "$CHAT_ID" --member "$MEMBER_ID"
|
|
111
|
+
larkmate group-members --chat "$CHAT_ID"
|
|
112
|
+
larkmate group-update --chat "$CHAT_ID" --name '新群名' --description '新介绍'
|
|
113
|
+
larkmate group-dissolve --chat "$CHAT_ID"
|
|
114
|
+
larkmate group-bot-info --chat "$CHAT_ID" --bot "$BOT_ID"
|
|
115
|
+
larkmate group-bot-protection --chat "$CHAT_ID" --bot "$BOT_ID" --allow-member-removal
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
`--member` 可重复传入。CLI 会先识别普通用户与机器人,无法确认类型时停止执行。创建或邀请机器人时,默认开启「仅群主和添加者可移除」;指定 `--allow-member-removal` 可关闭此限制。`group-update --description ''` 可清空群介绍。实际操作取决于当前用户和群的权限。
|
|
119
|
+
|
|
120
|
+
`verified` 只表示机器人的移除限制已读回,不表示消息已送达。`EFFECT_UNKNOWN` 表示写入结果未知;`GROUP_CREATED_PARTIAL` 和 `INVITE_PARTIAL` 表示部分步骤可能已生效。此时先检查实际状态,再决定是否重试。群成员分页支持 `--cursor`、`--offset` 和 `--limit`。
|
|
121
|
+
|
|
122
|
+
网页客户端接口可能变化,也可能受企业策略影响。创建、邀请、群资料修改、机器人限制和解散曾在临时群验证;普通用户邀请只经过模拟测试。协议来源和第三方许可见 [third_party/NOTICE.md](third_party/NOTICE.md)。
|
package/bin/larkmate.js
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command, CommanderError } from 'commander';
|
|
3
|
+
import { loadCookie } from '../src/credentials.js';
|
|
4
|
+
import { Gateway } from '../src/gateway.js';
|
|
5
|
+
import { LarkMateClient } from '../src/client.js';
|
|
6
|
+
import { SessionControls } from '../src/session-controls.js';
|
|
7
|
+
import { Minutes, formatTranscript } from '../src/minutes.js';
|
|
8
|
+
import { writeFile } from 'node:fs/promises';
|
|
9
|
+
import { FeishuError } from '../src/errors.js';
|
|
10
|
+
|
|
11
|
+
const program = new Command();
|
|
12
|
+
program.name('larkmate').description('Operate Feishu as the logged-in user.').version('0.1.0');
|
|
13
|
+
program.option('--credentials-file <path>', 'read LarkMate credentials.json');
|
|
14
|
+
program.exitOverride();
|
|
15
|
+
|
|
16
|
+
const collect = (value, previous) => [...previous, value];
|
|
17
|
+
const output = value => process.stdout.write(`${JSON.stringify({ ok: true, ...value }, null, 2)}\n`);
|
|
18
|
+
|
|
19
|
+
async function controls() {
|
|
20
|
+
return new SessionControls(new Gateway({ cookie: await loadCookie({ file: program.opts().credentialsFile }) }));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function client() {
|
|
24
|
+
const cookie = await loadCookie({ file: program.opts().credentialsFile });
|
|
25
|
+
return new LarkMateClient(new Gateway({ cookie }));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async function minutes() {
|
|
29
|
+
return new Minutes(new Gateway({ cookie: await loadCookie({ file: program.opts().credentialsFile }) }));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
program.command('status').description('Check the current user login.')
|
|
33
|
+
.action(async () => output(await (await client()).status()));
|
|
34
|
+
|
|
35
|
+
program.command('search').description('Search users, bots and groups.')
|
|
36
|
+
.requiredOption('--query <text>', 'search text')
|
|
37
|
+
.action(async options => output(await (await client()).search(options.query)));
|
|
38
|
+
|
|
39
|
+
program.command('chats').description('List a page of inbox chats without opening them.')
|
|
40
|
+
.option('--limit <number>', 'inbox cards per page, 1 to 100', '50')
|
|
41
|
+
.option('--cursor <number>', 'continue with the returned cursor')
|
|
42
|
+
.option('--parent <id>', 'list a box returned by a previous page')
|
|
43
|
+
.option('--type <type>', 'filter this page: p2p, group or topic_group')
|
|
44
|
+
.option('--scope <scope>', 'inbox or done', 'inbox')
|
|
45
|
+
.option('--state <state>', 'filter this page: read or unread')
|
|
46
|
+
.action(async options => {
|
|
47
|
+
if (options.type && !['p2p', 'group', 'topic_group'].includes(options.type)) throw new FeishuError('INVALID_ARGUMENT', 'Invalid chat type.');
|
|
48
|
+
if (options.state && !['read', 'unread'].includes(options.state)) throw new FeishuError('INVALID_ARGUMENT', 'Invalid read state.');
|
|
49
|
+
const page = await (await client()).chats({ limit: Number(options.limit), cursor: options.cursor, parent: options.parent, scope: options.scope });
|
|
50
|
+
if (options.type) page.items = page.items.filter(item => item.type === options.type);
|
|
51
|
+
if (options.state) { page.unknownReadState = page.items.filter(item => item.unread == null).length; page.items = page.items.filter(item => item.unread === (options.state === 'unread')); }
|
|
52
|
+
output(page);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
program.command('pinned').description('List pinned conversations.').action(async () => output(await (await controls()).pinned()));
|
|
56
|
+
program.command('marked').description('List conversations marked with a flag.').action(async () => output(await (await controls()).marked()));
|
|
57
|
+
program.command('labels').description('List personal conversation labels.').action(async () => output(await (await controls()).labels()));
|
|
58
|
+
program.command('label-chats').description('List conversations in a label.')
|
|
59
|
+
.requiredOption('--label <id>', 'numeric label ID').action(async o => output(await (await controls()).labelChats(o.label)));
|
|
60
|
+
program.command('label-create').description('Create a personal conversation label.')
|
|
61
|
+
.requiredOption('--name <name>', 'label name').action(async o => output(await (await controls()).createLabel(o.name)));
|
|
62
|
+
program.command('label-rename').description('Rename a conversation label.')
|
|
63
|
+
.requiredOption('--label <id>', 'numeric label ID').requiredOption('--name <name>', 'new name')
|
|
64
|
+
.action(async o => output(await (await controls()).renameLabel(o.label, o.name)));
|
|
65
|
+
program.command('label-delete').description('Delete a personal conversation label.')
|
|
66
|
+
.requiredOption('--label <id>', 'numeric label ID').action(async o => output(await (await controls()).deleteLabel(o.label)));
|
|
67
|
+
for (const [command, enabled] of [['label-add', true], ['label-remove', false]]) {
|
|
68
|
+
program.command(command).description(enabled ? 'Add a chat to a manual label.' : 'Remove a chat from a manual label.')
|
|
69
|
+
.requiredOption('--label <id>', 'numeric label ID').requiredOption('--chat <id>', 'numeric chat ID')
|
|
70
|
+
.action(async o => output(await (await controls()).labelChat(o.label, o.chat, enabled)));
|
|
71
|
+
}
|
|
72
|
+
program.command('chat-state').description('Read pin, flag, notification and read state for a conversation.')
|
|
73
|
+
.requiredOption('--chat <id>', 'numeric chat ID').action(async o => output(await (await controls()).state(o.chat)));
|
|
74
|
+
for (const [command, method, enabled, description] of [
|
|
75
|
+
['pin', 'pin', true, 'Pin a conversation.'], ['unpin', 'pin', false, 'Unpin a conversation.'],
|
|
76
|
+
['mark', 'mark', true, 'Flag a conversation.'], ['unmark', 'mark', false, 'Remove a conversation flag.'],
|
|
77
|
+
['mute', 'setMute', true, 'Mute a conversation.'], ['unmute', 'setMute', false, 'Unmute a conversation.'],
|
|
78
|
+
['done', 'setDone', true, 'Move a conversation to done.'], ['inbox', 'setDone', false, 'Return a conversation to inbox.'],
|
|
79
|
+
['box', 'setBox', true, 'Move a conversation into the box.'], ['unbox', 'setBox', false, 'Remove a conversation from the box.'],
|
|
80
|
+
]) {
|
|
81
|
+
program.command(command).description(description).requiredOption('--chat <id>', 'numeric chat ID')
|
|
82
|
+
.action(async o => output(await (await controls())[method](o.chat, enabled)));
|
|
83
|
+
}
|
|
84
|
+
program.command('unread').description('Mark a conversation manually unread.')
|
|
85
|
+
.requiredOption('--chat <id>', 'numeric chat ID').action(async o => output(await (await controls()).setUnread(o.chat)));
|
|
86
|
+
program.command('read').description('Mark a conversation read through its latest visible position.')
|
|
87
|
+
.requiredOption('--chat <id>', 'numeric chat ID').action(async o => output(await (await controls()).setRead(o.chat)));
|
|
88
|
+
|
|
89
|
+
program.command('minutes-list').description('List accessible recording minutes with the LarkMate Cookie.')
|
|
90
|
+
.option('--limit <number>', 'items per page, 1 to 100', '20')
|
|
91
|
+
.option('--cursor <cursor>', 'continue from the previous page')
|
|
92
|
+
.action(async o => output(await (await minutes()).list({ limit: Number(o.limit), cursor: o.cursor })));
|
|
93
|
+
|
|
94
|
+
program.command('minutes-access-info').description('Check who owns a recording and whether an access request is allowed.')
|
|
95
|
+
.requiredOption('--minute <token-or-url>', 'recording minutes token or URL')
|
|
96
|
+
.action(async o => output(await (await minutes()).accessInfo(o.minute)));
|
|
97
|
+
|
|
98
|
+
program.command('minutes-export').description('Export a complete recording transcript.')
|
|
99
|
+
.requiredOption('--minute <token-or-url>', 'recording minutes token or URL')
|
|
100
|
+
.option('--format <format>', 'txt or markdown', 'txt')
|
|
101
|
+
.option('--no-speakers', 'omit speaker names')
|
|
102
|
+
.option('--no-timestamps', 'omit timestamps')
|
|
103
|
+
.option('--output <path>', 'write a new local file; otherwise return text as JSON')
|
|
104
|
+
.action(async o => {
|
|
105
|
+
if (!['txt', 'markdown'].includes(o.format)) throw new FeishuError('INVALID_ARGUMENT', 'Format must be txt or markdown.');
|
|
106
|
+
const result = await (await minutes()).transcript(o.minute);
|
|
107
|
+
const content = formatTranscript(result.entries, o);
|
|
108
|
+
if (o.output) {
|
|
109
|
+
try { await writeFile(o.output, content, { encoding: 'utf8', flag: 'wx', mode: 0o600 }); }
|
|
110
|
+
catch (error) { throw new FeishuError('EXPORT_WRITE_FAILED', error.code === 'EEXIST' ? 'Output file already exists; choose a new path.' : 'Could not write the output file.'); }
|
|
111
|
+
output({ output: o.output, total: result.total, format: o.format });
|
|
112
|
+
} else output({ total: result.total, format: o.format, content });
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
program.command('chat-open').description('Open or find a private chat by numeric user or bot ID.')
|
|
116
|
+
.requiredOption('--id <id>', 'numeric ID from search')
|
|
117
|
+
.action(async options => output(await (await client()).openChat(options.id)));
|
|
118
|
+
|
|
119
|
+
program.command('chat-info').description('Read basic information about a chat.')
|
|
120
|
+
.requiredOption('--chat <id>', 'numeric chat ID')
|
|
121
|
+
.action(async options => output(await (await client()).chatInfo(options.chat)));
|
|
122
|
+
|
|
123
|
+
program.command('history').description('Read a bounded page of chat messages as the user.')
|
|
124
|
+
.requiredOption('--chat <id>', 'numeric chat ID')
|
|
125
|
+
.option('--limit <number>', 'number of positions, 1 to 100', '20')
|
|
126
|
+
.option('--start <number>', 'first position; defaults to the most recent page')
|
|
127
|
+
.option('--pages <number>', 'scan up to this many pages backwards, 1 to 100', '1')
|
|
128
|
+
.option('--query <text>', 'filter text within the scanned positions')
|
|
129
|
+
.option('--sender <id>', 'filter sender ID within the scanned positions')
|
|
130
|
+
.option('--after <seconds>', 'filter from Unix time in seconds, inclusive')
|
|
131
|
+
.option('--before <seconds>', 'filter until Unix time in seconds, inclusive')
|
|
132
|
+
.action(async options => output(await (await client()).historyPages({
|
|
133
|
+
chatId: options.chat, limit: Number(options.limit), pages: Number(options.pages), query: options.query, sender: options.sender,
|
|
134
|
+
...(options.after != null ? { after: Number(options.after) } : {}),
|
|
135
|
+
...(options.before != null ? { before: Number(options.before) } : {}),
|
|
136
|
+
...(options.start != null ? { start: Number(options.start) } : {}),
|
|
137
|
+
})));
|
|
138
|
+
|
|
139
|
+
program.command('send').description('Send text once as the user; delivery remains unconfirmed.')
|
|
140
|
+
.requiredOption('--chat <id>', 'numeric chat ID')
|
|
141
|
+
.requiredOption('--text <text>', 'message text')
|
|
142
|
+
.option('--mention <id:name>', 'mention a numeric user or bot ID; repeatable', collect, [])
|
|
143
|
+
.action(async options => {
|
|
144
|
+
const mentions = options.mention.map(value => {
|
|
145
|
+
const colon = value.indexOf(':');
|
|
146
|
+
if (colon < 1) throw new FeishuError('INVALID_ARGUMENT', 'A mention must use id:name.');
|
|
147
|
+
return { id: value.slice(0, colon), name: value.slice(colon + 1) };
|
|
148
|
+
});
|
|
149
|
+
output(await (await client()).send({ chatId: options.chat, text: options.text, mentions }));
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
program.command('send-file').description('Upload and send a local file as the user.')
|
|
153
|
+
.requiredOption('--chat <id>', 'numeric chat ID')
|
|
154
|
+
.requiredOption('--file <path>', 'local file path')
|
|
155
|
+
.action(async options => output(await (await client()).sendFile({ chatId: options.chat, path: options.file })));
|
|
156
|
+
|
|
157
|
+
program.command('group-create').description('Create a group as the user.')
|
|
158
|
+
.requiredOption('--name <name>', 'group name')
|
|
159
|
+
.option('--description <text>', 'group description')
|
|
160
|
+
.option('--member <id>', 'numeric user or bot ID; repeatable', collect, [])
|
|
161
|
+
.option('--allow-member-removal', 'allow ordinary members to remove invited bots')
|
|
162
|
+
.action(async options => output(await (await client()).createGroup({
|
|
163
|
+
name: options.name, description: options.description, memberIds: options.member,
|
|
164
|
+
protectBots: !options.allowMemberRemoval,
|
|
165
|
+
})));
|
|
166
|
+
|
|
167
|
+
program.command('group-update').description('Change a group name or description.')
|
|
168
|
+
.requiredOption('--chat <id>', 'numeric group ID')
|
|
169
|
+
.option('--name <name>', 'new group name')
|
|
170
|
+
.option('--description <text>', 'new group description; use an empty string to clear it')
|
|
171
|
+
.action(async options => output(await (await client()).updateGroup({
|
|
172
|
+
chatId: options.chat, name: options.name, description: options.description,
|
|
173
|
+
})));
|
|
174
|
+
|
|
175
|
+
program.command('group-dissolve').description('Dissolve a group as its owner.')
|
|
176
|
+
.requiredOption('--chat <id>', 'numeric group ID')
|
|
177
|
+
.action(async options => output(await (await client()).dissolveGroup(options.chat)));
|
|
178
|
+
|
|
179
|
+
program.command('group-invite').description('Invite users or bots once; verify membership separately.')
|
|
180
|
+
.requiredOption('--chat <id>', 'numeric group ID')
|
|
181
|
+
.requiredOption('--member <id>', 'numeric user or bot ID; repeatable', collect, [])
|
|
182
|
+
.option('--allow-member-removal', 'allow ordinary members to remove invited bots')
|
|
183
|
+
.action(async options => output(await (await client()).invite({
|
|
184
|
+
chatId: options.chat, memberIds: options.member, protectBots: !options.allowMemberRemoval,
|
|
185
|
+
})));
|
|
186
|
+
|
|
187
|
+
program.command('group-bot-info').description('Read a bot’s removal protection in a group.')
|
|
188
|
+
.requiredOption('--chat <id>', 'numeric group ID')
|
|
189
|
+
.requiredOption('--bot <id>', 'numeric bot ID')
|
|
190
|
+
.action(async options => output(await (await client()).botProtection({ chatId: options.chat, botId: options.bot })));
|
|
191
|
+
|
|
192
|
+
program.command('group-bot-protection').description('Change a bot’s removal protection in a group.')
|
|
193
|
+
.requiredOption('--chat <id>', 'numeric group ID')
|
|
194
|
+
.requiredOption('--bot <id>', 'numeric bot ID')
|
|
195
|
+
.option('--allow-member-removal', 'allow ordinary members to remove this bot')
|
|
196
|
+
.action(async options => output(await (await client()).setBotProtection({
|
|
197
|
+
chatId: options.chat, botId: options.bot, enabled: !options.allowMemberRemoval,
|
|
198
|
+
})));
|
|
199
|
+
|
|
200
|
+
program.command('group-members').description('Read one page of group members.')
|
|
201
|
+
.requiredOption('--chat <id>', 'numeric group ID')
|
|
202
|
+
.option('--cursor <number>', 'page cursor')
|
|
203
|
+
.option('--offset <value>', 'page offset')
|
|
204
|
+
.option('--limit <number>', 'page size, 1 to 200', '100')
|
|
205
|
+
.action(async options => output(await (await client()).members({
|
|
206
|
+
chatId: options.chat, cursor: options.cursor, offset: options.offset, limit: Number(options.limit),
|
|
207
|
+
})));
|
|
208
|
+
|
|
209
|
+
try {
|
|
210
|
+
await program.parseAsync(process.argv);
|
|
211
|
+
if (!process.argv.slice(2).length) program.help();
|
|
212
|
+
} catch (error) {
|
|
213
|
+
if (error instanceof CommanderError && error.exitCode === 0) process.exit(0);
|
|
214
|
+
const safe = error instanceof FeishuError
|
|
215
|
+
? { code: error.code, message: error.message, ...error.details }
|
|
216
|
+
: { code: 'CLI_ERROR', message: 'The command could not be completed.' };
|
|
217
|
+
process.stderr.write(`${JSON.stringify({ ok: false, error: safe })}\n`);
|
|
218
|
+
process.exitCode = 1;
|
|
219
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "larkmate",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A small, user-identity Feishu CLI with a modular gateway client",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "UNLICENSED",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/NWYLZW/larkmate.git"
|
|
10
|
+
},
|
|
11
|
+
"bugs": "https://github.com/NWYLZW/larkmate/issues",
|
|
12
|
+
"homepage": "https://github.com/NWYLZW/larkmate#readme",
|
|
13
|
+
"files": [
|
|
14
|
+
"bin/",
|
|
15
|
+
"src/",
|
|
16
|
+
"proto/",
|
|
17
|
+
"skills/",
|
|
18
|
+
"third_party/",
|
|
19
|
+
"INSTALL.md"
|
|
20
|
+
],
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"registry": "https://registry.npmjs.org/"
|
|
23
|
+
},
|
|
24
|
+
"bin": {
|
|
25
|
+
"larkmate": "bin/larkmate.js"
|
|
26
|
+
},
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=20"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"test": "node --test",
|
|
32
|
+
"check": "node --check bin/larkmate.js && node --test"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"commander": "^13.1.0",
|
|
36
|
+
"protobufjs": "^8.6.0"
|
|
37
|
+
}
|
|
38
|
+
}
|