send_file_as_user
Send a file to a chat as the authenticated user. Requires prior upload via the Official API to obtain a file key.
Instructions
[User Identity] Send a file as the logged-in user. Requires file_key (upload via Official API first).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| chat_id | Yes | Target chat ID. Numeric preferred; oc_xxx is auto-resolved (v1.3.7 C1.4). | |
| file_key | Yes | File key from upload | |
| file_name | Yes | Display file name | |
| root_id | No | Thread root message ID (optional) |
Implementation Reference
- src/tools/messaging-user.js:283-288 (handler)Core handler for 'send_file_as_user' tool. Gets the user client (cookie-based), resolves the chat ID, and calls c.sendFile() to send the file via the Feishu user-identity protobuf path.
async send_file_as_user(args, ctx) { const c = await ctx.getUserClient(); const chatId = await _resolveCookieChatId(args.chat_id, ctx); const r = await c.sendFile(chatId, args.file_key, args.file_name, { rootId: args.root_id }); return sendResult(r, `File "${args.file_name}" sent to ${args.chat_id}`); }, - src/tools/messaging-user.js:136-148 (schema)Input schema definition for 'send_file_as_user'. Defines required parameters: chat_id, file_key, file_name, and optional root_id for threading.
{ name: 'send_file_as_user', description: '[User Identity] Send a file as the logged-in user. Requires file_key (upload via Official API first).', inputSchema: { type: 'object', properties: { chat_id: { type: 'string', description: 'Target chat ID. Numeric preferred; oc_xxx is auto-resolved (v1.3.7 C1.4).' }, file_key: { type: 'string', description: 'File key from upload' }, file_name: { type: 'string', description: 'Display file name' }, root_id: { type: 'string', description: 'Thread root message ID (optional)' }, }, required: ['chat_id', 'file_key', 'file_name'], }, - src/clients/user.js:280-282 (helper)The sendFile() helper method on the user client. Delegates to _sendMsg with MsgType.FILE, wrapping fileKey and fileName in the protobuf content payload.
async sendFile(chatId, fileKey, fileName, opts = {}) { return this._sendMsg(MsgType.FILE, chatId, { fileKey, fileName }, opts); } - src/clients/user.js:182-191 (helper)Generic _sendMsg() method that builds the protobuf request (cmd=5, PutMessageRequest) and sends it through the cookie-based gateway.
async _sendMsg(type, chatId, content, { rootId, parentId } = {}) { const req = { type, chatId, cid: generateCid(), isNotified: true, version: 1, content }; if (rootId) req.rootId = rootId; if (parentId) req.parentId = parentId; const { packet, ok } = await this._gateway(5, 'PutMessageRequest', req, '5.7.0'); if (!ok) { throw new Error(`_sendMsg: cookie protobuf gateway returned non-2xx for type=${type}. The wire format likely doesn't match what Feishu expects.`); } return { success: true, status: packet.status }; } - src/server.js:48-57 (registration)Registration: the messaging-user module (containing the tool's schema and handler) is loaded in server.js and its schemas/handlers are aggregated into the tool registry.
require('./tools/messaging-user'), require('./tools/okr'), require('./tools/profile'), require('./tools/tasks'), require('./tools/uploads'), require('./tools/wiki'), ]; const TOOLS = TOOL_MODULES.flatMap((m) => m.schemas); const HANDLERS = Object.fromEntries(TOOL_MODULES.flatMap((m) => Object.entries(m.handlers)));