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.7 KB
Raw Blame
import { createAction, Property } from '@activepieces/pieces-framework';
import { phoneValidatorAuth } from '../../lib/common/auth';
import { PhoneValidatorClient } from '../../lib/common/client';

export const validatePhone = createAction({
  auth: phoneValidatorAuth,
  name: 'validatePhone',
  displayName: 'Validate Phone Number',
  description: 'Validate a phone number and retrieve line type, carrier, and location information',
  audience: 'both',
  aiMetadata: { description: 'Looks up a phone number via the PhoneValidator API to determine whether it is valid and real. Choose the search type: "basic" returns line type, carrier, location, and a fake-number check, while "fake" runs only the fake/disposable-number check. Use it to verify or enrich a phone number before contacting it; the number can be passed in various formats (e.g. 7029270000 or 1-702-927-0000). This is a read-only lookup, safe to repeat.', idempotent: true },
  props: {
    phoneNumber: Property.ShortText({
      displayName: 'Phone Number',
      description: 'The phone number to validate (e.g., 7029270000, 1-702-927-0000)',
      required: true,
    }),
    searchType: Property.StaticDropdown({
      displayName: 'Search Type',
      description: 'Type of phone lookup to perform',
      required: true,
      options: {
        options: [
          {
            label: 'Basic (Line Type + Carrier + Location + Fake Check)',
            value: 'basic',
          },
          {
            label: 'Fake Number Check Only',
            value: 'fake',
          },
        ],
      },
      defaultValue: 'basic',
    }),
  },
  async run({ auth, propsValue }) {
    const client = new PhoneValidatorClient(auth.secret_text);
    const response = await client.validatePhone(propsValue.phoneNumber, propsValue.searchType as 'basic' | 'fake');

    if (response.StatusCode === '200') {
      const result: any = {
        phoneNumber: response.PhoneNumber,
        cost: response.Cost,
        searchDate: response.SearchDate,
        statusCode: response.StatusCode,
        statusMessage: response.StatusMessage,
      };

      if (response.PhoneBasic) {
        result.phoneBasic = {
          phoneNumber: response.PhoneBasic.PhoneNumber,
          reportDate: response.PhoneBasic.ReportDate,
          lineType: response.PhoneBasic.LineType,
          phoneCompany: response.PhoneBasic.PhoneCompany,
          phoneLocation: response.PhoneBasic.PhoneLocation,
          fakeNumber: response.PhoneBasic.FakeNumber,
          fakeNumberReason: response.PhoneBasic.FakeNumberReason || response.PhoneBasic.FakeReason || '',
          errorCode: response.PhoneBasic.ErrorCode,
          errorDescription: response.PhoneBasic.ErrorDescription,
        };
      }

      return result;
    }

    return response;
  },
});