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

export const listCalls = createAction({
  auth: blandAiAuth,
  name: 'list_calls',
  classification: 'SEARCH',
  displayName: 'List Calls',
  description: 'List recent Bland AI calls with optional filters.',
  audience: 'both',
  aiMetadata: {
    description:
      'Lists recent Bland AI calls, optionally narrowed by origin (from) and/or destination (to) phone number and capped by a limit (1-100). Leave the number filters empty to retrieve the most recent calls regardless of party. Use to discover call IDs or survey call history. Read-only and idempotent.',
    idempotent: true,
  },
  props: {
    limit: Property.Number({
      displayName: 'Limit',
      description: 'Maximum number of calls to return.',
      required: false,
      defaultValue: 10,
    }),
    fromNumber: Property.ShortText({
      displayName: 'From Number',
      description: 'Optional origin phone number filter.',
      required: false,
    }),
    toNumber: Property.ShortText({
      displayName: 'To Number',
      description: 'Optional destination phone number filter.',
      required: false,
    }),
  },
  async run(context) {
    const { limit, fromNumber, toNumber } = context.propsValue;
    const safeLimit = Math.max(1, Math.min(100, limit ?? 10));
    const query: Record<string, string> = {
      limit: String(safeLimit),
      ...(fromNumber ? { from_number: fromNumber } : {}),
      ...(toNumber ? { to_number: toNumber } : {}),
    };

    return blandApiCall({
      apiKey: context.auth.secret_text,
      method: HttpMethod.GET,
      path: '/calls',
      query,
    });
  },
});