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

2.5 KB
Raw Blame
import { createTrigger, TriggerStrategy, StaticPropsValue, AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework';
import { DedupeStrategy, Polling, pollingHelper, HttpMethod } from '@activepieces/pieces-common';
import dayjs from 'dayjs';
import { makeRequest } from '../common/client';
import { SiteSpeakAuth } from '../common/auth';
import { chatbotIdDropdown } from '../common/dropdown';
const props = {
    chatbotId: chatbotIdDropdown,
}
const polling: Polling<AppConnectionValueForAuthProperty<typeof SiteSpeakAuth>, StaticPropsValue<typeof props>> = {
    strategy: DedupeStrategy.TIMEBASED,
    items: async ({ auth, propsValue }) => {
        if (!propsValue.chatbotId) {
            return [];
        }
        const response = await makeRequest(
            auth.secret_text,
            HttpMethod.GET,
            `/${propsValue.chatbotId}/leads`,
            undefined,
            {
                Accept: 'application/json',
            }
        );
        console.log(response);
        const leads = response || [];

        return leads
            .filter((lead: any) => lead.email)
            .map((lead: any) => ({
                epochMilliSeconds: dayjs(lead.created_at).valueOf(),
                data: lead,
            }));
    },
};

export const newLead = createTrigger({
    auth: SiteSpeakAuth,
    name: 'newLead',
    displayName: 'New Lead',
    description: 'Triggers when a new lead with an email address is created in SiteSpeakAI.',
    aiMetadata: {
      description:
        'Fires when a SiteSpeakAI chatbot captures a new lead that includes an email address. Polls the selected chatbot for newly created leads; each event represents one captured visitor contact.',
    },
    props,
    sampleData: {
        id: 'lead_12345',
        chatbot_id: 'chatbot_6789',
        visitor_id: 'visitor_9876',
        name: 'John Doe',
        email: '[email protected]',
        phone: null,
        status: 'read',
        last_entry_at: '2023-09-30 13:10:39',
        created_at: '2023-09-30 13:10:19',
        updated_at: '2023-10-03 05:49:48',
    },
    type: TriggerStrategy.POLLING,

    async test(context) {
        return await pollingHelper.test(polling, context);
    },

    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);
    },
});