Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

1.9 KB
Raw Blame
import { createTrigger, TriggerStrategy } from '@activepieces/pieces-framework';
import { baserowAuth } from '../auth';
import { baserowCommon, makeClient } from '../common';
import { createWebhookTriggerHooks, dynamicWebhookInstructions, webhookUrlInfo } from '../common/webhook-trigger';
import { rowOutputSchema } from '../output-schemas';

const triggerHooks = createWebhookTriggerHooks({
  events: ['rows.created'],
  storeKey: 'baserow_row_created_trigger',
});

export const rowCreatedTrigger = createTrigger({
  name: 'baserow_row_created',
  classification: 'READ',
  outputSchema: rowOutputSchema,
  auth: baserowAuth,
  displayName: 'New Row',
  description: 'Triggers when a new row is created in a Baserow table.',
  aiMetadata: {
    description:
      'Fires when a new row is added to the selected Baserow table, emitting one event per created row. Use to react to individual new records; for the batch form use New Rows (Batch).',
  },
  type: TriggerStrategy.WEBHOOK,
  propertyGroups: [
    {
      key: 'table',
      display: 'section',
      label: 'Table to Watch',
      icon: 'file',
      props: ['table_id'],
    },
    {
      key: 'setup',
      display: 'section',
      label: 'Webhook',
      icon: 'send',
      props: ['webhook_url', 'instructions'],
    },
  ],
  props: {
    table_id: baserowCommon.tableId(),
    webhook_url: webhookUrlInfo(),
    instructions: dynamicWebhookInstructions('Rows created'),
  },
  sampleData: {
    id: 1,
    order: '1.00000000000000000000',
    Name: 'Example row',
  },
  onEnable: triggerHooks.onEnable,
  onDisable: triggerHooks.onDisable,
  async run(context) {
    const body = context.payload.body as { items?: unknown[] };
    return body.items ?? [];
  },
  async test(context) {
    const tableId = context.propsValue.table_id;
    if (!tableId) return [];
    const client = await makeClient(context.auth);
    const response = await client.listRows(tableId, 1, 5);
    return response.results;
  },
});