KosmoKrator

communication

Lark Suite Lua API for KosmoKrator Agents

Agent-facing Lua documentation and function reference for the Lark Suite KosmoKrator integration.

7 functions 5 read 2 write Bearer token auth

Lua Namespace

Agents call this integration through app.integrations.lark.*. Use lua_read_doc("integrations.lark") inside KosmoKrator to discover the same reference at runtime.

Agent-Facing Lua Docs

This is the rendered version of the full Lua documentation exposed to agents when they inspect the integration namespace.

Lark Suite — Lua API Reference

list_chats

List chats the current authenticated user belongs to.

Parameters

NameTypeRequiredDescription
page_sizeintegernoNumber of chats per page (max 50, default 20)
page_tokenstringnoPagination cursor from a previous response

Examples

-- List first page of chats
local result = app.integrations.lark.list_chats({
  page_size = 20
})

for _, chat in ipairs(result.data.items) do
  print(chat.name .. " (" .. chat.chat_id .. ")")
end

-- Get next page
if result.data.has_more then
  local next = app.integrations.lark.list_chats({
    page_size = 20,
    page_token = result.data.page_token
  })
end

get_chat

Get detailed information about a specific chat.

Parameters

NameTypeRequiredDescription
chat_idstringyesThe chat ID (e.g., "oc_a0553eda9014c201e6969b478895c230")

Example

local result = app.integrations.lark.get_chat({
  chat_id = "oc_a0553eda9014c201e6969b478895c230"
})
print("Chat: " .. result.data.name)
print("Members: " .. result.data.member_count)

create_chat

Create a new group chat.

Parameters

NameTypeRequiredDescription
chat_idstringyesUnique identifier for the new chat
namestringyesDisplay name for the group chat

Example

local result = app.integrations.lark.create_chat({
  chat_id = "oc_my_project_chat",
  name = "Project Discussion"
})
print("Created chat: " .. result.data.chat_id)

list_messages

List messages in a specific chat.

Parameters

NameTypeRequiredDescription
chat_idstringyesThe chat ID to list messages from
page_sizeintegernoNumber of messages per page (max 50, default 20)
page_tokenstringnoPagination cursor from a previous response

Example

local result = app.integrations.lark.list_messages({
  chat_id = "oc_a0553eda9014c201e6969b478895c230",
  page_size = 10
})

for _, msg in ipairs(result.data.items) do
  print(msg.sender.id .. ": " .. msg.body.content)
end

send_message

Send a message to a specific chat.

Parameters

NameTypeRequiredDescription
chat_idstringyesThe chat ID to send the message to
contentstringyesMessage content (JSON-encoded for rich types)
msg_typestringnoMessage type: "text", "post", "image", "file", etc. (default: "text")

Message Types

TypeContent FormatExample
text{"text":"Hello"}Plain text message
postRich text JSONFormatted post with sections
image{"image_key":"..."}Image message
file{"file_key":"..."}File attachment

Examples

-- Send a simple text message
app.integrations.lark.send_message({
  chat_id = "oc_a0553eda9014c201e6969b478895c230",
  content = '{"text":"Hello team!"}',
  msg_type = "text"
})

-- Send plain text (auto-wrapped)
app.integrations.lark.send_message({
  chat_id = "oc_a0553eda9014c201e6969b478895c230",
  content = "Quick update: deployment complete.",
  msg_type = "text"
})

list_members

List members of a specific chat.

Parameters

NameTypeRequiredDescription
chat_idstringyesThe chat ID to list members from
page_sizeintegernoNumber of members per page (max 50, default 20)
page_tokenstringnoPagination cursor from a previous response

Example

local result = app.integrations.lark.list_members({
  chat_id = "oc_a0553eda9014c201e6969b478895c230"
})

for _, member in ipairs(result.data.items) do
  print(member.name .. " (" .. member.member_id .. ")")
end

get_current_user

Get information about the currently authenticated Lark user.

Parameters

None.

Example

local result = app.integrations.lark.get_current_user({})
print("User: " .. result.data.name)
print("ID: " .. result.data.user_id)

Multi-Account Usage

If you have multiple Lark accounts configured, use account-specific namespaces:

-- Default account (always works)
app.integrations.lark.list_chats({})

-- Explicit default (portable across setups)
app.integrations.lark.default.list_chats({})

-- Named accounts
app.integrations.lark.work.send_message({
  chat_id = "oc_abc123",
  content = "Hello from work account!",
  msg_type = "text"
})

app.integrations.lark.personal.list_chats({})

All functions are identical across accounts — only the credentials differ.

Raw agent markdown
# Lark Suite — Lua API Reference

## list_chats

List chats the current authenticated user belongs to.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `page_size` | integer | no | Number of chats per page (max 50, default 20) |
| `page_token` | string | no | Pagination cursor from a previous response |

### Examples

```lua
-- List first page of chats
local result = app.integrations.lark.list_chats({
  page_size = 20
})

for _, chat in ipairs(result.data.items) do
  print(chat.name .. " (" .. chat.chat_id .. ")")
end

-- Get next page
if result.data.has_more then
  local next = app.integrations.lark.list_chats({
    page_size = 20,
    page_token = result.data.page_token
  })
end
```

---

## get_chat

Get detailed information about a specific chat.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `chat_id` | string | yes | The chat ID (e.g., `"oc_a0553eda9014c201e6969b478895c230"`) |

### Example

```lua
local result = app.integrations.lark.get_chat({
  chat_id = "oc_a0553eda9014c201e6969b478895c230"
})
print("Chat: " .. result.data.name)
print("Members: " .. result.data.member_count)
```

---

## create_chat

Create a new group chat.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `chat_id` | string | yes | Unique identifier for the new chat |
| `name` | string | yes | Display name for the group chat |

### Example

```lua
local result = app.integrations.lark.create_chat({
  chat_id = "oc_my_project_chat",
  name = "Project Discussion"
})
print("Created chat: " .. result.data.chat_id)
```

---

## list_messages

List messages in a specific chat.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `chat_id` | string | yes | The chat ID to list messages from |
| `page_size` | integer | no | Number of messages per page (max 50, default 20) |
| `page_token` | string | no | Pagination cursor from a previous response |

### Example

```lua
local result = app.integrations.lark.list_messages({
  chat_id = "oc_a0553eda9014c201e6969b478895c230",
  page_size = 10
})

for _, msg in ipairs(result.data.items) do
  print(msg.sender.id .. ": " .. msg.body.content)
end
```

---

## send_message

Send a message to a specific chat.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `chat_id` | string | yes | The chat ID to send the message to |
| `content` | string | yes | Message content (JSON-encoded for rich types) |
| `msg_type` | string | no | Message type: `"text"`, `"post"`, `"image"`, `"file"`, etc. (default: `"text"`) |

### Message Types

| Type | Content Format | Example |
|------|---------------|---------|
| `text` | `{"text":"Hello"}` | Plain text message |
| `post` | Rich text JSON | Formatted post with sections |
| `image` | `{"image_key":"..."}` | Image message |
| `file` | `{"file_key":"..."}` | File attachment |

### Examples

```lua
-- Send a simple text message
app.integrations.lark.send_message({
  chat_id = "oc_a0553eda9014c201e6969b478895c230",
  content = '{"text":"Hello team!"}',
  msg_type = "text"
})

-- Send plain text (auto-wrapped)
app.integrations.lark.send_message({
  chat_id = "oc_a0553eda9014c201e6969b478895c230",
  content = "Quick update: deployment complete.",
  msg_type = "text"
})
```

---

## list_members

List members of a specific chat.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `chat_id` | string | yes | The chat ID to list members from |
| `page_size` | integer | no | Number of members per page (max 50, default 20) |
| `page_token` | string | no | Pagination cursor from a previous response |

### Example

```lua
local result = app.integrations.lark.list_members({
  chat_id = "oc_a0553eda9014c201e6969b478895c230"
})

for _, member in ipairs(result.data.items) do
  print(member.name .. " (" .. member.member_id .. ")")
end
```

---

## get_current_user

Get information about the currently authenticated Lark user.

### Parameters

None.

### Example

```lua
local result = app.integrations.lark.get_current_user({})
print("User: " .. result.data.name)
print("ID: " .. result.data.user_id)
```

---

## Multi-Account Usage

If you have multiple Lark accounts configured, use account-specific namespaces:

```lua
-- Default account (always works)
app.integrations.lark.list_chats({})

-- Explicit default (portable across setups)
app.integrations.lark.default.list_chats({})

-- Named accounts
app.integrations.lark.work.send_message({
  chat_id = "oc_abc123",
  content = "Hello from work account!",
  msg_type = "text"
})

app.integrations.lark.personal.list_chats({})
```

All functions are identical across accounts — only the credentials differ.

Metadata-Derived Lua Example

local result = app.integrations.lark.lark_list_chats({
  page_size = 1,
  page_token = "example_page_token"
})
print(result)

Functions

lark_list_chats

List chats the current authenticated user belongs to in Lark. Returns chat IDs, names, and metadata for use with other Lark tools.

Operation
Read read
Full name
lark.lark_list_chats
ParameterTypeRequiredDescription
page_size integer no Number of chats to return per page (max 50, default 20).
page_token string no Pagination cursor from a previous response to fetch the next page.

lark_get_chat

Get detailed information about a specific Lark chat, including its name, description, owner, and member count.

Operation
Read read
Full name
lark.lark_get_chat
ParameterTypeRequiredDescription
chat_id string yes The chat ID to retrieve (e.g., "oc_a0553eda9014c201e6969b478895c230").

lark_create_chat

Create a new group chat in Lark. Specify a chat ID and name for the new chat.

Operation
Write write
Full name
lark.lark_create_chat
ParameterTypeRequiredDescription
chat_id string yes A unique identifier for the new chat (e.g., "oc_my_new_chat").
name string yes The display name for the new group chat.

lark_list_messages

List messages in a specific Lark chat. Returns message IDs, sender info, content, and timestamps.

Operation
Read read
Full name
lark.lark_list_messages
ParameterTypeRequiredDescription
chat_id string yes The chat ID to list messages from (e.g., "oc_a0553eda9014c201e6969b478895c230").
page_size integer no Number of messages to return per page (max 50, default 20).
page_token string no Pagination cursor from a previous response to fetch the next page.

lark_send_message

Send a message to a specific Lark chat. Supports text and rich message types.

Operation
Write write
Full name
lark.lark_send_message
ParameterTypeRequiredDescription
chat_id string yes The chat ID to send the message to (e.g., "oc_a0553eda9014c201e6969b478895c230").
content string yes The message content. For text messages, pass plain text or JSON like '{"text":"Hello"}'. For rich messages, pass the appropriate JSON structure.
msg_type string no The message type: "text", "post", "image", "file", etc. Defaults to "text".

lark_list_members

List members of a specific Lark chat. Returns member IDs, names, and roles.

Operation
Read read
Full name
lark.lark_list_members
ParameterTypeRequiredDescription
chat_id string yes The chat ID to list members from (e.g., "oc_a0553eda9014c201e6969b478895c230").
page_size integer no Number of members to return per page (max 50, default 20).
page_token string no Pagination cursor from a previous response to fetch the next page.

lark_get_current_user

Get information about the currently authenticated Lark user, including name, user ID, and avatar.

Operation
Read read
Full name
lark.lark_get_current_user
ParameterTypeRequiredDescription
No parameters.