KosmoKrator

productivity

Google Forms Lua API for KosmoKrator Agents

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

13 functions 5 read 8 write OAuth browser flow auth

Lua Namespace

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

Google Integration — Lua API Supplement

Google services are registered as separate namespaces: integrations.gmail, integrations.google_sheets, integrations.google_calendar, integrations.google_drive, etc. All share the same OAuth credentials.

Gmail

Send email with CC/BCC:

app.integrations.gmail.send_email({
    to = "[email protected]",
    subject = "Q1 Report",
    body = "Please find the report attached.",
    cc = "[email protected], [email protected]",
    bcc = "[email protected]",
})

Search, read, then reply workflow:

-- Step 1: Search for messages
local results = app.integrations.gmail.search_emails({
    query = "from:alice subject:meeting is:unread",
    max_results = 5,
})

-- Step 2: Read the full message
local msg = app.integrations.gmail.read_email({ message_id = results.messages[1].id })

-- Step 3: Reply in the same thread
app.integrations.gmail.reply({
    message_id = msg.id,
    thread_id = msg.threadId,
    body = "Thanks, I'll be there.",
    cc = "[email protected]",
})

Draft vs direct send — use create_draft to stage an email without sending, then send_draft to send it later:

-- Create a draft (not sent)
local draft = app.integrations.gmail.create_draft({
    to = "[email protected]",
    subject = "Proposal",
    body = "Draft content here...",
})

-- Send it later using the draft ID
app.integrations.gmail.send_draft({ draft_id = draft.draftId })

Google Sheets

Values use 2D Lua tables — each inner table is one row:

local values = {
    {"Name", "Age", "City"},
    {"Alice", 30, "NYC"},
    {"Bob", 25, "LA"},
}

A1 notation examples:

  • "Sheet1!A1:D10" — specific range
  • "Sheet1!A:A" — entire column
  • "Sheet1" — entire sheet
  • "'My Sheet'!A1:B2" — sheet names with spaces need quotes

Input modes: "user_entered" (default) parses formulas and dates, "raw" stores literal strings.

Create a spreadsheet, add a sheet, write data:

-- Create a new spreadsheet
local ss = app.integrations.google_sheets.create_spreadsheet({ title = "Q1 Sales" })
local id = ss.spreadsheetId

-- Add a second sheet/tab
app.integrations.google_sheets.add({
    spreadsheet_id = id,
    title = "By Region",
})

-- Write data with headers
app.integrations.google_sheets.write_range({
    spreadsheet_id = id,
    range = "Sheet1!A1:C3",
    values = {
        {"Region", "Revenue", "Growth"},
        {"North", 50000, "=B2/50000-1"},
        {"South", 42000, "=B3/42000-1"},
    },
    input = "user_entered",  -- parses the formulas
})

Read data back:

local data = app.integrations.google_sheets.read_range({
    spreadsheet_id = id,
    range = "Sheet1!A1:C3",
    render = "formatted",  -- "formatted" (default), "unformatted", or "formula"
})
-- data.values is a 2D table: {{"Region","Revenue","Growth"}, {"North","50000","0%"}, ...}

Append vs write — append_rows auto-detects the last row and adds below it:

app.integrations.google_sheets.append_rows({
    spreadsheet_id = id,
    range = "Sheet1",
    values = {
        {"East", 38000, "=B4/38000-1"},
    },
    input = "user_entered",
})

Google Calendar

Create a timed event with attendees:

app.integrations.google_calendar.create_event({
    summary = "Sprint Planning",
    description = "Bi-weekly sprint planning session",
    location = "Conference Room B",
    start_date_time = "2026-04-01T10:00:00-05:00",
    end_date_time = "2026-04-01T11:00:00-05:00",
    time_zone = "America/New_York",
    attendees = "[email protected], [email protected]",
    recurrence = "RRULE:FREQ=WEEKLY;INTERVAL=2;COUNT=10",
})

Create an all-day event:

app.integrations.google_calendar.create_event({
    summary = "Company Holiday",
    start_date = "2026-07-04",
    end_date = "2026-07-05",
})

Date/time format: ISO 8601 with timezone offset for timed events (2026-04-01T10:00:00-05:00), plain YYYY-MM-DD for all-day events. Use time_zone for IANA names like "America/New_York".

Google Drive

Search for files, then get details:

-- Search by name and type
local results = app.integrations.google_drive.search({
    query = "name contains 'report' and mimeType = 'application/vnd.google-apps.spreadsheet'",
    max_results = 10,
    order_by = "modifiedTime desc",
})

-- Get full file info (and optionally export content)
local file = app.integrations.google_drive.get_file({
    file_id = results.files[1].id,
    export_as = "csv",  -- "text", "csv", or "markdown" (Google Workspace files only)
})

Common Drive query patterns:

  • "name contains 'budget'" — by name
  • "mimeType = 'application/vnd.google-apps.spreadsheet'" — Sheets
  • "mimeType = 'application/vnd.google-apps.document'" — Docs
  • "mimeType = 'application/vnd.google-apps.folder'" — folders
  • "modifiedTime > '2026-01-01'" — recently modified
  • "sharedWithMe = true" — shared files
  • "'FOLDER_ID' in parents" — files in a folder

Share a file:

-- Share with a specific user
app.integrations.google_drive.share_file({
    file_id = "abc123",
    role = "writer",       -- "reader", "writer", or "commenter"
    email = "[email protected]",
    notify = "true",
})

-- Share with anyone via link
app.integrations.google_drive.share_file({
    file_id = "abc123",
    role = "reader",
    type = "anyone",
})

Tips

  • All Google APIs share the same OAuth token — if Gmail is connected, the same credentials work for Sheets, Drive, Calendar, etc.
  • Use input = "user_entered" when writing Sheets data that contains formulas (e.g., "=SUM(A1:A10)") or dates. Use "raw" for literal strings.
  • Sheet names with spaces must be quoted in A1 notation: "'My Sheet'!A1:B2".
  • append_rows is better than write_range when adding rows to an existing table — it auto-detects where the data ends.
  • Calendar event times use ISO 8601 with timezone offset. Always include the offset or set time_zone explicitly.
  • Drive search excludes trashed files by default.

Multi-Account Usage

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

-- Default account (always works)
app.integrations.google.function_name({...})

-- Explicit default (portable across setups)
app.integrations.google.default.function_name({...})

-- Named accounts
app.integrations.google.work.function_name({...})
app.integrations.google.personal.function_name({...})

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

Raw agent markdown
# Google Integration — Lua API Supplement

Google services are registered as separate namespaces: `integrations.gmail`, `integrations.google_sheets`, `integrations.google_calendar`, `integrations.google_drive`, etc. All share the same OAuth credentials.

## Gmail

Send email with CC/BCC:

```lua
app.integrations.gmail.send_email({
    to = "[email protected]",
    subject = "Q1 Report",
    body = "Please find the report attached.",
    cc = "[email protected], [email protected]",
    bcc = "[email protected]",
})
```

Search, read, then reply workflow:

```lua
-- Step 1: Search for messages
local results = app.integrations.gmail.search_emails({
    query = "from:alice subject:meeting is:unread",
    max_results = 5,
})

-- Step 2: Read the full message
local msg = app.integrations.gmail.read_email({ message_id = results.messages[1].id })

-- Step 3: Reply in the same thread
app.integrations.gmail.reply({
    message_id = msg.id,
    thread_id = msg.threadId,
    body = "Thanks, I'll be there.",
    cc = "[email protected]",
})
```

Draft vs direct send -- use `create_draft` to stage an email without sending, then `send_draft` to send it later:

```lua
-- Create a draft (not sent)
local draft = app.integrations.gmail.create_draft({
    to = "[email protected]",
    subject = "Proposal",
    body = "Draft content here...",
})

-- Send it later using the draft ID
app.integrations.gmail.send_draft({ draft_id = draft.draftId })
```

## Google Sheets

Values use 2D Lua tables -- each inner table is one row:

```lua
local values = {
    {"Name", "Age", "City"},
    {"Alice", 30, "NYC"},
    {"Bob", 25, "LA"},
}
```

A1 notation examples:

- `"Sheet1!A1:D10"` -- specific range
- `"Sheet1!A:A"` -- entire column
- `"Sheet1"` -- entire sheet
- `"'My Sheet'!A1:B2"` -- sheet names with spaces need quotes

Input modes: `"user_entered"` (default) parses formulas and dates, `"raw"` stores literal strings.

Create a spreadsheet, add a sheet, write data:

```lua
-- Create a new spreadsheet
local ss = app.integrations.google_sheets.create_spreadsheet({ title = "Q1 Sales" })
local id = ss.spreadsheetId

-- Add a second sheet/tab
app.integrations.google_sheets.add({
    spreadsheet_id = id,
    title = "By Region",
})

-- Write data with headers
app.integrations.google_sheets.write_range({
    spreadsheet_id = id,
    range = "Sheet1!A1:C3",
    values = {
        {"Region", "Revenue", "Growth"},
        {"North", 50000, "=B2/50000-1"},
        {"South", 42000, "=B3/42000-1"},
    },
    input = "user_entered",  -- parses the formulas
})
```

Read data back:

```lua
local data = app.integrations.google_sheets.read_range({
    spreadsheet_id = id,
    range = "Sheet1!A1:C3",
    render = "formatted",  -- "formatted" (default), "unformatted", or "formula"
})
-- data.values is a 2D table: {{"Region","Revenue","Growth"}, {"North","50000","0%"}, ...}
```

Append vs write -- `append_rows` auto-detects the last row and adds below it:

```lua
app.integrations.google_sheets.append_rows({
    spreadsheet_id = id,
    range = "Sheet1",
    values = {
        {"East", 38000, "=B4/38000-1"},
    },
    input = "user_entered",
})
```

## Google Calendar

Create a timed event with attendees:

```lua
app.integrations.google_calendar.create_event({
    summary = "Sprint Planning",
    description = "Bi-weekly sprint planning session",
    location = "Conference Room B",
    start_date_time = "2026-04-01T10:00:00-05:00",
    end_date_time = "2026-04-01T11:00:00-05:00",
    time_zone = "America/New_York",
    attendees = "[email protected], [email protected]",
    recurrence = "RRULE:FREQ=WEEKLY;INTERVAL=2;COUNT=10",
})
```

Create an all-day event:

```lua
app.integrations.google_calendar.create_event({
    summary = "Company Holiday",
    start_date = "2026-07-04",
    end_date = "2026-07-05",
})
```

Date/time format: ISO 8601 with timezone offset for timed events (`2026-04-01T10:00:00-05:00`), plain `YYYY-MM-DD` for all-day events. Use `time_zone` for IANA names like `"America/New_York"`.

## Google Drive

Search for files, then get details:

```lua
-- Search by name and type
local results = app.integrations.google_drive.search({
    query = "name contains 'report' and mimeType = 'application/vnd.google-apps.spreadsheet'",
    max_results = 10,
    order_by = "modifiedTime desc",
})

-- Get full file info (and optionally export content)
local file = app.integrations.google_drive.get_file({
    file_id = results.files[1].id,
    export_as = "csv",  -- "text", "csv", or "markdown" (Google Workspace files only)
})
```

Common Drive query patterns:

- `"name contains 'budget'"` -- by name
- `"mimeType = 'application/vnd.google-apps.spreadsheet'"` -- Sheets
- `"mimeType = 'application/vnd.google-apps.document'"` -- Docs
- `"mimeType = 'application/vnd.google-apps.folder'"` -- folders
- `"modifiedTime > '2026-01-01'"` -- recently modified
- `"sharedWithMe = true"` -- shared files
- `"'FOLDER_ID' in parents"` -- files in a folder

Share a file:

```lua
-- Share with a specific user
app.integrations.google_drive.share_file({
    file_id = "abc123",
    role = "writer",       -- "reader", "writer", or "commenter"
    email = "[email protected]",
    notify = "true",
})

-- Share with anyone via link
app.integrations.google_drive.share_file({
    file_id = "abc123",
    role = "reader",
    type = "anyone",
})
```

## Tips

- All Google APIs share the same OAuth token -- if Gmail is connected, the same credentials work for Sheets, Drive, Calendar, etc.
- Use `input = "user_entered"` when writing Sheets data that contains formulas (e.g., `"=SUM(A1:A10)"`) or dates. Use `"raw"` for literal strings.
- Sheet names with spaces must be quoted in A1 notation: `"'My Sheet'!A1:B2"`.
- `append_rows` is better than `write_range` when adding rows to an existing table -- it auto-detects where the data ends.
- Calendar event times use ISO 8601 with timezone offset. Always include the offset or set `time_zone` explicitly.
- Drive search excludes trashed files by default.

---

## Multi-Account Usage

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

```lua
-- Default account (always works)
app.integrations.google.function_name({...})

-- Explicit default (portable across setups)
app.integrations.google.default.function_name({...})

-- Named accounts
app.integrations.google.work.function_name({...})
app.integrations.google.personal.function_name({...})
```

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

Metadata-Derived Lua Example

local result = app.integrations.google_forms.google_forms_add_question({
  form_id = "example_form_id",
  title = "example_title",
  type = "example_type",
  required = true,
  description = "example_description",
  options = "example_options",
  low = 1,
  high = 1
})
print(result)

Functions

google_forms_add_question

Add a question to a Google Form. Supports types: text, paragraph, multiple_choice, checkbox, dropdown, scale, date, time, rating. Use options for choice types. Use low/high/lowLabel/highLabel for scale. Use ratingScale/ratingIcon for rating. Use includeTime/includeYear for date. Use duration for time. Omit index to add at end. Use google_forms_get to see current form structure before editing.

Operation
Write write
Full name
google_forms.google_forms_add_question
ParameterTypeRequiredDescription
form_id string yes Google Forms form ID.
title string yes Question title text.
type string yes Question type: text, paragraph, multiple_choice, checkbox, dropdown, scale, date, time, or rating.
required boolean no Whether the question is required (default false).
description string no Help text / description for the question.
options array no Array of option strings (for multiple_choice, checkbox, dropdown).
low integer no For scale: low value (default 1).
high integer no For scale: high value (default 5).
low_label string no For scale: label for the low end.
high_label string no For scale: label for the high end.
rating_scale integer no For rating: scale level 3-10 (default 5).
rating_icon string no For rating: STAR (default), HEART, or THUMB_UP.
include_time boolean no For date: include time (default false).
include_year boolean no For date: include year (default true).
duration boolean no For time: duration mode instead of time-of-day (default false).
index integer no Insert position (0-based). Omit to add at end.

google_forms_add_section

Add a page break / section to a Google Form. Omit index to add at end. Use google_forms_get to see current form structure.

Operation
Write write
Full name
google_forms.google_forms_add_section
ParameterTypeRequiredDescription
form_id string yes Google Forms form ID.
title string yes Title of the section.
description string no Description of the section.
index integer no Insert position (0-based). Omit to add at end.

google_forms_add_text_item

Add a static text block to a Google Form. Omit index to add at end. Use google_forms_get to see current form structure.

Operation
Write write
Full name
google_forms.google_forms_add_text_item
ParameterTypeRequiredDescription
form_id string yes Google Forms form ID.
title string yes Title of the text item.
description string no Body text / description.
index integer no Insert position (0-based). Omit to add at end.

google_forms_create

Create a new Google Form with a title, optional description, and optional quiz mode. Auto-publishes. Returns form ID, edit URL, and responder URL.

Operation
Read read
Full name
google_forms.google_forms_create
ParameterTypeRequiredDescription
title string yes Title of the new form.
description string no Description of the form.
is_quiz boolean no Enable quiz mode (default false).

google_forms_delete_item

Delete an item from a Google Form by its 0-based index. Use google_forms_get to see current form structure.

Operation
Write write
Full name
google_forms.google_forms_delete_item
ParameterTypeRequiredDescription
form_id string yes Google Forms form ID.
index integer yes 0-based position of the item to delete.

google_forms_get

Get a Google Form's structure: title, description, settings, all questions with types/options/IDs, and responder URL. The form ID is the long string in the Google Forms URL: docs.google.com/forms/d/{formId}/edit To list all forms, use google_drive_search with file type "application/vnd.google-apps.form".

Operation
Read read
Full name
google_forms.google_forms_get
ParameterTypeRequiredDescription
form_id string yes Google Forms form ID (from the URL).

google_forms_get_response

Get a single response to a Google Form by response ID, with question labels. The form ID is the long string in the Google Forms URL: docs.google.com/forms/d/{formId}/edit

Operation
Read read
Full name
google_forms.google_forms_get_response
ParameterTypeRequiredDescription
form_id string yes Google Forms form ID (from the URL).
response_id string yes Response ID.

google_forms_list_responses

List responses to a Google Form with question labels. The form ID is the long string in the Google Forms URL: docs.google.com/forms/d/{formId}/edit

Operation
Read read
Full name
google_forms.google_forms_list_responses
ParameterTypeRequiredDescription
form_id string yes Google Forms form ID (from the URL).
after string no Only responses after this timestamp (RFC3339).
page_size integer no Max responses per page (default 10, max 5000).
page_token string no Pagination token from previous response.

google_forms_move_item

Move an item in a Google Form from one 0-based index to another. Use google_forms_get to see current form structure.

Operation
Write write
Full name
google_forms.google_forms_move_item
ParameterTypeRequiredDescription
form_id string yes Google Forms form ID.
from integer yes Current item index (0-based).
to integer yes Target index (0-based).

google_forms_publish

Set publish settings for a Google Form: publish/unpublish and accept/stop accepting responses. At least one of published or acceptingResponses must be provided.

Operation
Read read
Full name
google_forms.google_forms_publish
ParameterTypeRequiredDescription
form_id string yes Google Forms form ID.
published boolean no Publish or unpublish the form.
accepting_responses boolean no Accept or stop accepting responses.

google_forms_update_info

Update a Google Form title and/or description. At least one of title or description must be provided.

Operation
Write write
Full name
google_forms.google_forms_update_info
ParameterTypeRequiredDescription
form_id string yes Google Forms form ID.
title string no New title for the form.
description string no New description for the form.

google_forms_update_question

Update a question in a Google Form by its 0-based index. Can update title, description, required status, and options (for choice questions). Use google_forms_get to see current form structure.

Operation
Write write
Full name
google_forms.google_forms_update_question
ParameterTypeRequiredDescription
form_id string yes Google Forms form ID.
index integer yes 0-based item position of the question to update.
title string no New title for the question.
description string no New description/help text for the question.
required boolean no Whether the question is required.
options array no New options array (for choice questions: multiple_choice, checkbox, dropdown).

google_forms_update_settings

Update Google Form settings such as quiz mode and email collection. At least one setting must be provided.

Operation
Write write
Full name
google_forms.google_forms_update_settings
ParameterTypeRequiredDescription
form_id string yes Google Forms form ID.
is_quiz boolean no Enable or disable quiz mode.
email_collection string no Email collection: DO_NOT_COLLECT, VERIFIED, or RESPONDER_INPUT.