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.5 KB
Raw Blame
import { createAction, Property } from '@activepieces/pieces-framework';
import { AuthenticationType, httpClient, HttpMethod } from '@activepieces/pieces-common';
import { twilioAuth } from '../..';

export const twilioPhoneNumberLookup = createAction({
  auth: twilioAuth,
  name: 'phone_number_lookup',
  classification: 'READ',
  description: 'Look up the carrier and line type (mobile, landline) of a number.',
  audience: 'both',
  aiMetadata: { description: 'Looks up carrier and line-type intelligence for a single phone number via the Twilio Lookup API. Use to validate or enrich a number (e.g. detect mobile vs landline, carrier) before messaging or calling it. Read-only and idempotent.', idempotent: true },
  displayName: 'Phone Number Lookup',
  props: {
    phone_number:Property.ShortText({
      displayName:'Phone Number',
      description:'Phone number with country code, starting with +.',
      placeholder:'+15558675310',
      required:true
    })
  },
  async run(context) {
    const { phone_number } = context.propsValue;

    const account_sid = context.auth.username;
    const auth_token = context.auth.password;

    const response = await httpClient.sendRequest({
      method:HttpMethod.GET,
      url:`https://lookups.twilio.com/v2/PhoneNumbers/${encodeURIComponent(phone_number)}`,
       authentication: {
            type: AuthenticationType.BASIC,
            username: account_sid,
            password: auth_token,
          },
        queryParams:{
          Fields:'line_type_intelligence'
        }
    })

    return response.body
  },
});