KosmoKrator

social

Facebook Lua API for KosmoKrator Agents

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

7 functions 6 read 1 write Bearer token auth

Lua Namespace

Agents call this integration through app.integrations.facebook.*. Use lua_read_doc("integrations.facebook") 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.

Facebook — Lua API Reference

list_pages

List all Facebook Pages the authenticated user manages.

Parameters

NameTypeRequiredDescription
fieldsstringnoComma-separated fields (e.g. "id,name,category,fan_count,about"). Defaults to "id,name,category".
limitintegernoMax pages per request.

Example

local result = app.integrations.facebook.list_pages({
  fields = "id,name,fan_count,category"
})

for _, page in ipairs(result.data) do
  print(page.name .. " (ID: " .. page.id .. ", Fans: " .. page.fan_count .. ")")
end

get_page

Get details for a specific Facebook Page.

Parameters

NameTypeRequiredDescription
page_idstringyesThe Facebook Page ID.
fieldsstringnoComma-separated fields. Defaults to "id,name,category,fan_count,about".

Example

local result = app.integrations.facebook.get_page({
  page_id = "123456789",
  fields = "id,name,fan_count,about,website"
})

print(result.name .. " — " .. result.fan_count .. " followers")

list_posts

List posts published by a Facebook Page.

Parameters

NameTypeRequiredDescription
page_idstringyesThe Facebook Page ID.
fieldsstringnoComma-separated fields per post. Defaults to "id,message,created_time".
limitintegernoMax posts per request.
sincestringnoOnly posts after this timestamp/date.
untilstringnoOnly posts before this timestamp/date.

Example

local result = app.integrations.facebook.list_posts({
  page_id = "123456789",
  fields = "id,message,created_time",
  limit = 10
})

for _, post in ipairs(result.data) do
  print(post.created_time .. ": " .. (post.message or "(no text)"))
end

create_post

Publish a new post on a Facebook Page.

Parameters

NameTypeRequiredDescription
page_idstringyesThe Facebook Page ID.
messagestringyesPost body text.
linkstringnoURL to attach to the post.
scheduled_publish_timestringnoUNIX timestamp for scheduled publishing.

Example

-- Publish immediately
local result = app.integrations.facebook.create_post({
  page_id = "123456789",
  message = "Check out our latest blog post!",
  link = "https://example.com/blog"
})

print("Published post ID: " .. result.id)

-- Schedule for later
local result = app.integrations.facebook.create_post({
  page_id = "123456789",
  message = "Scheduled post content",
  scheduled_publish_time = "1735689600"
})

get_post

Get details for a specific Facebook post.

Parameters

NameTypeRequiredDescription
post_idstringyesThe Facebook Post ID (e.g. "pageId_postId").
fieldsstringnoComma-separated fields. Defaults to "id,message,created_time,attachments".

Example

local result = app.integrations.facebook.get_post({
  post_id = "123456789_987654321",
  fields = "id,message,created_time,attachments,shares"
})

print(result.message)

list_insights

Get engagement and performance metrics for a Facebook Page.

Parameters

NameTypeRequiredDescription
page_idstringyesThe Facebook Page ID.
metricstringnoComma-separated metric names. Omit for all available metrics.
periodstringnoAggregation period: "day", "week", "days_28", "month", "lifetime". Defaults to "day".
sincestringnoStart date (UNIX timestamp or ISO date).
untilstringnoEnd date (UNIX timestamp or ISO date).

Common Metrics

MetricDescription
page_impressionsTotal impressions of the page
page_engaged_usersUsers who engaged with the page
page_post_engagementsEngagements on page posts
page_fansTotal page followers/fans
page_views_totalTotal page views
page_actions_post_reactions_totalReactions on page posts

Example

local result = app.integrations.facebook.list_insights({
  page_id = "123456789",
  metric = "page_impressions,page_engaged_users",
  period = "day",
  since = "2026-01-01",
  until = "2026-01-31"
})

for _, insight in ipairs(result.data) do
  print(insight.name .. ":")
  for _, val in ipairs(insight.values) do
    print("  " .. val.end_time .. " = " .. val.value)
  end
end

get_current_user

Get the authenticated user’s Facebook profile information.

Parameters

NameTypeRequiredDescription
fieldsstringnoComma-separated fields. Defaults to "id,name".

Example

local result = app.integrations.facebook.get_current_user({
  fields = "id,name,picture"
})

print("Authenticated as: " .. result.name .. " (ID: " .. result.id .. ")")

Multi-Account Usage

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

-- Default account (always works)
app.integrations.facebook.list_pages({})

-- Explicit default (portable across setups)
app.integrations.facebook.default.list_pages({})

-- Named accounts
app.integrations.facebook.work.list_pages({})
app.integrations.facebook.client_page.list_pages({})

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

Raw agent markdown
# Facebook — Lua API Reference

## list_pages

List all Facebook Pages the authenticated user manages.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `fields` | string | no | Comma-separated fields (e.g. `"id,name,category,fan_count,about"`). Defaults to `"id,name,category"`. |
| `limit` | integer | no | Max pages per request. |

### Example

```lua
local result = app.integrations.facebook.list_pages({
  fields = "id,name,fan_count,category"
})

for _, page in ipairs(result.data) do
  print(page.name .. " (ID: " .. page.id .. ", Fans: " .. page.fan_count .. ")")
end
```

---

## get_page

Get details for a specific Facebook Page.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `page_id` | string | yes | The Facebook Page ID. |
| `fields` | string | no | Comma-separated fields. Defaults to `"id,name,category,fan_count,about"`. |

### Example

```lua
local result = app.integrations.facebook.get_page({
  page_id = "123456789",
  fields = "id,name,fan_count,about,website"
})

print(result.name .. " — " .. result.fan_count .. " followers")
```

---

## list_posts

List posts published by a Facebook Page.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `page_id` | string | yes | The Facebook Page ID. |
| `fields` | string | no | Comma-separated fields per post. Defaults to `"id,message,created_time"`. |
| `limit` | integer | no | Max posts per request. |
| `since` | string | no | Only posts after this timestamp/date. |
| `until` | string | no | Only posts before this timestamp/date. |

### Example

```lua
local result = app.integrations.facebook.list_posts({
  page_id = "123456789",
  fields = "id,message,created_time",
  limit = 10
})

for _, post in ipairs(result.data) do
  print(post.created_time .. ": " .. (post.message or "(no text)"))
end
```

---

## create_post

Publish a new post on a Facebook Page.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `page_id` | string | yes | The Facebook Page ID. |
| `message` | string | yes | Post body text. |
| `link` | string | no | URL to attach to the post. |
| `scheduled_publish_time` | string | no | UNIX timestamp for scheduled publishing. |

### Example

```lua
-- Publish immediately
local result = app.integrations.facebook.create_post({
  page_id = "123456789",
  message = "Check out our latest blog post!",
  link = "https://example.com/blog"
})

print("Published post ID: " .. result.id)

-- Schedule for later
local result = app.integrations.facebook.create_post({
  page_id = "123456789",
  message = "Scheduled post content",
  scheduled_publish_time = "1735689600"
})
```

---

## get_post

Get details for a specific Facebook post.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `post_id` | string | yes | The Facebook Post ID (e.g. `"pageId_postId"`). |
| `fields` | string | no | Comma-separated fields. Defaults to `"id,message,created_time,attachments"`. |

### Example

```lua
local result = app.integrations.facebook.get_post({
  post_id = "123456789_987654321",
  fields = "id,message,created_time,attachments,shares"
})

print(result.message)
```

---

## list_insights

Get engagement and performance metrics for a Facebook Page.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `page_id` | string | yes | The Facebook Page ID. |
| `metric` | string | no | Comma-separated metric names. Omit for all available metrics. |
| `period` | string | no | Aggregation period: `"day"`, `"week"`, `"days_28"`, `"month"`, `"lifetime"`. Defaults to `"day"`. |
| `since` | string | no | Start date (UNIX timestamp or ISO date). |
| `until` | string | no | End date (UNIX timestamp or ISO date). |

### Common Metrics

| Metric | Description |
|--------|-------------|
| `page_impressions` | Total impressions of the page |
| `page_engaged_users` | Users who engaged with the page |
| `page_post_engagements` | Engagements on page posts |
| `page_fans` | Total page followers/fans |
| `page_views_total` | Total page views |
| `page_actions_post_reactions_total` | Reactions on page posts |

### Example

```lua
local result = app.integrations.facebook.list_insights({
  page_id = "123456789",
  metric = "page_impressions,page_engaged_users",
  period = "day",
  since = "2026-01-01",
  until = "2026-01-31"
})

for _, insight in ipairs(result.data) do
  print(insight.name .. ":")
  for _, val in ipairs(insight.values) do
    print("  " .. val.end_time .. " = " .. val.value)
  end
end
```

---

## get_current_user

Get the authenticated user's Facebook profile information.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `fields` | string | no | Comma-separated fields. Defaults to `"id,name"`. |

### Example

```lua
local result = app.integrations.facebook.get_current_user({
  fields = "id,name,picture"
})

print("Authenticated as: " .. result.name .. " (ID: " .. result.id .. ")")
```

---

## Multi-Account Usage

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

```lua
-- Default account (always works)
app.integrations.facebook.list_pages({})

-- Explicit default (portable across setups)
app.integrations.facebook.default.list_pages({})

-- Named accounts
app.integrations.facebook.work.list_pages({})
app.integrations.facebook.client_page.list_pages({})
```

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

Metadata-Derived Lua Example

local result = app.integrations.facebook.facebook_list_pages({
  fields = "example_fields",
  limit = 1
})
print(result)

Functions

facebook_list_pages

List all Facebook Pages the authenticated user manages. Returns page IDs, names, and access tokens for further operations.

Operation
Read read
Full name
facebook.facebook_list_pages
ParameterTypeRequiredDescription
fields string no Comma-separated list of fields to return per page (e.g. "id,name,category,fan_count,about"). Defaults to "id,name,category".
limit integer no Maximum number of pages to return per request.

facebook_get_page

Get details for a specific Facebook Page by its ID. Returns page name, category, follower count, and other metadata.

Operation
Read read
Full name
facebook.facebook_get_page
ParameterTypeRequiredDescription
page_id string yes The Facebook Page ID.
fields string no Comma-separated list of fields to return (e.g. "id,name,category,fan_count,about,website,phone"). Defaults to "id,name,category,fan_count,about".

facebook_list_posts

List posts published by a Facebook Page. Returns post IDs, messages, creation times, and engagement metrics.

Operation
Read read
Full name
facebook.facebook_list_posts
ParameterTypeRequiredDescription
page_id string yes The Facebook Page ID.
fields string no Comma-separated list of fields to return per post (e.g. "id,message,created_time,attachments,insights"). Defaults to "id,message,created_time".
limit integer no Maximum number of posts to return per request.
since string no Only return posts created after this UNIX timestamp or ISO date.
until string no Only return posts created before this UNIX timestamp or ISO date.

facebook_create_post

Publish a new post on a Facebook Page. The post will appear on the Page's timeline immediately unless scheduled.

Operation
Write write
Full name
facebook.facebook_create_post
ParameterTypeRequiredDescription
page_id string yes The Facebook Page ID to publish the post on.
message string yes The text content of the post.
link string no A URL to attach to the post (e.g. "https://example.com/article").
scheduled_publish_time string no UNIX timestamp to schedule the post for future publication. The post will be saved as a draft until this time.

facebook_get_post

Get details for a specific Facebook post by its ID. Returns the post content, creation time, and engagement metrics.

Operation
Read read
Full name
facebook.facebook_get_post
ParameterTypeRequiredDescription
post_id string yes The Facebook Post ID.
fields string no Comma-separated list of fields to return (e.g. "id,message,created_time,attachments,shares,likes.summary(true)"). Defaults to "id,message,created_time,attachments".

facebook_list_insights

Get engagement and performance metrics (insights) for a Facebook Page. Supports metrics like page_impressions, page_engaged_users, page_post_engagements, and more.

Operation
Read read
Full name
facebook.facebook_list_insights
ParameterTypeRequiredDescription
page_id string yes The Facebook Page ID.
metric string no Comma-separated list of insight metrics to retrieve (e.g. "page_impressions,page_engaged_users,page_post_engagements"). Omit to return all available metrics.
period string no Aggregation period: "day", "week", "days_28", "month", or "lifetime". Defaults to "day".
since string no Start date for the insight data (UNIX timestamp or ISO date).
until string no End date for the insight data (UNIX timestamp or ISO date).

facebook_get_current_user

Get the authenticated user's Facebook profile information, including name and user ID.

Operation
Read read
Full name
facebook.facebook_get_current_user
ParameterTypeRequiredDescription
fields string no Comma-separated list of fields to return (e.g. "id,name,email,picture"). Defaults to "id,name".