KosmoKrator

communication

Discourse Lua API for KosmoKrator Agents

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

8 functions 5 read 3 write API key auth

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.

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

NameTypeRequiredDescription
pageintegernoPage 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

NameTypeRequiredDescription
topic_idintegeryesThe 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

NameTypeRequiredDescription
titlestringyesThe topic title
rawstringyesBody content in Markdown
categoryintegeryesCategory ID to post in
tagsarraynoTags 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

NameTypeRequiredDescription
topic_idintegeryesThe ID of the topic to update
titlestringnoNew title for the topic
categoryintegernoNew 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

NameTypeRequiredDescription
category_idintegeryesThe 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

NameTypeRequiredDescription
topic_idintegeryesThe ID of the topic to reply to
rawstringyesPost 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.

Metadata-Derived Lua Example

local result = app.integrations.discourse.discourse_list_topics({
  page = 1
})
print(result)

Functions

discourse_list_topics

List the latest topics from the Discourse forum. Returns topic titles, categories, and activity metadata.

Operation
Read read
Full name
discourse.discourse_list_topics
ParameterTypeRequiredDescription
page integer no Page number for pagination (default: 1).

discourse_get_topic

Get a single Discourse topic by ID, including its posts, author, and metadata.

Operation
Read read
Full name
discourse.discourse_get_topic
ParameterTypeRequiredDescription
topic_id integer yes The ID of the topic to retrieve.

discourse_create_topic

Create a new topic in a Discourse category. Requires a title, body content (Markdown), and category ID.

Operation
Write write
Full name
discourse.discourse_create_topic
ParameterTypeRequiredDescription
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).

discourse_update_topic

Update an existing Discourse topic's title or move it to a different category.

Operation
Write write
Full name
discourse.discourse_update_topic
ParameterTypeRequiredDescription
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).

discourse_list_categories

List all categories on the Discourse forum. Returns category names, IDs, descriptions, and parent relationships.

Operation
Read read
Full name
discourse.discourse_list_categories
ParameterTypeRequiredDescription
No parameters.

discourse_get_category

Get a single Discourse category by ID, including its recent topics and metadata.

Operation
Read read
Full name
discourse.discourse_get_category
ParameterTypeRequiredDescription
category_id integer yes The ID of the category to retrieve.

discourse_create_post

Reply to an existing Discourse topic with a new post. Provide the topic ID and body content in Markdown.

Operation
Write write
Full name
discourse.discourse_create_post
ParameterTypeRequiredDescription
topic_id integer yes The ID of the topic to reply to.
raw string yes The post body content in Markdown format.

discourse_get_current_user

Get the currently authenticated Discourse user profile. Useful for verifying API credentials and identifying the user context.

Operation
Read read
Full name
discourse.discourse_get_current_user
ParameterTypeRequiredDescription
No parameters.