productivity
Discourse Lua API for KosmoKrator Agents
Agent-facing Lua documentation and function reference for the Discourse KosmoKrator integration.Lua Namespace
Agents call this integration through app.integrations.discourse.*.
Use lua_read_doc("integrations.discourse") 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
Discourse workflow without starting an interactive agent session.
kosmo integrations:lua --eval 'dump(app.integrations.discourse.list_topics({page = 1}))' --json kosmo integrations:lua --eval 'print(docs.read("discourse"))' --json
kosmo integrations:lua --eval 'print(docs.read("discourse.list_topics"))' --json Workflow file
Put repeatable logic in a Lua file, then execute it with JSON output for the calling process.
local discourse = app.integrations.discourse
local result = discourse.list_topics({page = 1})
dump(result) kosmo integrations:lua workflow.lua --json
kosmo integrations:lua workflow.lua --force --json integrations:lua exposes app.integrations.discourse, app.mcp.*, docs.*, json.*, and regex.*. Use app.integrations.discourse.default.* or app.integrations.discourse.work.* when you configured named credential accounts.
MCP-only Lua
If the script only needs configured MCP servers and does not need Discourse, 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.
Discourse — Lua API Reference
list_topics
List the latest topics from the forum.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
page | integer | no | Page number for pagination (default: 1) |
Examples
local result = app.integrations.discourse.list_topics({ page = 1 })
for _, topic in ipairs(result.topic_list.topics) do
print(topic.id .. ": " .. topic.title .. " (category: " .. topic.category_id .. ")")
end
get_topic
Get a single topic with its posts and metadata.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
topic_id | integer | yes | The ID of the topic to retrieve |
Examples
local result = app.integrations.discourse.get_topic({ topic_id = 42 })
print("Title: " .. result.title)
print("Posts: " .. result.posts_count)
for _, post in ipairs(result.post_stream.posts) do
print(post.username .. ": " .. post.cooked)
end
create_topic
Create a new topic (first post) in a category.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
title | string | yes | The topic title |
raw | string | yes | Body content in Markdown |
category | integer | yes | Category ID to post in |
tags | array | no | Tags for the topic |
Examples
local result = app.integrations.discourse.create_topic({
title = "Welcome to the new forum",
raw = "This is the first post in our new category!",
category = 5,
tags = { "announcement", "welcome" }
})
print("Created topic ID: " .. result.topic_id)
update_topic
Update an existing topic’s title or move it to a different category.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
topic_id | integer | yes | The ID of the topic to update |
title | string | no | New title for the topic |
category | integer | no | New category ID to move the topic to |
At least one of title or category must be provided.
Examples
-- Rename a topic
app.integrations.discourse.update_topic({
topic_id = 42,
title = "Updated Topic Title"
})
-- Move a topic to a different category
app.integrations.discourse.update_topic({
topic_id = 42,
category = 10
})
list_categories
List all categories on the forum.
Parameters
None.
Examples
local result = app.integrations.discourse.list_categories({})
for _, cat in ipairs(result.category_list.categories) do
print(cat.id .. ": " .. cat.name .. " — " .. (cat.description_text or ""))
end
get_category
Get a single category with its recent topics.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
category_id | integer | yes | The ID of the category to retrieve |
Examples
local result = app.integrations.discourse.get_category({ category_id = 5 })
print("Category: " .. result.topic_list.name)
print("Description: " .. (result.topic_list.description_text or ""))
for _, topic in ipairs(result.topic_list.topics) do
print(" " .. topic.id .. ": " .. topic.title)
end
create_post
Reply to an existing topic with a new post.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
topic_id | integer | yes | The ID of the topic to reply to |
raw | string | yes | Post body content in Markdown |
Examples
local result = app.integrations.discourse.create_post({
topic_id = 42,
raw = "Thanks for the update! This looks great."
})
print("Created post ID: " .. result.id)
get_current_user
Get the currently authenticated user profile. Useful for verifying API credentials.
Parameters
None.
Examples
local result = app.integrations.discourse.get_current_user({})
print("User: " .. result.current_user.username)
print("Name: " .. (result.current_user.name or ""))
print("Admin: " .. tostring(result.current_user.admin))
Multi-Account Usage
If you have multiple Discourse instances configured, use account-specific namespaces:
-- Default account (always works)
app.integrations.discourse.list_topics({})
-- Explicit default (portable across setups)
app.integrations.discourse.default.list_topics({})
-- Named accounts
app.integrations.discourse.community.list_topics({})
app.integrations.discourse.support.list_topics({})
All functions are identical across accounts — only the credentials differ.
Raw agent markdown
# Discourse — Lua API Reference
## list_topics
List the latest topics from the forum.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `page` | integer | no | Page number for pagination (default: 1) |
### Examples
```lua
local result = app.integrations.discourse.list_topics({ page = 1 })
for _, topic in ipairs(result.topic_list.topics) do
print(topic.id .. ": " .. topic.title .. " (category: " .. topic.category_id .. ")")
end
```
---
## get_topic
Get a single topic with its posts and metadata.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `topic_id` | integer | yes | The ID of the topic to retrieve |
### Examples
```lua
local result = app.integrations.discourse.get_topic({ topic_id = 42 })
print("Title: " .. result.title)
print("Posts: " .. result.posts_count)
for _, post in ipairs(result.post_stream.posts) do
print(post.username .. ": " .. post.cooked)
end
```
---
## create_topic
Create a new topic (first post) in a category.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `title` | string | yes | The topic title |
| `raw` | string | yes | Body content in Markdown |
| `category` | integer | yes | Category ID to post in |
| `tags` | array | no | Tags for the topic |
### Examples
```lua
local result = app.integrations.discourse.create_topic({
title = "Welcome to the new forum",
raw = "This is the first post in our new category!",
category = 5,
tags = { "announcement", "welcome" }
})
print("Created topic ID: " .. result.topic_id)
```
---
## update_topic
Update an existing topic's title or move it to a different category.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `topic_id` | integer | yes | The ID of the topic to update |
| `title` | string | no | New title for the topic |
| `category` | integer | no | New category ID to move the topic to |
At least one of `title` or `category` must be provided.
### Examples
```lua
-- Rename a topic
app.integrations.discourse.update_topic({
topic_id = 42,
title = "Updated Topic Title"
})
-- Move a topic to a different category
app.integrations.discourse.update_topic({
topic_id = 42,
category = 10
})
```
---
## list_categories
List all categories on the forum.
### Parameters
None.
### Examples
```lua
local result = app.integrations.discourse.list_categories({})
for _, cat in ipairs(result.category_list.categories) do
print(cat.id .. ": " .. cat.name .. " — " .. (cat.description_text or ""))
end
```
---
## get_category
Get a single category with its recent topics.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `category_id` | integer | yes | The ID of the category to retrieve |
### Examples
```lua
local result = app.integrations.discourse.get_category({ category_id = 5 })
print("Category: " .. result.topic_list.name)
print("Description: " .. (result.topic_list.description_text or ""))
for _, topic in ipairs(result.topic_list.topics) do
print(" " .. topic.id .. ": " .. topic.title)
end
```
---
## create_post
Reply to an existing topic with a new post.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `topic_id` | integer | yes | The ID of the topic to reply to |
| `raw` | string | yes | Post body content in Markdown |
### Examples
```lua
local result = app.integrations.discourse.create_post({
topic_id = 42,
raw = "Thanks for the update! This looks great."
})
print("Created post ID: " .. result.id)
```
---
## get_current_user
Get the currently authenticated user profile. Useful for verifying API credentials.
### Parameters
None.
### Examples
```lua
local result = app.integrations.discourse.get_current_user({})
print("User: " .. result.current_user.username)
print("Name: " .. (result.current_user.name or ""))
print("Admin: " .. tostring(result.current_user.admin))
```
---
## Multi-Account Usage
If you have multiple Discourse instances configured, use account-specific namespaces:
```lua
-- Default account (always works)
app.integrations.discourse.list_topics({})
-- Explicit default (portable across setups)
app.integrations.discourse.default.list_topics({})
-- Named accounts
app.integrations.discourse.community.list_topics({})
app.integrations.discourse.support.list_topics({})
```
All functions are identical across accounts — only the credentials differ. local result = app.integrations.discourse.list_topics({page = 1})
print(result) Functions
list_topics Read
List the latest topics from the Discourse forum. Returns topic titles, categories, and activity metadata.
- Lua path
app.integrations.discourse.list_topics- Full name
discourse.discourse_list_topics
| Parameter | Type | Required | Description |
|---|---|---|---|
page | integer | no | Page number for pagination (default: 1). |
get_topic Read
Get a single Discourse topic by ID, including its posts, author, and metadata.
- Lua path
app.integrations.discourse.get_topic- Full name
discourse.discourse_get_topic
| Parameter | Type | Required | Description |
|---|---|---|---|
topic_id | integer | yes | The ID of the topic to retrieve. |
create_topic Write
Create a new topic in a Discourse category. Requires a title, body content (Markdown), and category ID.
- Lua path
app.integrations.discourse.create_topic- Full name
discourse.discourse_create_topic
| Parameter | Type | Required | Description |
|---|---|---|---|
title | string | yes | The topic title. |
raw | string | yes | The body content in Markdown format. |
category | integer | yes | The category ID to post the topic in. |
tags | array | no | Optional tags for the topic (strings). |
update_topic Write
Update an existing Discourse topic's title or move it to a different category.
- Lua path
app.integrations.discourse.update_topic- Full name
discourse.discourse_update_topic
| Parameter | Type | Required | Description |
|---|---|---|---|
topic_id | integer | yes | The ID of the topic to update. |
title | string | no | The new title for the topic (optional). |
category | integer | no | The new category ID to move the topic to (optional). |
list_categories Read
List all categories on the Discourse forum. Returns category names, IDs, descriptions, and parent relationships.
- Lua path
app.integrations.discourse.list_categories- Full name
discourse.discourse_list_categories
| Parameter | Type | Required | Description |
|---|---|---|---|
| No parameters. | |||
get_category Read
Get a single Discourse category by ID, including its recent topics and metadata.
- Lua path
app.integrations.discourse.get_category- Full name
discourse.discourse_get_category
| Parameter | Type | Required | Description |
|---|---|---|---|
category_id | integer | yes | The ID of the category to retrieve. |
create_post Write
Reply to an existing Discourse topic with a new post. Provide the topic ID and body content in Markdown.
- Lua path
app.integrations.discourse.create_post- Full name
discourse.discourse_create_post
| Parameter | Type | Required | Description |
|---|---|---|---|
topic_id | integer | yes | The ID of the topic to reply to. |
raw | string | yes | The post body content in Markdown format. |
get_current_user Read
Get the currently authenticated Discourse user profile. Useful for verifying API credentials and identifying the user context.
- Lua path
app.integrations.discourse.get_current_user- Full name
discourse.discourse_get_current_user
| Parameter | Type | Required | Description |
|---|---|---|---|
| No parameters. | |||