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

4.3 KB
Raw Blame

import { createTrigger, TriggerStrategy, PiecePropValueSchema, Property, AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework';
import { DedupeStrategy, HttpMethod, Polling, pollingHelper } from '@activepieces/pieces-common';
import { smooveAuth } from '../common/auth';
import { makeRequest } from '../common/client';

interface LandingPageData {
    formId: number;
    formTitle: string;
    formType: string;
    [key: string]: any;
}

const polling: Polling<AppConnectionValueForAuthProperty<typeof smooveAuth>, { formType?: string }> = {
    strategy: DedupeStrategy.LAST_ITEM,
    items: async ({ auth, propsValue }) => {
        try {
            let endpoint = '/LandingPages';
            const { formType } = propsValue;
            
            if (formType && formType !== 'All') {
                endpoint += `?type=${encodeURIComponent(formType)}`;
            }

            const response = await makeRequest(auth.secret_text, HttpMethod.GET, endpoint);
            
            if (!response) {
                return [];
            }
            
            const items: LandingPageData[] = Array.isArray(response) ? response : [response];

            const validItems = items
                .filter(item => item.formId && item.formTitle)
                .sort((a, b) => (b.formId || 0) - (a.formId || 0));

            return validItems.map(item => {
                const { formId, formTitle, formType, ...otherFields } = item;
                return {
                    id: formId.toString(),
                    data: {
                        formId,
                        formTitle,
                        formType: formType || 'Unknown',
                        ...otherFields
                    },
                };
            });
            
        } catch (error: any) {
            console.error('Error fetching landing pages:', error);
            return [];
        }
    }
};

export const newFormCreated = createTrigger({
    auth: smooveAuth,
    name: 'newFormCreated',
    classification: 'READ',
    displayName: 'New Form Created',
    description: 'Fires when a new form/landing page is created in your Smoove account',
    aiMetadata: {
      description: 'Fires when a new form or landing page is created in the connected Smoove account, optionally filtered to a specific form type (landing page, Facebook, mobile, embed, or popup).',
    },
    props: {
        formType: Property.StaticDropdown({
            displayName: 'Form Type Filter',
            description: 'Filter by specific form type, or select "All" to monitor all form types',
            required: false,
            defaultValue: 'All',
            options: {
                options: [
                    { label: 'All Types', value: 'All' },
                    { label: 'Landing Page', value: 'LandingPage' },
                    { label: 'Facebook Form', value: 'Facebook' },
                    { label: 'Mobile Form', value: 'Mobile' },
                    { label: 'Embed Form', value: 'Embed' },
                    { label: 'Popup Form', value: 'Popup' }
                ]
            }
        })
    },
    sampleData: {
        "formId": 581014,
        "formTitle": "Contact Us Landing Page",
        "formType": "LandingPage",
        "dateCreated": "2025-01-22T10:30:00Z",
        "isActive": true,
        "url": "https://example.smoove.io/landing/contact-us",
        "description": "Main contact form for lead generation",
        "fields": [
            {
                "name": "email",
                "type": "email",
                "required": true
            },
            {
                "name": "firstName", 
                "type": "text",
                "required": true
            },
            {
                "name": "phone",
                "type": "tel",
                "required": false
            }
        ]
    },
    type: TriggerStrategy.POLLING,
    
    async test(context) {
        const results = await pollingHelper.test(polling, context);
        return results;
    },
    
    async onEnable(context) {
        await pollingHelper.onEnable(polling, context);
    },
    
    async onDisable(context) {
        await pollingHelper.onDisable(polling, context);
    },
    
    async run(context) {
        return await pollingHelper.poll(polling, context);
    },
});