A common shape: many users see each other live, everyone's posts persist, and something posts on a timer (an AI commenter, a digest, a heartbeat). This wires the four pieces end-to-end so you don't have to assemble them from four separate skills; each links to its full reference.

The pieces:

  1. Realtime for live presence, plus a channel new posts arrive on (app-realtime).
  2. A function + database so posts persist, and the function pushes each new post into the room with realtime.publish() (app-development, app-function-services).
  3. A scheduled workflow that calls a function on a cron to post automatically (workflow).
  4. Deploy that provisions all of it from gipity.yaml (deploy).

Start from gipity add web-fullstack (it loads the Gipity.fn client SDK and ships the database and functions phases), then gipity add realtime (the kit, plus a realtime phase in gipity.yaml).

1. Realtime: presence + a server-fed posts channel

Build on the @gipity/realtime kit - don't hand-roll the client. A presence channel shows who's here; a messages channel (the default sync) receives each new post. Only functions publish on posts (it is a server_channels entry, step 4), so every post, a person's or the scheduler's, arrives the same way:

import { createRealtime } from '@gipity/realtime';

const rt = createRealtime({ room: 'feed' });      // a provisioned room name (step 4)
const here = rt.channel('presence', { sync: 'presence' });
here.setLocal({ name: myName });                   // rebroadcast ~20 Hz until changed
const renderPeers = () => renderPresence([here.local(), ...here.peers().values()]);
here.onChange(renderPeers);                        // fires per peer as (sid, peer)
here.onLeave(renderPeers);

const feed = rt.channel('posts');
feed.on('new', (post) => { if (post.fromServer) addPostToDom(post); });

rt.on('reconnected', loadRecentPosts);             // nothing is replayed after a drop
await rt.connect();                                // null (not a throw) if the join failed
loadRecentPosts();

Realtime is ephemeral: it delivers posts to pages that are open now and stores nothing. That's the database's job (next), and why the page loads recent posts on connect and reconnect.

2. Persist posts with a function + DB, then publish

A public function writes the post and publishes it to the room; the client only calls the function. See app-development for the function/DB API.

-- migrations/001_posts.sql
CREATE TABLE posts (
  id SERIAL PRIMARY KEY,
  author TEXT NOT NULL,
  body TEXT NOT NULL,
  created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
// functions/add-post.js
export default async function (ctx, { db, realtime }) {
  const { author, body } = ctx.body;
  if (!body) return { error: 'body required' };
  const { rows } = await db.query(
    'INSERT INTO posts (author, body) VALUES ($1, $2) RETURNING id, author, body, created_at',
    [author || 'anon', body],
  );
  // Reaches every open page in the room; data is at most 16 KB of JSON.
  await realtime.publish({ room: 'feed', channel: 'posts', type: 'new', data: rows[0] });
  return { post: rows[0] };
}
// functions/list-posts.js
export default async function (ctx, { db }) {
  const { rows } = await db.query(
    'SELECT id, author, body, created_at FROM posts ORDER BY id DESC LIMIT 50', []);
  return { posts: rows };
}
// client
await Gipity.fn('add-post', { author: myName, body: text });   // the post arrives via feed.on('new')
async function loadRecentPosts() {
  const { posts } = await Gipity.fn('list-posts');
  renderPosts(posts);
}

3. A scheduled poster

To post automatically on a timer - an AI commenter, say - write a function that does the work, then drive it from a scheduled workflow with a function step. A scheduled function step runs with the same injected services as an HTTP call (db, realtime, secrets, fetch, ...), so it writes and publishes exactly like add-post:

// functions/post-ai-comment.js  - reads recent posts, writes and publishes a new one
export default async function (ctx, { db, realtime }) {
  const recent = await db.query('SELECT body FROM posts ORDER BY id DESC LIMIT 5', []);
  const body = await generateComment(recent.rows);   // your logic; an llm call also needs llm in services:
  const { rows } = await db.query(
    'INSERT INTO posts (author, body) VALUES ($1, $2) RETURNING id, author, body, created_at',
    ['ai', body],
  );
  await realtime.publish({ room: 'feed', channel: 'posts', type: 'new', data: rows[0] });
  return { post: rows[0] };
}
# workflows/post-ai-comment.yaml
name: ai-poster            # unique within the project (enforced)
trigger: schedule          # `cron` is an accepted alias
cron: "0 9 * * *"          # once a day
steps:
  - name: post
    step_type: function
    config: { name: post-ai-comment }

Plans set a minimum cron interval (24h on the free plan): a more frequent schedule fails the deploy's workflows phase with "cron too frequent for your plan". gipity credits shows your plan's limits. Use a function step, not a webhook hop, to reach your own function.

4. Deploy it all

Add the feed room and the function permissions to the gipity.yaml the template and kit wrote. Keep every phase that is already there: a phase left out of the file is not deployed (files and realtime are never added back for you):

# gipity.yaml
version: 1
deploy:
  phases:
    - name: files
      type: static
      source: src
    - name: database
      type: sql
      source: migrations
    - name: functions
      type: functions
      source: functions
      functions:
        - { name: add-post, auth: public, tables: [posts], services: [realtime] }
        - { name: list-posts, auth: public, tables: [posts] }
        - { name: post-ai-comment, auth: member, tables: [posts], services: [realtime] }  # the workflow runs it as you
    - name: workflows
      type: workflows
      source: workflows
    - name: realtime
      type: realtime
      rooms:
        # ...the rooms `gipity add realtime` wrote (keep them), plus:
        - name: feed
          room_type: state
          auth_level: public
          server_channels: [posts]   # clients cannot send on it; only functions publish

A function only reaches the tables in its tables: list and the injected services in its services: list; anything else throws a permission error at runtime.

Verify

  1. gipity deploy dev --inspect - all phases green, page renders, console clean (see app-debugging).
  2. gipity page test <dev-url> --clients 2 --observe "<expr that counts the presence list>" - both clients see each other (the two-client check in app-realtime).
  3. gipity fn call add-post '{"author":"me","body":"hi"}' --env dev - the post appears on an open dev page without a reload.
  4. Cron workflows are off in an environment until gipity env set dev --schedules on; meanwhile gipity fn call post-ai-comment --env dev exercises the poster. On prod, gipity workflow runs ai-poster shows completed once it has fired.

Related skills