> ## 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.

# Plantillas de funciones

> El código real de las plantillas hello, save, ai y access.

Cuatro plantillas listas para empezar. Úsalas desde el panel o pídele a la IA que use `create_function` con `template` = `hello`, `save`, `ai` o `access`. La plantilla `hello` ya viene en cada script nuevo.

## `hello` · Respuesta simple

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

## `save` · Guardar datos

```js theme={null}
// Requiere la colección "items" en 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` · Llamar a la IA

```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` · Verificar acceso

```js theme={null}
// Responde si quien hizo la llamada puede usar el script
function handler(request) {
  const user = doglytdc.user;
  return doglytdc.respond(user ? 200 : 401, { allowed: !!user, user: user && user.username ? "@" + user.username : null });
}
```

> [!NOTE]
>
> La respuesta de `doglytdc.ai.chat` incluye el texto en el campo `text` (y el modelo en `model`). Los scripts creados antes del 06/11/2026 recibieron la plantilla `ai` que leía `r.content`; cámbialo por `r.text` si tu script tiene esa línea.

Para la plantilla `save`, crea también `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.