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

export const findContact = createAction({
  auth: respondIoAuth,
  name: 'find_contact',
  displayName: 'Find Contact',
  description: 'Search for contacts by name, email, or phone number in Respond.io.',
  audience: 'both',
  aiMetadata: { description: 'Searches Respond.io contacts by a free-text term matching name, email, or phone, returning matching contacts. Use to resolve a contact to its ID before acting on it, or to look up contacts. Supports a result limit (1-99, default 10) and cursor-based pagination. Read-only and idempotent.', idempotent: true },
  props: {
    search: Property.ShortText({
      displayName: 'Search Term',
      description:
        'The value to search for (e.g., email address, phone number, or name).',
      required: true,
    }),
    timezone: Property.ShortText({
      displayName: 'Timezone',
      description:
        'Timezone for the search (e.g., "Asia/Kuala_Lumpur"). Optional.',
      required: false,
    }),
    limit: Property.Number({
      displayName: 'Result Limit',
      description: 'Number of contacts to return (1-99). Default is 10.',
      required: false,
      defaultValue: 10,
    }),
    cursorId: Property.Number({
      displayName: 'Cursor ID',
      description: 'Contact ID to start from for pagination. Optional.',
      required: false,
    }),
  },
  async run({ propsValue, auth }) {
    const { search, timezone, limit = 10, cursorId } = propsValue;

    // Validate limit (API requirement: >= 1 < 100)
    if (limit < 1 || limit >= 100) {
      throw new Error('Limit must be between 1 and 99.');
    }

    // Build query parameters
    const queryParams = [`limit=${limit}`];
    if (cursorId) {
      queryParams.push(`cursorId=${cursorId}`);
    }

    // Build request body
    const body: {
      search: string;
      timezone?: string;
      filter?: { $and: any[] };
    } = { 
      search,
      filter: { $and: [] }
    };

    if (timezone) {
      body.timezone = timezone;
    }

    return await respondIoApiCall({
      method: HttpMethod.POST,
      url: `/contact/list?${queryParams.join('&')}`,
      auth: auth,
      body,
    });
  },
});