{"record":{"id":"8f2e9d4293d5d13a","repo":"Hmbown/CodeWhale","slug":"lark-sdk-client-does-not-expose-im-message-create-api","errorCode":null,"errorMessage":"Lark SDK client does not expose im message create API","messagePattern":"Lark SDK client does not expose im message create API","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"integrations/feishu-bridge/src/index.mjs","lineNumber":545,"sourceCode":"}\n\nasync function sendText(chatId, text) {\n  // Try reply API first — keeps bot responses inside the same Feishu\n  // thread/topic instead of spawning new standalone topics.\n  // / 优先使用 reply API，确保 bot 回复留在话题群的同一条话题内。\n  const state = await threadStore.getChat(chatId);\n  const replyToMessageId = state?.replyToMessageId || null;\n\n  const replyMessage =\n    replyToMessageId\n      ? client.im?.v1?.message?.reply?.bind(client.im.v1.message) ||\n        client.im?.message?.reply?.bind(client.im.message)\n      : null;\n  const createMessage =\n    client.im?.v1?.message?.create?.bind(client.im.v1.message) ||\n    client.im?.message?.create?.bind(client.im.message);\n  if (!createMessage) {\n    throw new Error(\"Lark SDK client does not expose im message create API\");\n  }\n\n  let canReply = Boolean(replyMessage);\n  for (const chunk of splitMessage(text, config.maxReplyChars)) {\n    const body = {\n      msg_type: \"text\",\n      content: JSON.stringify({ text: chunk })\n    };\n    if (canReply) {\n      try {\n        await replyMessage({\n          path: { message_id: replyToMessageId },\n          data: body\n        });\n        continue;\n      } catch (error) {\n        canReply = false;\n        console.warn(\"Feishu reply API failed; falling back to message create\", error);","sourceCodeStart":527,"sourceCodeEnd":563,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/integrations/feishu-bridge/src/index.mjs#L527-L563","documentation":"sendText in the Feishu bridge guards against Lark SDK shape drift: it probes client.im.v1.message.create / client.im.message.create / reply bindings, and if none of the expected im message-send functions exist on the injected Lark client it throws rather than silently failing to deliver replies.","triggerScenarios":"Constructing the bridge's message sender with a Lark client object lacking the im.v1.message.create (or legacy im.message.create) method — wrong SDK package version, a mock/test double, or a client built for a different API surface (e.g. only websocket events, no REST im namespace).","commonSituations":"Upgrading/downgrading @lark-base-open or lark-oapi to a version that renamed or restructured im.v1.message; passing a bot-only websocket client instead of a full API client; stubbing client.im in tests with a partial object.","solutions":["Pin the Lark SDK version the bridge documents and reinstall node_modules so client.im.v1.message.create exists.","Log the client shape (Object.keys(client.im)) to see what the installed SDK actually exposes and adapt imports to the correct package.","If testing, provide a stub that includes im.v1.message.create (and reply) functions matching the real SDK surface."],"exampleFix":"// before: partial stub in test\nconst client = { im: {} };\n// after: stub the full surface sendText probes\nconst client = { im: { v1: { message: { create: async () => ({ ok: true }) } } } };","handlingStrategy":"type-guard","validationCode":"import assert from 'node:assert';\nassert(typeof client?.im?.v1?.message?.create === 'function',\n  'Lark SDK client lacks im.v1.message.create — check the installed SDK version');","typeGuard":"function hasImCreateApi(client) {\n  return typeof client?.im?.v1?.message?.create === 'function' ||\n    typeof client?.im?.message?.create === 'function';\n}","tryCatchPattern":"try {\n  await sendText(client, config, chatId, text);\n} catch (e) {\n  if (String(e.message).includes('im message create API')) {\n    console.error('Lark SDK version incompatible — pin the documented version.');\n  }\n}","preventionTips":["Pin the Lark SDK to the version the bridge documents in its lockfile.","Smoke-test a real im message create against a test chat during setup.","In tests, stub the full im.v1.message surface, not a partial client."],"tags":["lark","sdk","feishu-bridge","dependency","api-surface"],"backgroundTag":"missing-dependency","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}