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

const sampleData = {
  event: 'subscription_canceled',
  user_id: 123456,
  user_email: '[email protected]',
  subscription_id: 'sub_789xyz',
  subscription_title: 'Premium Plan',
  canceled_at: '2025-10-27T13:32:10Z',
  custom_fields: {
    favorite_genre: 'Comedy',
    referral_source: 'Google Ads',
  },
};

export const canceledSubscription = createTrigger({
  auth: uscreenAuth,
  name: 'canceled_subscription',
  displayName: 'Canceled Subscription',
  description:
    'Triggers when a subscription is canceled for a user.',
  aiMetadata: {
    description: 'Fires when a user cancels (or has canceled) a subscription on the Uscreen storefront (event subscription_canceled). Represents a churn event, including the affected user, the subscription, and when it was canceled.',
  },
  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 !== 'subscription_canceled') {
      return [];
    }

    return [payload];
  },

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