@max1874/feishu 0.2.25 → 0.2.26

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@max1874/feishu",
3
- "version": "0.2.25",
3
+ "version": "0.2.26",
4
4
  "type": "module",
5
5
  "description": "OpenClaw Feishu/Lark channel plugin",
6
6
  "license": "MIT",
package/src/channel.ts CHANGED
@@ -55,6 +55,7 @@ export const feishuPlugin: ChannelPlugin<ResolvedFeishuAccount> = {
55
55
  messageToolHints: () => [
56
56
  "- Feishu targeting: omit `target` to reply to the current conversation (auto-inferred). Explicit targets: `user:open_id` or `chat:chat_id`.",
57
57
  "- Feishu supports interactive cards for rich messages.",
58
+ "- Use feishu_chat_messages to read message history. Omit chat_id to read from the current conversation.",
58
59
  ],
59
60
  },
60
61
  groups: {
package/src/docx.ts CHANGED
@@ -1247,5 +1247,113 @@ export function registerFeishuDocTools(api: OpenClawPluginApi) {
1247
1247
  { name: "feishu_app_scopes" },
1248
1248
  );
1249
1249
 
1250
- api.logger.info?.(`feishu_doc: Registered 14 document/wiki tools`);
1250
+ // Tool 15: feishu_chat_messages
1251
+ const ChatMessagesSchema = Type.Object({
1252
+ chat_id: Type.Optional(
1253
+ Type.String({
1254
+ description: "Chat ID (oc_xxx). Omit to use the current conversation.",
1255
+ }),
1256
+ ),
1257
+ start_time: Type.Optional(
1258
+ Type.String({ description: "Start time, Unix timestamp in seconds" }),
1259
+ ),
1260
+ end_time: Type.Optional(
1261
+ Type.String({ description: "End time, Unix timestamp in seconds" }),
1262
+ ),
1263
+ sort_type: Type.Optional(
1264
+ Type.Union([Type.Literal("ByCreateTimeAsc"), Type.Literal("ByCreateTimeDesc")], {
1265
+ description: "Sort order (default: ByCreateTimeDesc)",
1266
+ }),
1267
+ ),
1268
+ page_size: Type.Optional(
1269
+ Type.Number({ description: "Page size, 1-50 (default 20)" }),
1270
+ ),
1271
+ page_token: Type.Optional(
1272
+ Type.String({ description: "Pagination token from previous response" }),
1273
+ ),
1274
+ });
1275
+
1276
+ api.registerTool(
1277
+ {
1278
+ name: "feishu_chat_messages",
1279
+ label: "Feishu Chat Messages",
1280
+ description:
1281
+ "Read message history from a Feishu chat (group or DM). " +
1282
+ "Omit chat_id to read from the current conversation. " +
1283
+ "Returns messages with sender info, content, and timestamps. " +
1284
+ "Requires im:message scope; bot must be a member of the chat.",
1285
+ parameters: ChatMessagesSchema,
1286
+ async execute(_toolCallId, params) {
1287
+ const {
1288
+ chat_id,
1289
+ start_time,
1290
+ end_time,
1291
+ sort_type,
1292
+ page_size,
1293
+ page_token,
1294
+ } = params as {
1295
+ chat_id?: string;
1296
+ start_time?: string;
1297
+ end_time?: string;
1298
+ sort_type?: "ByCreateTimeAsc" | "ByCreateTimeDesc";
1299
+ page_size?: number;
1300
+ page_token?: string;
1301
+ };
1302
+ try {
1303
+ const container_id = chat_id || getConversationContext()?.chatId;
1304
+ if (!container_id) {
1305
+ return json({
1306
+ error:
1307
+ "No chat_id provided and no current conversation context available.",
1308
+ });
1309
+ }
1310
+
1311
+ const client = getClient();
1312
+ const res = await client.im.message.list({
1313
+ params: {
1314
+ container_id_type: "chat",
1315
+ container_id,
1316
+ ...(start_time && { start_time }),
1317
+ ...(end_time && { end_time }),
1318
+ ...(sort_type && { sort_type }),
1319
+ ...(page_size && { page_size }),
1320
+ ...(page_token && { page_token }),
1321
+ },
1322
+ });
1323
+
1324
+ if (res.code !== 0) throw new Error(res.msg);
1325
+
1326
+ const messages = (res.data?.items ?? []).map((m) => {
1327
+ let content: unknown = m.body?.content;
1328
+ if (typeof content === "string") {
1329
+ try {
1330
+ content = JSON.parse(content);
1331
+ } catch {
1332
+ // keep raw string
1333
+ }
1334
+ }
1335
+ return {
1336
+ message_id: m.message_id,
1337
+ msg_type: m.msg_type,
1338
+ sender: m.sender,
1339
+ content,
1340
+ create_time: m.create_time,
1341
+ deleted: m.deleted,
1342
+ };
1343
+ });
1344
+
1345
+ return json({
1346
+ messages,
1347
+ has_more: res.data?.has_more ?? false,
1348
+ page_token: res.data?.page_token,
1349
+ });
1350
+ } catch (err) {
1351
+ return json({ error: err instanceof Error ? err.message : String(err) });
1352
+ }
1353
+ },
1354
+ },
1355
+ { name: "feishu_chat_messages" },
1356
+ );
1357
+
1358
+ api.logger.info?.(`feishu_doc: Registered 15 document/wiki/messaging tools`);
1251
1359
  }