Integrate an agent with Lark

Updated at:
Copy as MD

Connect a Function Compute AgentRun agent to Lark so you can interact with it in group chats or private messages by @-mentioning the bot.

Prerequisites

Step 1: Create a Lark app

1. Create an app and get credentials

  1. Sign in to the Lark Open Platform.

  2. Click Create an enterprise-internal app, enter the app name and description, select an app icon, and then click Create.

  3. In the left navigation pane, click Credentials & Basic Info, and then copy the App ID and App Secret.

    The App Secret is displayed only once when you create it. Store it securely. If you lose the secret, you must regenerate it.

2. Import required permissions

  1. In the left navigation pane, click permission management.

  2. Click Batch Import/Export Permissions and paste the following JSON configuration:

    {
      "scopes": {
        "tenant": [
          "aily:file:read",
          "aily:file:write",
          "application:application.app_message_stats.overview:readonly",
          "application:application:self_manage",
          "application:bot.menu:write",
          "cardkit:card:write",
          "contact:user.employee_id:readonly",
          "corehr:file:download",
          "docs:document.content:read",
          "event:ip_list",
          "im:chat",
          "im:chat.access_event.bot_p2p_chat:read",
          "im:chat.members:bot_access",
          "im:message",
          "im:message.group_at_msg:readonly",
          "im:message.group_msg",
          "im:message.p2p_msg:readonly",
          "im:message:readonly",
          "im:message:send_as_bot",
          "im:resource",
          "sheets:spreadsheet",
          "wiki:wiki:readonly"
        ],
        "user": [
          "aily:file:read",
          "aily:file:write",
          "im:chat.access_event.bot_p2p_chat:read"
        ]
      }
    }
  3. Click Next, confirm the new permissions, and then click Request to Activate.

The JSON configuration includes 22 tenant-scoped permissions and 3 user-scoped permissions covering instant messaging, file read/write, document access, spreadsheets, and knowledge bases. Ensure that all permissions are activated. Otherwise, some agent features may not function properly.

3. Enable bot capabilities

  1. In the left navigation pane, click Add App Features.

  2. On the Add by Feature tab, find the Bot card and click Configure.

Step 2: Configure Lark integration

  1. Sign in to the AgentRun console.

  2. Click the name of your target agent to open its details page.

  3. Click the Integration and Publishing tab, click IM Integration, and then click Add IM Bot.

  4. In the Add IM Bot panel, set Robot Mode to Standard Bot, set Select Platform to Lark Bot, and then configure the following parameters:

    Parameter

    Description

    Robot Name

    Enter the display name for the bot. Maximum 128 characters.

    Description

    (Optional) Enter a description for the bot. Maximum 256 characters.

    Robot Mode

    Select Standard Bot to process messages using an Agent Endpoint.

    Select Endpoint

    Select a published Agent Endpoint. The bot uses this endpoint to process messages.

    Select Protocol

    Select a protocol specification for message processing. If you have not created one, click Add Protocol to create one, or click Refresh Protocol List to update.

    Lark App ID

    The App ID from Step 1. You can get it from Application Management - Application Details - Credentials in the Lark Open Platform.

    Lark App Secret

    The App Secret from Step 1.

    Enable upon Creation

    Selected by default. The bot starts running immediately after creation. If cleared, the bot is created in a stopped state and can be enabled later from the list.

  5. Click Create Bot to complete the Lark integration.

    Note

    After the bot is configured, the system automatically deploys an IM service function under your enterprise account. A single function is reused for each primary account. The system provisions one instance (1 vCPU, 1 GB memory, scalable on demand) to maintain a long-lived connection with the bot. Provisioning this instance incurs charges. For more information, see Billing Overview.

Configure Lark event subscriptions

After you complete the AgentRun configuration, return to the Lark Open Platform to configure event subscriptions so the bot can receive user messages.

  1. In the left navigation pane of the Lark Open Platform, click Events & Callbacks.

  2. On the Event Configuration tab, for Subscription Method, select Use Long Connection to Receive Events, and then click Save.

  3. On the Event Configuration page, click Add Event, search for the im.message.receive_v1 event (Receive Message), and then click Confirm Add.

Publish the Lark app

  1. In the left navigation pane of the Lark Open Platform, click Versioning & Publishing.

  2. Click Create Version, enter a version number and update description, and then click Save.

  3. Submit the app for review and then publish it.

    After the app is published, only Lark users within its visibility range can use the bot.

Step 3: Use the agent in Lark

After the configuration is complete, you can interact with the agent in Lark group chats or private messages.

Use in group chats

  1. In Lark, create a new group chat or open an existing one.

  2. In the group settings, add the bot that you created in Step 1.

  3. In the group chat, @-mention the bot's name and enter your question to start a conversation with the agent.

Use in private messages

In the Lark search bar, search for the bot's name, open the chat window with the bot, and send a message to start a private conversation.