You can transfer data from Lark to a RAGFlow knowledge base in Data Transmission Service (DTS). Supported data types include Lark Docs, Sheets, Bitable, and Wiki.
Prerequisites
You have created a RAGFlow knowledge base in DTS and configured an IP whitelist.
Background information
Supported data types
DTS RAGFlow supports data from Lark Docs, Sheets, Bitable, and Wiki.
Access methods
Lark data can be accessed by using either an application access token (tenant_access_token) or a user access token (user_access_token).
|
Method |
Permission type |
Pros |
Cons |
|
|
Application identity |
|
More complex authorization. You must configure separate access permissions for Drive and Wiki. |
|
|
User identity |
Simpler authorization. Grants access to all folders without requiring separate permissions for Drive and Wiki. |
|
Before you begin
-
Log in to the Lark Open Platform, and go to the Developer Console.
-
You can click Create Enterprise-developed Application, configure related information such as Name and Application Description, and then click Create.
-
Click the app card to open its configuration page.
By default, you are on the page.
-
On the Credentials and Basic Information page, in the Application Credentials section, record the App ID and App Secret.
Procedure
For detailed instructions on Lark, see the official Lark documentation (Help Center and development documents).
Step 1: Configure access permissions
Application access token
-
Log in to the Lark Open Platform, and go to the Developer Console.
-
Click the app that you created in the Before you begin section.
-
Add a bot and release the app.
-
In the left navigation bar, select .
-
On the Add by Capability tab, in the card for the bot, click Add.
-
At the top of the page, click Create Version.
NoteAlternatively, in the left navigation bar, select , and then click Create Version.
-
On the Version Details page, enter the Application Version and Update Description.
NoteYou can use the default bot for the default mobile client capabilities and default desktop client capabilities.
-
Click Save.
-
In the dialog box that appears, click Confirm Publish.
-
-
Configure API permissions.
-
In the left navigation bar, select .
-
Click Batch Import/Export Permissions.
-
On the Import tab, in the JSON text box, configure the following user identity permissions for the application.
{ "scopes": { "tenant": [ "docs:document:export", "drive:drive", "wiki:wiki" ], "user": [] } } -
Click Next to confirm the new permissions.
-
Click Activate Now.
-
-
Log in to the Lark client, create a new group, and add the application that you created in the Preparations section as a group bot.
-
Configure access permissions for Drive and Wiki.
Drive permissions
-
Go to the target folder in Drive.
-
On the right side of the page, click Share.
-
For Invite collaborators, add the group that you created in Step 5.
The default Read permission is sufficient for this purpose.
-
Click Send.
Wiki permissions
-
Go to the All Wikis page.
-
Move the pointer over the target knowledge base, and then click Knowledge Base Settings.
-
Click the Member Settings tab, and on the Administrator tab in the Roles and Permissions area, click Add Administrator.
-
In the dialog box that appears, add the group that you created in Step 5, and click Next.
-
Click Send.
-
User access token
-
Log in to the Lark Open Platform, and go to the Developer Console.
-
Click the app that you created in the Before you begin section.
-
Configure API permissions.
-
In the left navigation bar, select .
-
Click Batch Import/Export Permissions.
-
Paste the following JSON to grant the required user identity permissions to the app you created.
{ "scopes": { "tenant": [], "user": [ "offline_access", "docs:document:export", "drive:drive", "wiki:wiki" ] } } -
Click Next, Confirm New Permissions.
-
Click Activate Now.
-
-
Configure the redirect URL.
-
In the left navigation bar, select .
-
In the Redirect URL text box, enter
https://www.aliyun.com. -
Click Add to the right of the text box.
-
Turn on the Refresh user_access_token switch.
NoteIf this switch is not visible, the feature is enabled by default.
-
-
Obtain the authorization code.
-
Construct the URL for the Lark authorization page.
NoteYou must replace
YOUR_FEISHU_CLIENT_IDin the URL with the App ID recorded in Preparations.https://accounts.feishu.cn/open-apis/authen/v1/authorize?client_id=YOUR_FEISHU_CLIENT_ID&redirect_uri=https://www.aliyun.com&scope=drive:drive offline_access docs:document:export wiki:wiki -
Open the authorization page in a browser.
-
Click Authorize.
-
Obtain the authorization code (
code) from the redirect URL.NoteThe authorization code does not include code=, &, or information that follows the & symbol.
-
Step 2: Get the Lark folder token and Wiki ID
-
Log on to the Lark client.
-
Obtain the folder token for the Lark Docs folder.
-
Go to the target folder.
-
From the address bar of your browser, copy the URL for the folder.
-
Obtain the token from the URL (the information after
folder/).NoteThe token does not include the ? or any information that follows.
-
-
Obtain the ID of the Wiki.
-
Go to the All Wikis page.
-
Move the pointer over the target knowledge base, and then click Knowledge Base Settings.
-
From the address bar of your browser, copy the URL for the target Wiki.
-
Obtain the knowledge base ID from the URL (the string after
settings/).NoteThe knowledge base ID is purely numeric and does not include the # symbol or any information that follows it.
-
Step 3: Run the KBSync program
-
Obtain the KBSync file.
NoteYou can join the DingTalk group (ID: 79690034672) and contact technical support to obtain the KBSync file.
-
Prepare the runtime environment for the KBSync program.
NoteThe KBSync program requires a Linux environment with access to the Lark Open Platform and RAGFlow.
-
Prepare the config file.
-
Create a Linux system file named config.
-
Copy the following code to the config file.
whiteList= blackList= sinkType=RagFlow sourceType=FeiShu ragflowUrl=http://XX.XX.XX.XX ragflowApiKey=Bearer RAGFlow-BmND******MDI0Mm ragflowDatasetId=928d061******2ac120006 feishuAppId=cli_a8a******d00d feishuAppSecret=pMp73Si******UDrWXBSOa feishuUserAccessCode=bGzpx6******B9KFCdzdCDHG feishuCloudSpaceDirToken=ESJm*******CRdn002cii3bnAc feishuWikiSpaceId=7504968******8674 -
Replace the parameters in the config file.
Important-
For parameters that you do not need to configure, leave the value empty.
-
If you provide values for both the
feishuCloudSpaceDirTokenandfeishuWikiSpaceIdparameters, only Lark Docs and their parent folders are transferred because only thefeishuCloudSpaceDirTokenparameter takes effect. -
The
blackListparameter has a higher priority than thewhiteListparameter.
Parameter
Required
Description
How to obtain
whiteListNo
The paths of files to transfer (whitelist) and files to exclude (blacklist). These paths include folder paths in Lark Docs and document paths in the knowledge base.
NoteRegular expressions are supported. Separate multiple paths with spaces.
Obtain the paths from the Lark client.
blackListNo
sinkTypeYes
The type of the destination.
Set this parameter to
RagFlow.sourceTypeYes
The type of the source.
Set this parameter to
Feishu.ragflowUrlYes
The address of RAGFlow (API server).
Obtain the API server address of the RAGFlow knowledge base.
ragflowApiKeyYes
The API key for the RAGFlow knowledge base.
ragflowDatasetIdYes
The ID of the RAGFlow knowledge base.
feishuAppIdYes
The ID of the application in Lark (App ID).
feishuAppSecretYes
The secret of the application in Lark (App Secret).
feishuUserAccessCodeNo
NoteThis parameter is required only when you access Lark data using the user_access_token method.
The authorization code for Lark.
feishuCloudSpaceDirTokenNo
NotePass a value for only one of these parameters.
The token for the folder that contains the Lark Docs.
Obtain the token for the Lark Docs folder and the ID of the knowledge base.
feishuWikiSpaceIdThe ID of the Lark knowledge base.
-
-
-
Place the KBSync file and the config configuration file in the same directory in a Linux environment.
-
In your Linux environment, run the
./KBSync --config configcommand to start the KBSync program.The following output indicates that KBSync is running correctly.
./KBSync --config config INFO config whiteList=, blackList= INFO config ragflowUrl=http://XX.XX.XX.XX/, ragflowApiKey=Bearer RAGFlow-BmND******MDI0Mm INFO config ragflowDatasetId=928d061******2ac120006 INFO config feishuAppId=cli_a8a******d00d, feishuAppSecret=pMp73Si******UDrWXBSOa INFO Response from https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal: 200, headers: {'Server': 'Tengine', 'Content-Type': 'application/json', 'Content-Length': '102', 'Connection': 'keep-alive', 'Date': 'Tue, 08 Jul 2025 02:49:01 GMT', 'Request-Id': '25bf****-d386-4a86-****-f440f070****', 'Tt_st****': '1', 'X-Lgw-Dst-Svc': 'jbpiSR****OiA0J3d****-Oz0xugYAH9otZIFg4x****', 'X-Request-Id': '25bf****-d386-4a86-b9f4-f440f070****', 'X-Tt-Logid': '202507081049012933B870245850D****', 'server-timing': 'inner; dur=73, cdn-cache;desc=MISS,edge;dur=0,origin;dur=129', 'x-tt-trace-host': '****', 'x-tt-trace-tag': '****', 'x-tt-trace-id': '00-****', 'X-Timestamp': '175194****.952', 'Via': 'cache8.cn6540[129,0]', 'Timing-Allow-Origin': '*', 'EagleId': '6ae3651c1751942941849****'}, body: b'{"code":0,"expire":4340,"msg":"ok","tenant_access_token":"t-g10478a*******CSC3YVY"}' INFO set feishu tenant access token expires in: 4340
Appendix
Get the RAGFlow API server address
-
In the navigation pane on the left, click API.
-
Obtain the API server.
Get the RAGFlow API key
-
In the navigation pane on the left, click API.
-
To the right of RAGFlow API, click API KEY.
-
In the API KEY dialog box, click Create New Key.
-
Click
to copy the key, and then save it in a secure location.
Get the RAGFlow knowledge base ID
-
On the Knowledge Base page, click the target knowledge base.
-
In the URL in your browser's address bar, copy the knowledge base ID.
NoteThe knowledge base ID is the string of characters that follows
id=.