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.6 KB
Raw Blame
import { createAction, Property } from '@activepieces/pieces-framework';
import { lightfunnelsAuth } from '../auth';
import { lightfunnelsCommon } from '../common/index';

export const createCustomer = createAction({
  auth: lightfunnelsAuth,
  name: 'create_customer',
  displayName: 'Create Customer',
  description: 'Create a new customer',
  audience: 'both',
  aiMetadata: { description: 'Creates a new customer record in Lightfunnels with first/last name, email, phone, marketing-consent flag, and tags. Use to add a contact; not for updating an existing customer. Not idempotent — each call creates a separate customer even with identical input.', idempotent: false },
  props: {
    firstName: Property.ShortText({
      displayName: 'First Name',
      description: 'First name of the customer',
      required: true,
    }),
    lastName: Property.ShortText({
      displayName: 'Last Name',
      description: 'Last name of the customer',
      required: true,
    }),
    email: Property.ShortText({
      displayName: 'Email',
      description: 'Email of the customer',
      required: true,
    }),
    phone: Property.ShortText({
      displayName: 'Phone',
      description: 'Phone number of the customer eg: +1234567890',
      required: true,
    }),
    acceptsMarketing: Property.Checkbox({
      displayName: 'Accepts Marketing',
      description: 'Whether the customer accepts marketing communications',
      required: true,
    }),
    tags: Property.Array({
      displayName: 'Tags',
      description: 'Tags to associate with the customer',
      required: true,
      properties: {
        tag: Property.ShortText({
          displayName: 'Tag',
          required: true,
        }),
      },
    }),
  },
  async run(context) {
    const { firstName, lastName, email, phone, acceptsMarketing, tags } = context.propsValue;

    const graphqlQuery = `
      mutation createCustomerMutation($node: InputCustomer!) {
        createCustomer(node: $node) {
          id
          _id
          first_name
          last_name
          full_name
          email
          phone
          accepts_marketing
          tags
          created_at
          updated_at
        }
      }
    `;

    const tagArray = (tags || []).map((t: any) => t.tag);

    const variables = {
      node: {
        first_name: firstName,
        last_name: lastName,
        email,
        phone,
        accepts_marketing: acceptsMarketing,
        tags: tagArray,
      },
    };

    const response = await lightfunnelsCommon.makeGraphQLRequest(
      context.auth,
      graphqlQuery,
      variables
    );

    return response.data.createCustomer;
  },
});