productivity
Matrix Lua API for KosmoKrator Agents
Agent-facing Lua documentation and function reference for the Matrix KosmoKrator integration.Lua Namespace
Agents call this integration through app.integrations.matrix.*.
Use lua_read_doc("integrations.matrix") inside KosmoKrator to discover the same reference at runtime.
Call Lua from the Headless CLI
Use kosmo integrations:lua when a shell script, CI job, cron job, or another coding CLI should run a deterministic
Matrix workflow without starting an interactive agent session.
kosmo integrations:lua --eval 'dump(app.integrations.matrix.list_rooms({limit = 1, from = "example_from"}))' --json kosmo integrations:lua --eval 'print(docs.read("matrix"))' --json
kosmo integrations:lua --eval 'print(docs.read("matrix.list_rooms"))' --json Workflow file
Put repeatable logic in a Lua file, then execute it with JSON output for the calling process.
local matrix = app.integrations.matrix
local result = matrix.list_rooms({limit = 1, from = "example_from"})
dump(result) kosmo integrations:lua workflow.lua --json
kosmo integrations:lua workflow.lua --force --json integrations:lua exposes app.integrations.matrix, app.mcp.*, docs.*, json.*, and regex.*. Use app.integrations.matrix.default.* or app.integrations.matrix.work.* when you configured named credential accounts.
MCP-only Lua
If the script only needs configured MCP servers and does not need Matrix, use the narrower mcp:lua command.
# Use mcp:lua for MCP-only scripts; use integrations:lua for this integration namespace.
kosmo mcp:lua --eval 'dump(mcp.servers())' --json Agent-Facing Lua Docs
This is the rendered version of the full Lua documentation exposed to agents when they inspect the integration namespace.
Matrix — Lua API Reference
list_rooms
List rooms the authenticated user has joined on Matrix.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
limit | integer | no | Maximum number of rooms to return (default: 50) |
from | string | no | Pagination token from a previous response to get the next page |
Examples
local result = app.integrations.matrix.list_rooms({
limit = 20
})
for _, room in ipairs(result.rooms) do
print(room.room_id .. ": " .. (room.name or "Unnamed"))
end
get_room
Get details of a specific Matrix room.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
room_id | string | yes | The room ID (e.g., "!abc123:matrix.org") |
Example
local result = app.integrations.matrix.get_room({
room_id = "!abc123:matrix.org"
})
print("Name: " .. (result.name or "Unnamed"))
print("Topic: " .. (result.topic or "No topic"))
create_room
Create a new room on the Matrix homeserver.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
name | string | yes | The room name |
topic | string | no | The room topic / description |
visibility | string | no | "public" or "private" (default: "private") |
preset | string | no | "private_chat", "public_chat", or "trusted_private_chat" (default: "private_chat") |
Example
local result = app.integrations.matrix.create_room({
name = "Project Alpha",
topic = "Discussion for Project Alpha",
visibility = "private",
preset = "private_chat"
})
print("Created room: " .. result.room_id)
send_message
Send a text message to a Matrix room.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
room_id | string | yes | The room ID to send the message to |
body | string | yes | The message body text |
msgtype | string | no | Message type: "m.text" (default), "m.notice", "m.emote", or "m.html" |
txn_id | string | no | Unique transaction ID. If omitted, a random ID is generated |
Example
local result = app.integrations.matrix.send_message({
room_id = "!abc123:matrix.org",
body = "Hello from the integration!",
msgtype = "m.text"
})
print("Event ID: " .. result.event_id)
list_members
List members of a Matrix room.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
room_id | string | yes | The room ID |
limit | integer | no | Maximum number of members to return (default: 100) |
Example
local result = app.integrations.matrix.list_members({
room_id = "!abc123:matrix.org",
limit = 50
})
for _, member in ipairs(result.members) do
print(member.user_id .. " (" .. (member.display_name or "no name") .. ")")
end
get_profile
Get a Matrix user’s profile information.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
user_id | string | yes | The Matrix user ID (e.g., "@alice:matrix.org") |
Example
local result = app.integrations.matrix.get_profile({
user_id = "@alice:matrix.org"
})
print("Display name: " .. (result.displayname or "Unknown"))
print("Avatar: " .. (result.avatar_url or "No avatar"))
get_current_user
Get the currently authenticated Matrix user’s information.
Parameters
None.
Example
local result = app.integrations.matrix.get_current_user()
print("User ID: " .. result.user_id)
print("Device ID: " .. (result.device_id or "N/A"))
Multi-Account Usage
If you have multiple Matrix accounts configured, use account-specific namespaces:
-- Default account (always works)
app.integrations.matrix.list_rooms({})
-- Explicit default (portable across setups)
app.integrations.matrix.default.list_rooms({})
-- Named accounts
app.integrations.matrix.work.list_rooms({})
app.integrations.matrix.personal.send_message({
room_id = "!room:matrix.org",
body = "Hello from personal account!"
})
All functions are identical across accounts — only the credentials differ.
Raw agent markdown
# Matrix — Lua API Reference
## list_rooms
List rooms the authenticated user has joined on Matrix.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `limit` | integer | no | Maximum number of rooms to return (default: 50) |
| `from` | string | no | Pagination token from a previous response to get the next page |
### Examples
```lua
local result = app.integrations.matrix.list_rooms({
limit = 20
})
for _, room in ipairs(result.rooms) do
print(room.room_id .. ": " .. (room.name or "Unnamed"))
end
```
---
## get_room
Get details of a specific Matrix room.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `room_id` | string | yes | The room ID (e.g., `"!abc123:matrix.org"`) |
### Example
```lua
local result = app.integrations.matrix.get_room({
room_id = "!abc123:matrix.org"
})
print("Name: " .. (result.name or "Unnamed"))
print("Topic: " .. (result.topic or "No topic"))
```
---
## create_room
Create a new room on the Matrix homeserver.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `name` | string | yes | The room name |
| `topic` | string | no | The room topic / description |
| `visibility` | string | no | `"public"` or `"private"` (default: `"private"`) |
| `preset` | string | no | `"private_chat"`, `"public_chat"`, or `"trusted_private_chat"` (default: `"private_chat"`) |
### Example
```lua
local result = app.integrations.matrix.create_room({
name = "Project Alpha",
topic = "Discussion for Project Alpha",
visibility = "private",
preset = "private_chat"
})
print("Created room: " .. result.room_id)
```
---
## send_message
Send a text message to a Matrix room.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `room_id` | string | yes | The room ID to send the message to |
| `body` | string | yes | The message body text |
| `msgtype` | string | no | Message type: `"m.text"` (default), `"m.notice"`, `"m.emote"`, or `"m.html"` |
| `txn_id` | string | no | Unique transaction ID. If omitted, a random ID is generated |
### Example
```lua
local result = app.integrations.matrix.send_message({
room_id = "!abc123:matrix.org",
body = "Hello from the integration!",
msgtype = "m.text"
})
print("Event ID: " .. result.event_id)
```
---
## list_members
List members of a Matrix room.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `room_id` | string | yes | The room ID |
| `limit` | integer | no | Maximum number of members to return (default: 100) |
### Example
```lua
local result = app.integrations.matrix.list_members({
room_id = "!abc123:matrix.org",
limit = 50
})
for _, member in ipairs(result.members) do
print(member.user_id .. " (" .. (member.display_name or "no name") .. ")")
end
```
---
## get_profile
Get a Matrix user's profile information.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `user_id` | string | yes | The Matrix user ID (e.g., `"@alice:matrix.org"`) |
### Example
```lua
local result = app.integrations.matrix.get_profile({
user_id = "@alice:matrix.org"
})
print("Display name: " .. (result.displayname or "Unknown"))
print("Avatar: " .. (result.avatar_url or "No avatar"))
```
---
## get_current_user
Get the currently authenticated Matrix user's information.
### Parameters
None.
### Example
```lua
local result = app.integrations.matrix.get_current_user()
print("User ID: " .. result.user_id)
print("Device ID: " .. (result.device_id or "N/A"))
```
---
## Multi-Account Usage
If you have multiple Matrix accounts configured, use account-specific namespaces:
```lua
-- Default account (always works)
app.integrations.matrix.list_rooms({})
-- Explicit default (portable across setups)
app.integrations.matrix.default.list_rooms({})
-- Named accounts
app.integrations.matrix.work.list_rooms({})
app.integrations.matrix.personal.send_message({
room_id = "!room:matrix.org",
body = "Hello from personal account!"
})
```
All functions are identical across accounts — only the credentials differ. local result = app.integrations.matrix.list_rooms({limit = 1, from = "example_from"})
print(result) Functions
list_rooms Read
List rooms the authenticated user has joined on Matrix. Returns room IDs, names, and aliases.
- Lua path
app.integrations.matrix.list_rooms- Full name
matrix.matrix_list_rooms
| Parameter | Type | Required | Description |
|---|---|---|---|
limit | integer | no | Maximum number of rooms to return (default: 50). |
from | string | no | Pagination token from a previous response to get the next page. |
get_room Read
Get details of a specific Matrix room, including name, topic, members, and aliases.
- Lua path
app.integrations.matrix.get_room- Full name
matrix.matrix_get_room
| Parameter | Type | Required | Description |
|---|---|---|---|
room_id | string | yes | The room ID (e.g., "!abc123:matrix.org"). |
create_room Write
Create a new room on the Matrix homeserver. Returns the newly created room ID.
- Lua path
app.integrations.matrix.create_room- Full name
matrix.matrix_create_room
| Parameter | Type | Required | Description |
|---|---|---|---|
name | string | yes | The room name (displayed to users). |
topic | string | no | The room topic / description. |
visibility | string | no | Room visibility: "public" or "private" (default: "private"). |
preset | string | no | Room preset: "private_chat", "public_chat", or "trusted_private_chat" (default: "private_chat"). |
send_message Write
Send a text message to a Matrix room. Uses a unique transaction ID to prevent duplicate messages.
- Lua path
app.integrations.matrix.send_message- Full name
matrix.matrix_send_message
| Parameter | Type | Required | Description |
|---|---|---|---|
room_id | string | yes | The room ID to send the message to (e.g., "!abc123:matrix.org"). |
body | string | yes | The message body text. |
msgtype | string | no | Message type: "m.text" (default), "m.notice", "m.emote", or "m.html". |
txn_id | string | no | Unique transaction ID. If omitted, a random ID is generated. |
list_members Read
List members of a Matrix room. Returns user IDs, display names, and avatar URLs.
- Lua path
app.integrations.matrix.list_members- Full name
matrix.matrix_list_members
| Parameter | Type | Required | Description |
|---|---|---|---|
room_id | string | yes | The room ID (e.g., "!abc123:matrix.org"). |
limit | integer | no | Maximum number of members to return (default: 100). |
get_profile Read
Get a Matrix user's profile information, including display name and avatar URL.
- Lua path
app.integrations.matrix.get_profile- Full name
matrix.matrix_get_profile
| Parameter | Type | Required | Description |
|---|---|---|---|
user_id | string | yes | The Matrix user ID (e.g., "@alice:matrix.org"). |
get_current_user Read
Get the currently authenticated Matrix user's information, including user ID and device ID.
- Lua path
app.integrations.matrix.get_current_user- Full name
matrix.matrix_get_current_user
| Parameter | Type | Required | Description |
|---|---|---|---|
| No parameters. | |||