Back to Docs

Examples

Worked examples — copy, tweak, deploy.

Reading reference docs is fine. Reading a working extension is better. Each full example below is a complete project: create the two files, change a bit, deploy it.

What it shows: the action-link trigger — single and bulk placements, reading transactions, logging a summary.

Scopes: read:transactions

prosaic.extension.toml:

toml
#:schema https://developer.prosaic.works/schemas/extension-manifest.json
name = "action-link-demo"
version = "0.0.1"
description = "Reads selected transactions and logs a summary"

[scopes]
required = ["read:transactions"]

[[targets.actions]]
placement = "transaction.single"
label = "Describe transaction"

[[targets.actions]]
placement = "transaction.bulk"
label = "Summarise transactions"

src/index.ts:

typescript
const { input } = prosaic.context;

if (input?.transactionId) {
  const txn = await prosaic.transactions.get(input.transactionId);
  prosaic.log.info('Transaction details', {
    id: txn.id,
    date: txn.date,
    description: txn.description,
    amount: txn.amount,
  });
}

if (input?.transactionIds) {
  const ids = input.transactionIds as string[];
  prosaic.log.info(`Processing ${ids.length} transactions`);

  for (const id of ids.slice(0, 10)) {
    const txn = await prosaic.transactions.get(id);
    prosaic.log.info(`${txn.description}: ${txn.amount}`);
  }

  if (ids.length > 10) {
    prosaic.log.info(`... and ${ids.length - 10} more`);
  }
}

Deploy it against a test entity:

bash
prosaic extension deploy --dir . --entity-id <your-entity-id>

Then click the button on a transaction — the execution shows up in prosaic extension logs.

Large-transaction alerts in Slack

What it shows: an event trigger, a [[connections]] declaration, prosaic.http.fetch, and dedupe with storage.

Scopes: read:transactions, read:entities, use:http

prosaic.extension.toml:

toml
#:schema https://developer.prosaic.works/schemas/extension-manifest.json
name = "large-transaction-alerts"
version = "0.0.1"
description = "Posts to Slack when a large transaction is reconciled"

[scopes]
required = ["read:transactions", "read:entities", "use:http"]

[[targets.events]]
type = "transaction.reconciled"

[[connections]]
name = "slack"
label = "Slack"
description = "A Slack bot token with the chat:write scope"
auth = "bearer"
base_url = "https://slack.com"
allowed_hosts = ["slack.com"]

[[connections.fields]]
key = "token"
label = "Bot token"
secret = true

src/index.ts:

typescript
const CHANNEL = '#bookkeeping';
const THRESHOLD = 10000;

async function main(): Promise<void> {
  const { input, entityId } = prosaic.context;
  const seenKey = `${entityId}:slack:${input.transactionId}`;
  if (await prosaic.storage.get(seenKey)) return;

  const txn = await prosaic.transactions.get(input.transactionId);
  if (Math.abs(Number(txn.amount)) < THRESHOLD) return;

  // The date is midnight in the entity's timezone, stored as UTC.
  const entity = await prosaic.entities.get(entityId);
  const date = new Date(txn.date).toLocaleDateString('en-CA', {
    timeZone: entity.timezone ?? 'Pacific/Auckland',
  });

  const res = await prosaic.http.fetch({
    connection: 'slack',
    path: '/api/chat.postMessage',
    method: 'POST',
    body: {
      channel: CHANNEL,
      text: `Reconciled: ${txn.description} for ${txn.amount} on ${date}`,
    },
  });

  // Slack reports most failures in the body of a 200 response.
  if (!res.ok || !(res.body as { ok?: boolean }).ok) {
    prosaic.log.error('Slack refused the message', {
      status: res.status,
      body: res.body,
    });
    return;
  }

  await prosaic.storage.set(seenKey, true);
}

await main();

After you deploy, a workspace admin opens the extension under Settings → Extensions and enters the bot token. Until then, http.fetch throws because the connection isn't connected.

Sketches

These are shapes rather than finished projects. Each uses only methods and scopes that exist today.

Monthly profit and loss email (cron + reports + email)

Runs on the 1st of each month. Calls prosaic.reports.generate('profit-loss', { periodType: 'last-month' }), picks out the totals, and emails them to the client.

Scopes: read:reports, send:email.

Select transactions, click the button. The extension reads the chart of accounts with prosaic.tools.invoke('accounts.list', {}), asks prosaic.ai.complete for the best account for each, and logs the suggestions for a person to apply. The full handler is in Triggers.

Scopes: read:transactions, read:entities, use:tools, use:ai.

GST return filed notice (event + GST + email)

React to gst.return.filed. Fetch the return with prosaic.gst.get(input.gstReturnId) and email the client the period, the net GST position and the due date.

Scopes: read:gst-returns, send:email.

Client reply handler (email + storage)

Send a conversational email asking a client for documents, and record the threadId in storage. When they reply, the extension runs with prosaic.context.trigger === 'email.reply'; look the thread up, log what they said, and mark it answered.

Scopes: send:email.

Build your own

The fastest path from idea to deployed extension is Build with an LLM — describe what you want, let Claude or Cursor scaffold it, deploy.

If you've got a pattern you'd like us to ship as an example, drop a note at support@prosaic.works.