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

export const searchTweets = createAction({
  auth: xquikAuth,
  name: 'search_tweets',
  classification: 'SEARCH',
  displayName: 'Search Tweets',
  description: 'Search public X/Twitter posts with X query operators.',
  audience: 'both',
  aiMetadata: {
    description:
      'Searches public X/Twitter posts matching a query, which supports keywords, hashtags, exact phrases, from:user, and X search operators. Use to find posts on a topic; set the result type to fetch the latest posts or top engagement-ranked ones, and optionally bound results by a time window. Read-only and idempotent.',
    idempotent: true,
  },
  props: {
    query: Property.ShortText({
      displayName: 'Query',
      description:
        'Search query. Supports keywords, hashtags, from:user, exact phrases, and X search operators.',
      required: true,
    }),
    queryType: Property.StaticDropdown({
      displayName: 'Result Type',
      description: 'Return latest posts or top engagement-ranked posts.',
      required: false,
      defaultValue: 'Latest',
      options: {
        options: [
          {
            label: 'Latest',
            value: 'Latest',
          },
          {
            label: 'Top',
            value: 'Top',
          },
        ],
      },
    }),
    limit: Property.Number({
      displayName: 'Limit',
      description: 'Maximum posts to return. Use 1-200.',
      required: false,
      defaultValue: 20,
    }),
    cursor: Property.ShortText({
      displayName: 'Cursor',
      description: 'Pagination cursor from a previous response.',
      required: false,
    }),
    sinceTime: Property.DateTime({
      displayName: 'Since Time',
      description: 'Only return posts after this ISO timestamp.',
      required: false,
    }),
    untilTime: Property.DateTime({
      displayName: 'Until Time',
      description: 'Only return posts before this ISO timestamp.',
      required: false,
    }),
  },
  async run(context) {
    return xquikCommon.api.get({
      apiKey: context.auth.secret_text,
      path: '/x/tweets/search',
      queryParams: xquikCommon.utils.cleanQueryParams({
        cursor: context.propsValue.cursor,
        limit: context.propsValue.limit,
        q: context.propsValue.query,
        queryType: context.propsValue.queryType,
        sinceTime: context.propsValue.sinceTime,
        untilTime: context.propsValue.untilTime,
      }),
    });
  },
});