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

3.0 KB
Raw Blame
import { createAction, Property } from '@activepieces/pieces-framework';

import { cannyAuth } from '../auth';
import { cannyRequest, cleanBody } from '../common/client';

export const listPostsAction = createAction({
  auth: cannyAuth,
  name: 'list_posts',
  classification: 'SEARCH',
  displayName: 'List Posts',
  description: 'Returns a list of posts for a board, with optional filtering and sorting.',
  audience: 'both',
  aiMetadata: {
    description:
      'Lists Canny posts, optionally scoped to one board or queried across all boards when no board is given, with optional search text, status filter, sort order, and pagination (limit/skip). Use to discover or search posts rather than fetch one known post by ID. Read-only and idempotent.',
    idempotent: true,
  },
  props: {
    boardID: Property.Dropdown({
      auth: cannyAuth,
      displayName: 'Board',
      description: 'The board to list posts for (optional — omit to list across all boards).',
      required: false,
      refreshers: [],
      options: async ({ auth }) => {
        if (!auth) {
          return {
            disabled: true,
            placeholder: 'Connect your Canny account first.',
            options: [],
          };
        }

        const response = await cannyRequest<{
          boards: Array<{ id: string; name: string }>;
        }>({
          apiKey: auth.secret_text,
          path: '/boards/list',
        });

        return {
          disabled: false,
          options: (response.boards ?? []).map((b) => ({
            label: b.name,
            value: b.id,
          })),
        };
      },
    }),
    search: Property.ShortText({
      displayName: 'Search',
      description: 'A search query to filter posts.',
      required: false,
    }),
    sort: Property.StaticDropdown({
      displayName: 'Sort',
      description: 'The order of returned posts.',
      required: false,
      options: {
        disabled: false,
        options: [
          { label: 'Newest', value: 'newest' },
          { label: 'Oldest', value: 'oldest' },
          { label: 'Score', value: 'score' },
          { label: 'Trending', value: 'trending' },
          { label: 'Status Changed', value: 'statusChanged' },
        ],
      },
    }),
    status: Property.ShortText({
      displayName: 'Status',
      description: 'Comma-separated list of statuses to filter by (e.g. "open,planned").',
      required: false,
    }),
    limit: Property.Number({
      displayName: 'Limit',
      description: 'Number of posts to fetch (default 10).',
      required: false,
    }),
    skip: Property.Number({
      displayName: 'Skip',
      description: 'Number of posts to skip (for pagination).',
      required: false,
    }),
  },
  async run({ auth, propsValue }) {
    return await cannyRequest({
      apiKey: auth.secret_text,
      path: '/posts/list',
      body: cleanBody({
        boardID: propsValue.boardID,
        search: propsValue.search,
        sort: propsValue.sort,
        status: propsValue.status,
        limit: propsValue.limit,
        skip: propsValue.skip,
      }),
    });
  },
});