> ## Documentation Index
> Fetch the complete documentation index at: https://docs.doglytdc.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Function templates

> The actual code for the hello, save, ai, and access templates.

Four ready-to-use templates to get started. Use them through the dashboard, or ask the AI to use `create_function` with `template` = `hello`, `save`, `ai`, or `access`. The `hello` template is included in every new script.

## `hello` · Simple response

```js theme={null}
function handler(request) {
  return doglytdc.respond(200, { ok: true, message: "Olá do DoglyTdc", method: request.method });
}
```

## `save` · Save data

```js theme={null}
// Requires the "items" collection in supabase/collections.json
function handler(request) {
  const body = request.body || {};
  const doc = doglytdc.db.collection("items").insert({ text: String(body.text || "").slice(0, 500) });
  return doglytdc.respond(201, doc);
}
```

## `ai` · Call AI

```js theme={null}
function handler(request) {
  const q = String((request.body || {}).prompt || "").slice(0, 2000);
  if (!q) return doglytdc.respond(400, { error: "envie prompt" });
  const r = doglytdc.ai.chat([{ role: "user", content: q }]);
  return doglytdc.respond(200, { answer: r.text });
}
```

## `access` · Check access

```js theme={null}
// Reports whether the caller can use the script
function handler(request) {
  const user = doglytdc.user;
  return doglytdc.respond(user ? 200 : 401, { allowed: !!user, user: user && user.username ? "@" + user.username : null });
}
```

> [!NOTE]
>
> The `doglytdc.ai.chat` response contains the text in the `text` field (and the model in `model`). Scripts created before November 6, 2026 received the `ai` template reading `r.content`; replace it with `r.text` if your script has that line.

For the `save` template, also create `supabase/collections.json`:

```json theme={null}
{
  "collections": {
    "items": { "read": "users", "write": "users" }
  }
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.