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.6 KB
Raw Blame
import { createAction, Property } from '@activepieces/pieces-framework';
import { helpScoutApiRequest } from '../common/api';
import { helpScoutAuth } from '../common/auth';
import { propsValidation } from '@activepieces/pieces-common';
import * as z from 'zod/mini'
import { HttpMethod } from '@activepieces/pieces-common';

export const findCustomer = createAction({
  auth: helpScoutAuth,
  name: 'find_customer',
  classification: 'READ',
  displayName: 'Find Customer',
  description: 'Finds a customer by email.',
  audience: 'both',
  aiMetadata: {
    description:
      'Looks up a Help Scout customer by exact email and returns the first match (with a found flag). Use to resolve a customer ID or check existence before creating a customer or associating a conversation. Email is required; read-only and idempotent.',
    idempotent: true,
  },
  props: {
    email: Property.ShortText({
      displayName: 'Email',
      required: true,
    }),
  },
  async run({ auth, propsValue }) {
    await propsValidation.validateZod(propsValue, {
      email: z.string().check(z.minLength(1, 'Please provide a email.')),
    });
    const response = await helpScoutApiRequest({
      method: HttpMethod.GET,
      url: `/customers`,
      auth,
      queryParams: {
        query: `(email:"${propsValue.email}")`,
      },
    });
    const { _embedded } = response.body as {
      _embedded: {
        customers: { id: number; firstName: string; lastName: string }[];
      };
    };

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