{"id":13672836,"url":"https://github.com/larksuite/oapi-sdk-nodejs","last_synced_at":"2025-04-23T17:28:50.141Z","repository":{"id":37719513,"uuid":"304185765","full_name":"larksuite/oapi-sdk-nodejs","owner":"larksuite","description":"DEPRECATED","archived":false,"fork":false,"pushed_at":"2023-05-20T21:26:10.000Z","size":677,"stargazers_count":82,"open_issues_count":8,"forks_count":9,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-14T08:07:48.090Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/larksuite.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-10-15T02:16:00.000Z","updated_at":"2023-09-20T16:28:15.000Z","dependencies_parsed_at":"2024-01-17T04:18:44.454Z","dependency_job_id":null,"html_url":"https://github.com/larksuite/oapi-sdk-nodejs","commit_stats":{"total_commits":42,"total_committers":4,"mean_commits":10.5,"dds":"0.11904761904761907","last_synced_commit":"75fd98c46680664ba138e4f043125ae93438bdc8"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/larksuite%2Foapi-sdk-nodejs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/larksuite%2Foapi-sdk-nodejs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/larksuite%2Foapi-sdk-nodejs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/larksuite%2Foapi-sdk-nodejs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/larksuite","download_url":"https://codeload.github.com/larksuite/oapi-sdk-nodejs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250479907,"owners_count":21437455,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T09:01:50.974Z","updated_at":"2025-04-23T17:28:50.116Z","avatar_url":"https://github.com/larksuite.png","language":"TypeScript","readme":"[**飞书，点这里**](README.zh.md) | Larksuite(Overseas)\n\n- 如果使用的是飞书，请看 [**飞书，点这里**](README.zh.md) ，飞书与Larksuite使用的域名不一样，引用的文档地址也是不同的。(If you are using FeiShu, please see [**飞书，点这里**](README.zh.md) , Feishu and larksuite use different domain names and reference different document addresses.)\n\n# [Deprecated]LarkSuite open api SDK\n\n**Please use the new version of node-sdk: https://github.com/larksuite/node-sdk**\n## Overview\n\n---\n\n- Larksuite open platform facilitates the integration of enterprise applications and larksuite, making collaboration and\n  management more efficient.\n\n- Larksuite development interface SDK, convenient call server API and subscribe server events, such as: Message \u0026 group,\n  address book, calendar, docs and others can visit [larksuite open platform document](https://open.larksuite.cn/document) ,Take a look at [REFERENCE].\n\n## Problem feedback\n\nIf you encounter any problems during usage, please let us know by submitting  [Github Issues](https://github.com/larksuite/oapi-sdk-nodejs/issues). We will deal with these Issues and get back to you as soon as possible.\n\n\n## installation\n\n```shell script\n  npm i @larksuiteoapi/allcore@1.0.14\n```\n\n## Explanation of terms\n- Larksuite: the overseas name of lark, which mainly provides services for overseas enterprises and has an independent [domain name address](https://www.larksuite.com/) .\n- Development documents: reference to the open interface of the open platform **developers must see, and can use search to query documents efficiently** . [more information](https://open.feishu.cn/document/) .\n- Developer background: the management background for developers to develop applications, [more introduction](https://open.larksuite.cn/app/) .\n- Cutome APP: the application can only be installed and used in the enterprise，[more introduction](https://open.larksuite.com/document/ukzMxEjL5MTMx4SOzETM/uEjNwYjLxYDM24SM2AjN) .\n- Marketplace App：The app will be displayed in [App Directory](https://app.larksuite.com/) Display, each enterprise can choose to install.\n\n![App type](doc/app_type.en.png)\n\n\n## Quick use\n\n---\n\n### Call API\n\n#### Example of using `Custom App` to access [send text message](https://open.larksuite.com/document/uMzMyEjLzMjMx4yMzITM/ugDN0EjL4QDNx4CO0QTM) API\n- Since the SDK has encapsulated the app_access_token、tenant_access_token So when calling the business API, you don't need to get the app_access_token、tenant_access_token. If the business interface needs to use user_access_token, which needs to be set（lark.api.setUserAccessToken(\"UserAccessToken\")), Please refer to README.md -\u003e How to build a request(Request)\n- For more use examples, please see: [packages/sample/src/api](packages/sample/src/api)\n\n```javascript\n// import * as lark from \"@larksuiteoapi/allcore\";  // typescript\nconst lark = require(\"@larksuiteoapi/allcore\");     // javascript\n\n// Configuration of custom app, parameter description:\n// appID、appSecret: \"Developer Console\" -\u003e \"Credentials\"（App ID、App Secret）\n// verificationToken、encryptKey：\"Developer Console\" -\u003e \"Event Subscriptions\"（Verification Token、Encrypt Key）\n// helpDeskID、helpDeskToken, Help Desk token：https://open.feishu.cn/document/ukTMukTMukTM/ugDOyYjL4gjM24CO4IjN\nconst appSettings = lark.newInternalAppSettings({\n    appID: \"App ID\",\n    appSecret: \"App Secret\",\n    encryptKey: \"Encrypt Key\", // Not required. Required when subscribing to events\n    verificationToken: \"Verification Token\", // Not required, required to subscribe to event and message cards\n    helpDeskID: \"HelpDesk ID\", // Not required, required when using the help Desk API\n    helpDeskToken: \"HelpDesk Token\", // Not required, required when using the help Desk API\n})\n\n// Currently, you are visiting larksuite, which uses default storage and default log (error level). For more optional configurations, see readme.md -\u003e How to Build an overall Configuration (Config).\nconst conf = lark.newConfig(lark.Domain.FeiShu, appSettings, {\n    loggerLevel: lark.LoggerLevel.ERROR,\n})\n\n// The content of the sent message\nconst body = {\n    open_id: \"user open id\",\n    msg_type: \"text\",\n    content: {\n        text: \"test send message\",\n    },\n}\n// Build request\nconst req = lark.api.newRequest(\"/open-apis/message/v4/send\", \"POST\", lark.api.AccessTokenType.Tenant, body)\n// Send request \nlark.api.sendRequest(conf, req).then(r =\u003e {\n    // Print the requestId of the request\n    console.log(r.getRequestID())\n    // Print the response status of the request\n    console.log(r.getHTTPStatusCode())\n    console.log(r) // r = response.body\n}).catch(e =\u003e {\n    // Error handling of request\n    console.log(e)\n})\n```\n\n### Subscribe to events\n\n- [Subscribe to events](https://open.larksuite.com/document/uMzMyEjLzMjMx4yMzITM/uETM4QjLxEDO04SMxgDN) , to understand\n  the process and precautions of subscribing to events.\n- For more use examples, please refer to [packages/sample/src/event](packages/sample/src/event)（including: use in combination with express）\n\n#### Example of using `Custom App` to subscribe [App First Enabled](https://open.larksuite.com/document/uMzMyEjLzMjMx4yMzITM/uYjMyYjL2IjM24iNyIjN) event.\n\n```javascript\n// import * as lark from \"@larksuiteoapi/allcore\";  // typescript\nconst lark = require(\"@larksuiteoapi/allcore\");     // javascript\n\n// Configuration of custom app, parameter description:\n// appID、appSecret: \"Developer Console\" -\u003e \"Credentials\"（App ID、App Secret）\n// verificationToken、encryptKey：\"Developer Console\" -\u003e \"Event Subscriptions\"（Verification Token、Encrypt Key）\n// helpDeskID、helpDeskToken, Help Desk token：https://open.feishu.cn/document/ukTMukTMukTM/ugDOyYjL4gjM24CO4IjN\nconst appSettings = lark.newInternalAppSettings({\n    appID: \"App ID\",\n    appSecret: \"App Secret\",\n    encryptKey: \"Encrypt Key\",\n    verificationToken: \"Verification Token\",\n})\n\n// Currently, you are visiting larksuite, which uses default storage and default log (error level). For more optional configurations, see readme.md -\u003e How to Build an overall Configuration (Config).\nconst conf = lark.newConfig(lark.Domain.FeiShu, appSettings, {\n    loggerLevel: lark.LoggerLevel.ERROR,\n})\n\n// Set the application event handler to be enabled for the first time\nlark.event.setTypeHandler(conf, \"app_open\", (ctx, event) =\u003e {\n    // Print the request ID of the request\n    console.log(ctx.getRequestID());\n    // Print event\n    console.log(event);\n})\n\n// Start the httpserver, \"Developer Console\" -\u003e \"Event Subscriptions\", setting Request URL：https://domain\n// startup event http server, port: 8089\nlark.event.startServer(conf, 8089)\n\n```\n\n### Processing message card callbacks\n\n- [Message Card Development Process](https://open.larksuite.com/document/uMzMyEjLzMjMx4yMzITM/ukzM3QjL5MzN04SOzcDN) , to\n  understand the process and precautions of processing message cards\n- For more use examples, please refer to [packages/sample/src/card](packages/sample/src/card)（including: use in combination with express）\n\n#### Example of using `Custom App` to handling message card callback.\n\n```javascript\n// import * as lark from \"@larksuiteoapi/allcore\";  // typescript\nconst lark = require(\"@larksuiteoapi/allcore\");     // javascript\n\n// Configuration of custom app, parameter description:\n// appID、appSecret: \"Developer Console\" -\u003e \"Credentials\"（App ID、App Secret）\n// verificationToken、encryptKey：\"Developer Console\" -\u003e \"Event Subscriptions\"（Verification Token、Encrypt Key）\n// helpDeskID、helpDeskToken, Help Desk token：https://open.feishu.cn/document/ukTMukTMukTM/ugDOyYjL4gjM24CO4IjN\nconst appSettings = lark.newInternalAppSettings({\n    appID: \"App ID\",\n    appSecret: \"App Secret\",\n    encryptKey: \"Encrypt Key\", // Not required. Required when subscribing to events\n    verificationToken: \"Verification Token\",\n})\n\n// Currently, you are visiting larksuite, which uses default storage and default log (error level). For more optional configurations, see readme.md -\u003e How to Build an overall Configuration (Config).\nconst conf = lark.newConfig(lark.Domain.FeiShu, appSettings, {\n    loggerLevel: lark.LoggerLevel.ERROR,\n})\n\n// Set the handler of the message card\n// Return value: can be \"\", JSON string of new message card\nlark.card.setHandler(conf, (ctx, card) =\u003e {\n    // 打印消息卡片\n    console.log(card)\n    console.log(card.action)\n    return \"{\\\"config\\\":{\\\"wide_screen_mode\\\":true},\\\"i18n_elements\\\":{\\\"zh_cn\\\":[{\\\"tag\\\":\\\"div\\\",\\\"text\\\":{\\\"tag\\\":\\\"lark_md\\\",\\\"content\\\":\\\"[飞书](https://www.feishu.cn)整合即时沟通、日历、音视频会议、云文档、云盘、工作台等功能于一体，成就组织和个人，更高效、更愉悦。\\\"}}]}}\";\n})\n\n// Start the httpserver, \"Developer Console\" -\u003e \"Features\" -\u003e \"Bot\", setting Message Card Request URL: https://domain\n// startup event http server, port: 8089\nlark.event.startServer(conf, 8089)\n```\n\n## How to build app settings(AppSettings)\n\n```javascript\n// import * as lark from \"@larksuiteoapi/allcore\";  // typescript\nconst lark = require(\"@larksuiteoapi/allcore\");     // javascript\n\n// To prevent application information leakage, in the configuration environment variables, the variables (4) are described as follows:\n// APP_ID: \"Developer Console\" -\u003e \"Credentials\"（App ID）\n// APP_Secret: \"Developer Console\" -\u003e \"Credentials\"（App Secret）\n// VERIFICATION_Token: VerificationToken、EncryptKey：\"Developer Console\" -\u003e \"Event Subscriptions\"（Verification Token）\n// ENCRYPT_Key: VerificationToken、EncryptKey：\"Developer Console\" -\u003e \"Event Subscriptions\"（Encrypt Key）\n// HELP_DESK_ID: Service desk setup center -\u003e ID\n// HELP_DESK_TOKEN: Service desk setup center -\u003e 令牌\n// The configuration of \"Custom App\" is obtained through environment variables\nconst appSettings = lark.getInternalAppSettingsByEnv()\n// The configuration of \"Marketplace App\" is obtained through environment variables\nconst appSettings = lark.getISVAppSettingsByEnv()\n\n\n// Parameter description:\n// appID、appSecret: \"Developer Console\" -\u003e \"Credentials\"（App ID、App Secret）\n// verificationToken、encryptKey：\"Developer Console\" -\u003e \"Event Subscriptions\"（Verification Token、Encrypt Key）\n// helpDeskID、helpDeskToken, Help Desk token：https://open.feishu.cn/document/ukTMukTMukTM/ugDOyYjL4gjM24CO4IjN\n// The Configuration of custom app, parameter description:\nconst appSettings = lark.newInternalAppSettings({\n    appID: \"App ID\",\n    appSecret: \"App Secret\",\n    encryptKey: \"Encrypt Key\", // Not required. Required when subscribing to events\n    verificationToken: \"Verification Token\", // Not required, required to subscribe to event and message cards\n    helpDeskID: \"HelpDesk ID\", // Not required, required when using the help Desk API\n    helpDeskToken: \"HelpDesk Token\", // Not required, required when using the help Desk API\n})\n// The configuration of \"Marketplace App\"\nconst appSettings = lark.newISVAppSettings({\n    appID: \"App ID\",\n    appSecret: \"App Secret\",\n    encryptKey: \"Encrypt Key\", // Not required. Required when subscribing to events\n    verificationToken: \"Verification Token\", // Not required, required to subscribe to event and message cards\n    helpDeskID: \"HelpDesk ID\", // Not required, required when using the help Desk API\n    helpDeskToken: \"HelpDesk Token\", // Not required, required when using the help Desk API\n})\n\n```\n\n## How to build overall configuration(Config)\n\n- Visit Larksuite, Feishu or others\n- App settings\n- The implementation of logger is used to output the logs generated in the process of SDK processing, which is\n  convenient for troubleshooting.\n    - You can use the log implementation of the business system, see the sample\n      code: [packages/core/src/log/log.ts](packages/core/src/log/log.ts) ConsoleLogger\n- The implementation of store is used to save the access credentials (app/tenant_access_token), temporary voucher (\n  app_ticket）\n    - Redis is recommended. Please see the example code: [sample/config/redis_store.go](packages/sample/src/config/config.ts) RedisStore\n        - It can reduce the times of obtaining access credentials and prevent the frequency limit of calling access\n          credentials interface.\n        - \"Marketplace App\", accept open platform distributed `app_ticket` will be saved to the storage, so the\n          implementation of the storage interface (store) needs to support distributed storage.\n\n```javascript\n// import * as lark from \"@larksuiteoapi/allcore\";  // typescript\nconst lark = require(\"@larksuiteoapi/allcore\");\n\n// It is recommended to use Redis to implement the storage interface (Store) to reduce the number of accesses to the AccessToken interface\n// Parameter description:\n// domain: URL Domain address. Value range: lark.Domain.FeiShu / lark.Domain.LarkSuite / Other URL domain name address\n// appSettings: application configuration\n// opts: configuration options\n    // opts.logger: [log interface](core/log/log.go), default: lark.ConsoleLogger\n    // opts.loggerlevel: log level. Default: ERROR level （lark.LoggerLevel.ERROR）\n    // opts.store: [storage port](core/store/store.go), used to store app_ticket/app_access_token/tenant_access_token. Default: lark.DefaultStore\nlark.newConfig(domain: Domain, appSettings: AppSettings, opts: ConfigOpts): Config\n\n// Use example:\nconst conf = lark.newConfig(lark.Domain.FeiShu, appSettings, {\n    loggerLevel: lark.LoggerLevel.ERROR,\n    logger: new lark.ConsoleLogger(),\n    store: new lark.DefaultStore(),\n})\n```    \n\n## How to build a request(Request)\n\n- For more examples, see[packages/sample/src/api](packages/sample/src/api)（including: file upload and download）\n\n```javascript\n// import * as lark from \"@larksuiteoapi/allcore\";  // typescript\nconst lark = require(\"@larksuiteoapi/allcore\");\n\n// Create request \n// httpPath: API path\n    // such as: https://domain/open-apis/contact/v3/users/:user_id\n    // support: the path of the domain name after, httpPath: \"/open apis/contact/v3/users/:user_id\" (recommended)\n    // support: the full path, httpPath: \"https://domain/open-apis/contact/v3/users/:user_id\"\n    // support: httpPath: \"contact/v3/users/:user_id\"\n// httpMethod: GET/POST/PUT/BATCH/DELETE \n// accessTokenType: What kind of token access the API uses, value range: lark.api.AccessTokenType.App/Tenant/User, for example: lark.api.AccessTokenType.Tenant \n// input : The request body (may be formdata (for example: file upload)), if the request body is not needed (for example, some GET requests), pass: undefined\nlet req = lark.api.newRequest(httpPath: string, httpMethod: string, accessTokenType: AccessTokenType, input: any)\n\n// Request method , SDK version requirements: 1.0.9 and above\n\nsetPathParams(pathParams: { [key: string]: any }) // Set the URL Path parameter (with: prefix) value\n// Use example:\nreq.setPathParams({\"user_id\":4}) // when httpPath=\"users/:user_id\", the requested URL=\"https://{domain}/open-apis/users/4\" \n\n\nsetQueryParams(queryParams: { [key: string]: any }) // Set the URL qeury\n// Use example:\nreq.setQueryParams({\"age\":4,\"types\":[1,2]}) // it will be appended to the url?age=4\u0026types=1\u0026types=2 \n\n\nsetTenantKey(tenantKey: string) // to `ISV application` status, indication `tenant_access_token` access API, you need to set \n// Use example:\nreq.setTenantKey(\"68daYsd\") // Set TenantKey to \"68daysd\"\n\n\nsetUserAccessToken(userAccessToken: string) // use of` user_access_token` access API, you need to set \n// Use example:\nreq.setUserAccessToken(\"u-7f1bcd13fc57d46bac21793a18e560\") // Set the user access token to \"u-7f1bcd13fc57d46bac21793a18e560\"\n\n\nsetTimeoutOfMs(timeoutOfMs: number) // set the http request, timeout time in milliseconds \n// Use example:\nreq.setTimeoutOfMs(5000) // Set the request timeout to 5000 Ms\n\n\nsetIsResponseStream() // set whether the response is a stream, such as downloading a file, at this time: the output value is of Buffer type\n// Use example:\nreq.setIsResponseStream() // set the response is a stream\n\n\nsetResponseStream(responseStream: stream.Writable) // Set whether the response body is a stream. For example, when downloading a file, the response stream will be written to the responsestream\n// Use example:\nreq.setResponseStream(fs.createWriteStream(\"./test.1.png\")) // Write the response stream to the \"./test.1.png\" file\n\n\nsetNeedHelpDeskAuth() // If it is a HelpDesk API, you need to set the HelpDesk token\n// Use example:\nreq.setNeedHelpDeskAuth() // Sets whether the request requires a HelpDesk token\n\n\n```\n\n## How to send a request\n- Since the SDK has encapsulated the app_access_token、tenant_access_token So when calling the business API, you don't need to get the app_access_token、tenant_access_token. If the business interface needs to use user_access_token, which needs to be set（lark.api.setUserAccessToken(\"UserAccessToken\")), Please refer to README.md -\u003e How to build a request(Request)\n- For more use examples, please see: [packages/sample/src/api](packages/sample/src/api)（including: file upload and download）\n\n```javascript\n// import * as lark from \"@larksuiteoapi/allcore\";  // typescript\nconst lark = require(\"@larksuiteoapi/allcore\");\n\n// Parameter Description:\n// conf：Overall configuration（Config）\n// req：Request（Request）\n// resp: http response body json\n// err：Send request happen error \nasync lark.api.sendRequest(conf: lark.core.Config, req: lark.api.Request)\n\n```\n\n## lark.core.Context common methods\n\n```javascript\n// import * as lark from \"@larksuiteoapi/allcore\";  // typescript\nconst lark = require(\"@larksuiteoapi/allcore\");\n\n// In the handler of event subscription and message card callback, you can lark.core.Context Get config from\nconst conf = lark.core.getConfigByCtx(ctx: lark.core.Context)\n\n```\n\n## Download File Tool\n\n- Download files via network request\n- For more use examples, please see: [packages/sample/src/tools/downFile.js](packages/sample/src/tools/downFile.js)\n\n```javascript\n// import * as lark from \"@larksuiteoapi/allcore\";  // typescript\nconst lark = require(\"@larksuiteoapi/allcore\");\n\n// Get the file content\n// Parameter Description:\n// url：The HTTP address of the file\n// timeoutOfMs：Time the request timed out in milliseconds\n// Return value Description:\n// resp: http response body binary\n// err：Send request happen error\nasync lark.api.downloadFile(url: string, timeoutOfMs: number)\n\n```\n\n## License\n\n---\n\n- MIT\n    \n","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flarksuite%2Foapi-sdk-nodejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flarksuite%2Foapi-sdk-nodejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flarksuite%2Foapi-sdk-nodejs/lists"}