KosmoKrator

communication

OneSignal Lua API for KosmoKrator Agents

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

7 functions 6 read 1 write API key auth

Lua Namespace

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

OneSignal — Lua API Reference

list_notifications

List push notifications sent through OneSignal.

Parameters

NameTypeRequiredDescription
app_idstringyesOneSignal app ID
limitintegernoMax notifications to return (default: 50, max: 50)
offsetintegernoPagination offset (default: 0)

Example

local result = app.integrations["one-signal"].list_notifications({
  app_id = "12345678-abcd-efgh-ijkl-1234567890ab",
  limit = 10,
  offset = 0
})

for _, notif in ipairs(result.notifications) do
  print(notif.id .. ": " .. (notif.headings and notif.headings.en or "No title"))
end

get_notification

Get details of a specific push notification by ID.

Parameters

NameTypeRequiredDescription
idstringyesNotification ID
app_idstringyesOneSignal app ID

Example

local result = app.integrations["one-signal"].get_notification({
  id = "notif-abc-123",
  app_id = "12345678-abcd-efgh-ijkl-1234567890ab"
})

print("Successful: " .. result.successful .. " / " .. result.recipients)

create_notification

Send a new push notification via OneSignal.

Parameters

NameTypeRequiredDescription
app_idstringyesOneSignal app ID
contentsobjectyesMessage body per language, e.g. {"en": "Hello!"}
headingsobjectnoTitle per language, e.g. {"en": "Update"}
included_segmentsarraynoTarget segments, e.g. {"All", "Active Users"}
urlstringnoURL to open on notification tap
dataobjectnoCustom data payload delivered to the app

Example

local result = app.integrations["one-signal"].create_notification({
  app_id = "12345678-abcd-efgh-ijkl-1234567890ab",
  contents = { en = "Check out our latest update!" },
  headings = { en = "New Feature" },
  included_segments = { "All" },
  url = "https://example.com/updates",
  data = { type = "feature_update", id = 42 }
})

print("Notification sent! ID: " .. result.id)
print("Recipients: " .. result.recipients)

list_devices

List devices (players) registered in a OneSignal app.

Parameters

NameTypeRequiredDescription
app_idstringyesOneSignal app ID
limitintegernoMax devices to return (default: 50, max: 300)
offsetintegernoPagination offset (default: 0)

Example

local result = app.integrations["one-signal"].list_devices({
  app_id = "12345678-abcd-efgh-ijkl-1234567890ab",
  limit = 10
})

for _, device in ipairs(result.players) do
  print(device.id .. ": " .. device.device_type .. " sessions=" .. device.session_count)
end

get_device

Get details of a specific device (player) by ID.

Parameters

NameTypeRequiredDescription
idstringyesDevice/player ID
app_idstringyesOneSignal app ID

Example

local result = app.integrations["one-signal"].get_device({
  id = "player-xyz-789",
  app_id = "12345678-abcd-efgh-ijkl-1234567890ab"
})

print("Platform: " .. result.device_type)
print("Sessions: " .. result.session_count)
print("Tags: " .. json.stringify(result.tags or {}))

list_apps

List all OneSignal apps accessible with the configured API key.

Parameters

None.

Example

local result = app.integrations["one-signal"].list_apps()

for _, app in ipairs(result) do
  print(app.name .. " (" .. app.id .. ") — " .. app.players .. " players")
end

get_current_app

Get details of a specific OneSignal app by ID.

Parameters

NameTypeRequiredDescription
app_idstringyesOneSignal app ID

Example

local result = app.integrations["one-signal"].get_current_app({
  app_id = "12345678-abcd-efgh-ijkl-1234567890ab"
})

print("App: " .. result.name)
print("Site: " .. result.site_name)
print("Players: " .. result.players)

Multi-Account Usage

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

-- Default account (always works)
app.integrations["one-signal"].function_name({...})

-- Explicit default (portable across setups)
app.integrations["one-signal"].default.function_name({...})

-- Named accounts
app.integrations["one-signal"].production.function_name({...})
app.integrations["one-signal"].staging.function_name({...})

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

Raw agent markdown
# OneSignal — Lua API Reference

## list_notifications

List push notifications sent through OneSignal.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `app_id` | string | yes | OneSignal app ID |
| `limit` | integer | no | Max notifications to return (default: 50, max: 50) |
| `offset` | integer | no | Pagination offset (default: 0) |

### Example

```lua
local result = app.integrations["one-signal"].list_notifications({
  app_id = "12345678-abcd-efgh-ijkl-1234567890ab",
  limit = 10,
  offset = 0
})

for _, notif in ipairs(result.notifications) do
  print(notif.id .. ": " .. (notif.headings and notif.headings.en or "No title"))
end
```

---

## get_notification

Get details of a specific push notification by ID.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `id` | string | yes | Notification ID |
| `app_id` | string | yes | OneSignal app ID |

### Example

```lua
local result = app.integrations["one-signal"].get_notification({
  id = "notif-abc-123",
  app_id = "12345678-abcd-efgh-ijkl-1234567890ab"
})

print("Successful: " .. result.successful .. " / " .. result.recipients)
```

---

## create_notification

Send a new push notification via OneSignal.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `app_id` | string | yes | OneSignal app ID |
| `contents` | object | yes | Message body per language, e.g. `{"en": "Hello!"}` |
| `headings` | object | no | Title per language, e.g. `{"en": "Update"}` |
| `included_segments` | array | no | Target segments, e.g. `{"All", "Active Users"}` |
| `url` | string | no | URL to open on notification tap |
| `data` | object | no | Custom data payload delivered to the app |

### Example

```lua
local result = app.integrations["one-signal"].create_notification({
  app_id = "12345678-abcd-efgh-ijkl-1234567890ab",
  contents = { en = "Check out our latest update!" },
  headings = { en = "New Feature" },
  included_segments = { "All" },
  url = "https://example.com/updates",
  data = { type = "feature_update", id = 42 }
})

print("Notification sent! ID: " .. result.id)
print("Recipients: " .. result.recipients)
```

---

## list_devices

List devices (players) registered in a OneSignal app.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `app_id` | string | yes | OneSignal app ID |
| `limit` | integer | no | Max devices to return (default: 50, max: 300) |
| `offset` | integer | no | Pagination offset (default: 0) |

### Example

```lua
local result = app.integrations["one-signal"].list_devices({
  app_id = "12345678-abcd-efgh-ijkl-1234567890ab",
  limit = 10
})

for _, device in ipairs(result.players) do
  print(device.id .. ": " .. device.device_type .. " sessions=" .. device.session_count)
end
```

---

## get_device

Get details of a specific device (player) by ID.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `id` | string | yes | Device/player ID |
| `app_id` | string | yes | OneSignal app ID |

### Example

```lua
local result = app.integrations["one-signal"].get_device({
  id = "player-xyz-789",
  app_id = "12345678-abcd-efgh-ijkl-1234567890ab"
})

print("Platform: " .. result.device_type)
print("Sessions: " .. result.session_count)
print("Tags: " .. json.stringify(result.tags or {}))
```

---

## list_apps

List all OneSignal apps accessible with the configured API key.

### Parameters

None.

### Example

```lua
local result = app.integrations["one-signal"].list_apps()

for _, app in ipairs(result) do
  print(app.name .. " (" .. app.id .. ") — " .. app.players .. " players")
end
```

---

## get_current_app

Get details of a specific OneSignal app by ID.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `app_id` | string | yes | OneSignal app ID |

### Example

```lua
local result = app.integrations["one-signal"].get_current_app({
  app_id = "12345678-abcd-efgh-ijkl-1234567890ab"
})

print("App: " .. result.name)
print("Site: " .. result.site_name)
print("Players: " .. result.players)
```

---

## Multi-Account Usage

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

```lua
-- Default account (always works)
app.integrations["one-signal"].function_name({...})

-- Explicit default (portable across setups)
app.integrations["one-signal"].default.function_name({...})

-- Named accounts
app.integrations["one-signal"].production.function_name({...})
app.integrations["one-signal"].staging.function_name({...})
```

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

Metadata-Derived Lua Example

local result = app.integrations.one_signal.onesignal_list_notifications({
  app_id = "example_app_id",
  limit = 1,
  offset = 1
})
print(result)

Functions

onesignal_list_notifications

List push notifications sent through OneSignal. Returns notification details including delivery stats, click counts, and outcomes. Use limit and offset for pagination.

Operation
Read read
Full name
one-signal.onesignal_list_notifications
ParameterTypeRequiredDescription
app_id string yes The OneSignal app ID to list notifications for.
limit integer no Maximum number of notifications to return (default: 50, max: 50).
offset integer no Offset for pagination (default: 0).

onesignal_get_notification

Get details of a specific OneSignal push notification by its ID. Returns full notification data including content, delivery stats, and targeting.

Operation
Read read
Full name
one-signal.onesignal_get_notification
ParameterTypeRequiredDescription
id string yes The notification ID to retrieve.
app_id string yes The OneSignal app ID the notification belongs to.

onesignal_create_notification

Send a new push notification via OneSignal. Specify message contents (per language), optional headings, target segments, a click URL, and a custom data payload.

Operation
Write write
Full name
one-signal.onesignal_create_notification
ParameterTypeRequiredDescription
app_id string yes The OneSignal app ID to send the notification from.
contents object yes Notification body per language, e.g. {"en": "Hello!", "es": "¡Hola!"}. The "en" key is required.
headings object no Notification title per language, e.g. {"en": "Update"}. Defaults to the app name if omitted.
included_segments array no Segments to target, e.g. ["All", "Active Users"]. Defaults to ["All"] if omitted.
url string no URL to open when the notification is tapped.
data object no Custom key-value data payload delivered to the app when the notification is opened.

onesignal_list_devices

List devices (players) registered in a OneSignal app. Returns device identifiers, platform, session counts, and tags. Use limit and offset for pagination.

Operation
Read read
Full name
one-signal.onesignal_list_devices
ParameterTypeRequiredDescription
app_id string yes The OneSignal app ID to list devices for.
limit integer no Maximum number of devices to return (default: 50, max: 300).
offset integer no Offset for pagination (default: 0).

onesignal_get_device

Get details of a specific OneSignal device (player) by its ID. Returns push token, platform, session data, tags, and more.

Operation
Read read
Full name
one-signal.onesignal_get_device
ParameterTypeRequiredDescription
id string yes The device/player ID to retrieve.
app_id string yes The OneSignal app ID the device belongs to.

onesignal_list_apps

List all OneSignal apps accessible with the configured REST API key. Returns app names, IDs, player counts, and configuration.

Operation
Read read
Full name
one-signal.onesignal_list_apps
ParameterTypeRequiredDescription
No parameters.

onesignal_get_current_app

Get details of a specific OneSignal app by its ID. Returns app configuration, player counts, and platform settings.

Operation
Read read
Full name
one-signal.onesignal_get_current_app
ParameterTypeRequiredDescription
app_id string yes The OneSignal app ID to retrieve.