KosmoKrator

communication

WhatsApp Business Lua API for KosmoKrator Agents

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

6 functions 4 read 2 write Bearer token auth

Lua Namespace

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

WhatsApp Business — Lua API Reference

send_message

Send a text message to a WhatsApp recipient. Use this for replying within an existing 24-hour customer service window. For new conversations, use send_template instead.

Parameters

NameTypeRequiredDescription
tostringyesRecipient phone number in international format without + (e.g. "15551234567")
bodystringyesText content of the message (max 4096 characters)
preview_urlbooleannoWhether to render URLs as link previews (default: false)

Examples

-- Send a simple text message
local result = app.integrations.whatsapp.send_message({
  to = "15551234567",
  body = "Hello! Your order has been shipped."
})

print("Message ID: " .. result.messages[1].id)
-- Send with link preview
local result = app.integrations.whatsapp.send_message({
  to = "15551234567",
  body = "Check out our docs: https://example.com/docs",
  preview_url = true
})

get_message

Retrieve a specific WhatsApp message by its ID. Returns the message content, status (sent, delivered, read), and timestamps.

Parameters

NameTypeRequiredDescription
message_idstringyesThe WhatsApp message ID (e.g. "wamid.HBgM...")

Examples

local result = app.integrations.whatsapp.get_message({
  message_id = "wamid.HBgM..."
})

print("Status: " .. result.messages[1].message_status)

list_templates

List approved WhatsApp message templates. Templates are required to initiate new conversations outside the 24-hour service window.

Parameters

NameTypeRequiredDescription
limitintegernoMaximum number of templates to return (default: 100)
afterstringnoCursor for pagination — pass the value from a previous response to get the next page

Examples

local result = app.integrations.whatsapp.list_templates({
  limit = 50
})

for _, tmpl in ipairs(result.data) do
  print(tmpl.name .. " (" .. tmpl.status .. ")")
end
-- Paginate through templates
local page = app.integrations.whatsapp.list_templates({ limit = 10 })
local cursor = page.paging and page.paging.cursors and page.paging.cursors.after or nil

if cursor then
  local next_page = app.integrations.whatsapp.list_templates({ limit = 10, after = cursor })
end

list_contacts

List WhatsApp contacts for the business phone number. Returns WhatsApp IDs and profile names.

Parameters

NameTypeRequiredDescription
limitintegernoMaximum number of contacts to return (default: 100)
afterstringnoCursor for pagination — pass the value from a previous response to get the next page

Examples

local result = app.integrations.whatsapp.list_contacts({})

for _, contact in ipairs(result.data) do
  print(contact.wa_id .. ": " .. (contact.profile_name or "Unknown"))
end

send_template

Send a template-based WhatsApp message. Use this to initiate new conversations outside the 24-hour window. The template must be pre-approved in the WhatsApp Business Manager.

Parameters

NameTypeRequiredDescription
tostringyesRecipient phone number in international format without +
template_namestringyesName of the approved template (e.g. "hello_world")
languagestringnoLanguage code (e.g. "en_US", "en"). Defaults to "en"
componentsarraynoTemplate components — array of objects with type and parameters

Component Structure

[
  {
    "type": "body",
    "parameters": [
      { "type": "text", "text": "John" }
    ]
  }
]

Examples

-- Send the built-in hello_world template
local result = app.integrations.whatsapp.send_template({
  to = "15551234567",
  template_name = "hello_world",
  language = "en_US"
})

print("Message ID: " .. result.messages[1].id)
-- Send a template with dynamic body parameters
local result = app.integrations.whatsapp.send_template({
  to = "15551234567",
  template_name = "order_update",
  language = "en",
  components = {
    {
      type = "body",
      parameters = {
        { type = "text", text = "Order #12345" },
        { type = "text", text = "shipped" }
      }
    }
  }
})

get_current_user

Get the authenticated WhatsApp Business user info — name, email, and business ID. Useful for verifying which account is connected.

Parameters

None.

Examples

local result = app.integrations.whatsapp.get_current_user({})

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

Multi-Account Usage

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

-- Default account (always works)
app.integrations.whatsapp.send_message({ to = "15551234567", body = "Hello" })

-- Explicit default (portable across setups)
app.integrations.whatsapp.default.send_message({ to = "15551234567", body = "Hello" })

-- Named accounts
app.integrations.whatsapp.support.send_message({ to = "15551234567", body = "Hello" })
app.integrations.whatsapp.sales.send_template({ to = "15551234567", template_name = "hello_world" })

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

Raw agent markdown
# WhatsApp Business — Lua API Reference

## send_message

Send a text message to a WhatsApp recipient. Use this for replying within an existing 24-hour customer service window. For new conversations, use `send_template` instead.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `to` | string | yes | Recipient phone number in international format without + (e.g. `"15551234567"`) |
| `body` | string | yes | Text content of the message (max 4096 characters) |
| `preview_url` | boolean | no | Whether to render URLs as link previews (default: `false`) |

### Examples

```lua
-- Send a simple text message
local result = app.integrations.whatsapp.send_message({
  to = "15551234567",
  body = "Hello! Your order has been shipped."
})

print("Message ID: " .. result.messages[1].id)
```

```lua
-- Send with link preview
local result = app.integrations.whatsapp.send_message({
  to = "15551234567",
  body = "Check out our docs: https://example.com/docs",
  preview_url = true
})
```

---

## get_message

Retrieve a specific WhatsApp message by its ID. Returns the message content, status (sent, delivered, read), and timestamps.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `message_id` | string | yes | The WhatsApp message ID (e.g. `"wamid.HBgM..."`) |

### Examples

```lua
local result = app.integrations.whatsapp.get_message({
  message_id = "wamid.HBgM..."
})

print("Status: " .. result.messages[1].message_status)
```

---

## list_templates

List approved WhatsApp message templates. Templates are required to initiate new conversations outside the 24-hour service window.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `limit` | integer | no | Maximum number of templates to return (default: 100) |
| `after` | string | no | Cursor for pagination — pass the value from a previous response to get the next page |

### Examples

```lua
local result = app.integrations.whatsapp.list_templates({
  limit = 50
})

for _, tmpl in ipairs(result.data) do
  print(tmpl.name .. " (" .. tmpl.status .. ")")
end
```

```lua
-- Paginate through templates
local page = app.integrations.whatsapp.list_templates({ limit = 10 })
local cursor = page.paging and page.paging.cursors and page.paging.cursors.after or nil

if cursor then
  local next_page = app.integrations.whatsapp.list_templates({ limit = 10, after = cursor })
end
```

---

## list_contacts

List WhatsApp contacts for the business phone number. Returns WhatsApp IDs and profile names.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `limit` | integer | no | Maximum number of contacts to return (default: 100) |
| `after` | string | no | Cursor for pagination — pass the value from a previous response to get the next page |

### Examples

```lua
local result = app.integrations.whatsapp.list_contacts({})

for _, contact in ipairs(result.data) do
  print(contact.wa_id .. ": " .. (contact.profile_name or "Unknown"))
end
```

---

## send_template

Send a template-based WhatsApp message. Use this to initiate new conversations outside the 24-hour window. The template must be pre-approved in the WhatsApp Business Manager.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `to` | string | yes | Recipient phone number in international format without + |
| `template_name` | string | yes | Name of the approved template (e.g. `"hello_world"`) |
| `language` | string | no | Language code (e.g. `"en_US"`, `"en"`). Defaults to `"en"` |
| `components` | array | no | Template components — array of objects with `type` and parameters |

### Component Structure

```json
[
  {
    "type": "body",
    "parameters": [
      { "type": "text", "text": "John" }
    ]
  }
]
```

### Examples

```lua
-- Send the built-in hello_world template
local result = app.integrations.whatsapp.send_template({
  to = "15551234567",
  template_name = "hello_world",
  language = "en_US"
})

print("Message ID: " .. result.messages[1].id)
```

```lua
-- Send a template with dynamic body parameters
local result = app.integrations.whatsapp.send_template({
  to = "15551234567",
  template_name = "order_update",
  language = "en",
  components = {
    {
      type = "body",
      parameters = {
        { type = "text", text = "Order #12345" },
        { type = "text", text = "shipped" }
      }
    }
  }
})
```

---

## get_current_user

Get the authenticated WhatsApp Business user info — name, email, and business ID. Useful for verifying which account is connected.

### Parameters

None.

### Examples

```lua
local result = app.integrations.whatsapp.get_current_user({})

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

---

## Multi-Account Usage

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

```lua
-- Default account (always works)
app.integrations.whatsapp.send_message({ to = "15551234567", body = "Hello" })

-- Explicit default (portable across setups)
app.integrations.whatsapp.default.send_message({ to = "15551234567", body = "Hello" })

-- Named accounts
app.integrations.whatsapp.support.send_message({ to = "15551234567", body = "Hello" })
app.integrations.whatsapp.sales.send_template({ to = "15551234567", template_name = "hello_world" })
```

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

Metadata-Derived Lua Example

local result = app.integrations.whatsapp.whatsapp_send_message({
  to = "example_to",
  body = "example_body",
  preview_url = true
})
print(result)

Functions

whatsapp_send_message

Send a text message to a WhatsApp recipient. Use this for replying within an existing 24-hour customer service window. For new conversations, use the send_template tool instead.

Operation
Write write
Full name
whatsapp.whatsapp_send_message
ParameterTypeRequiredDescription
to string yes Recipient phone number in international format without + (e.g. "15551234567").
body string yes Text content of the message (max 4096 characters).
preview_url boolean no Whether to render URLs as link previews in the message (default: false).

whatsapp_get_message

Retrieve a specific WhatsApp message by its ID. Returns the message content, status (sent, delivered, read), and timestamps.

Operation
Read read
Full name
whatsapp.whatsapp_get_message
ParameterTypeRequiredDescription
message_id string yes The WhatsApp message ID (e.g. "wamid.HBgM...").

whatsapp_list_templates

List approved WhatsApp message templates. Templates are required to initiate new conversations outside the 24-hour service window.

Operation
Read read
Full name
whatsapp.whatsapp_list_templates
ParameterTypeRequiredDescription
limit integer no Maximum number of templates to return (default: 100).
after string no Cursor for pagination — pass the value from a previous response to get the next page.

whatsapp_list_contacts

List WhatsApp contacts for the business phone number. Returns WhatsApp IDs and profile names.

Operation
Read read
Full name
whatsapp.whatsapp_list_contacts
ParameterTypeRequiredDescription
limit integer no Maximum number of contacts to return (default: 100).
after string no Cursor for pagination — pass the value from a previous response to get the next page.

whatsapp_send_template

Send a template-based WhatsApp message. Use this to initiate new conversations outside the 24-hour window. The template must be pre-approved in the WhatsApp Business Manager.

Operation
Write write
Full name
whatsapp.whatsapp_send_template
ParameterTypeRequiredDescription
to string yes Recipient phone number in international format without + (e.g. "15551234567").
template_name string yes Name of the approved WhatsApp template (e.g. "hello_world").
language string no Language code for the template (e.g. "en_US", "en"). Defaults to "en".
components array no Template components — an array of objects with "type" (header, body, button) and corresponding parameters. Pass as a JSON string or array.

whatsapp_get_current_user

Get the authenticated WhatsApp Business user info — name, email, and business ID. Useful for verifying which account is connected.

Operation
Read read
Full name
whatsapp.whatsapp_get_current_user
ParameterTypeRequiredDescription
No parameters.