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.2 KB
Raw Blame
import { intercomAuth } from '../auth';
import { createAction, Property } from '@activepieces/pieces-framework';
import { intercomClient } from '../common';
import { findLeadOutputSchema } from '../output-schemas';

export const findLeadAction = createAction({
    auth: intercomAuth,
    name: 'find-lead',
    classification: 'READ',
    displayName: 'Find Lead',
    description: 'Finds an existing lead.',
    audience: 'human',
    aiMetadata: { description: 'Look up a single existing lead (prospect contact) by email, Intercom ID, or external user ID. Read-only and repeatable; returns the first match plus a found flag and only matches role=lead. To find a signed-up user instead, use Find User.', idempotent: true },
    props: {
        searchField: Property.StaticDropdown({
            displayName: 'Search Field',
            required: true,
            options: {
                disabled: false,
                options: [
                    { label: 'Email', value: 'email' },
                    { label: 'ID', value: 'id' },
                    { label: 'User ID', value: 'external_id' },
                ],
            },
        }),
        searchValue: Property.ShortText({
            displayName: 'Search Value',
            required: true,
        }),
    },
    outputSchema: findLeadOutputSchema,
    async run(context) {
        const { searchField, searchValue } = context.propsValue;

        const client = await intercomClient(context.auth);

        const contactResponse = await client.contacts.search({
            query: {
                operator: 'AND',
                value: [
                    {
                        field: searchField,
                        operator: '=',
                        value: searchValue,
                    },
                    {
                        field: 'role',
                        operator: '=',
                        value: 'lead',
                    },
                ],
            },
            pagination: { per_page: 1 },
        });

        return {
            found: contactResponse.data.length > 0,
            lead: contactResponse.data.length > 0 ? contactResponse.data[0] : {},
        };
    },
});