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.7 KB
Raw Blame
import { createTrigger, TriggerStrategy } from '@activepieces/pieces-framework';
import { uscreenAuth } from '../common/auth';
import { uscreenProps } from '../common/props';

const sampleData = {
  id: '   123456',
  email: '[email protected]',
  changes: {
    name: 'John Doe',
    email: '[email protected]',
    subscription_status: 'active',
    lifetime_spent: '100',
    bounced_email: false,
    status: 'active',
    field_1: 'value_1',
    field_2: 'value_2',
    field_3: 'value_3',
  },
  attributes: {
    name: 'John Doe',
    email: '[email protected]',
    subscription_status: 'active',
    lifetime_spent: '100',
    bounced_email: false,
    segments: ['segment_1', 'segment_2'],
    status: 'active',
    origin: 'user.creation_source',
  },
  event: 'user_updated',
};

export const userUpdated = createTrigger({
  auth: uscreenAuth,
  name: 'user_updated',
  displayName: 'User Updated',
  description:
    'Triggers when a user’s profile or information is updated.',
  aiMetadata: {
    description: 'Fires when an existing user’s profile or attributes change on the Uscreen storefront (event user_updated). Represents a customer-record update, exposing both the changed fields and the full current attributes (e.g. subscription status, lifetime spent, segments).',
  },
  props: { setupInstructions: uscreenProps.webhookInstructions() },
  sampleData: sampleData,
  type: TriggerStrategy.WEBHOOK,

  async onEnable(context) {
    //Empty
  },

  async onDisable(context) {
    //Empty
  },

  async run(context) {
    const payload = context.payload as unknown as typeof sampleData;

    if (payload.event !== 'user_updated') {
      return [];
    }

    return [payload];
  },

  async test(context) {
    return [sampleData];
  },
});