---
title: "Pipedream"
description: "TwexAPI를 통해 트윗 검색, 프로필, 인기 트윗, HTTP 트리거, 승인된 게시물을 위한 Pipedream 워크플로 자동화를 구축합니다."
---

검색, 프로필, 인기 트윗, 승인된 게시물을 위한 Pipedream Twitter 통합을 구축합니다. TwexAPI는 모든 워크플로에 하나의 REST API와 하나의 API 키를 제공합니다.

에이전트 핸드오프에는 웹훅 트리거를, 반복 검색에는 스케줄 트리거를, 사용자 지정 정규화가 필요할 때는 인라인 코드 단계를 선택하세요.

## Pipedream 자동화 패턴 선택

<CardGroup cols={2}>
  <Card title="HTTP 트리거 + 코드 단계" icon="webhook">
    MCP 에이전트로부터 엄격한 JSON을 수신하고, 행을 정규화하며, Slack 또는 Sheets로 라우팅합니다.
  </Card>

  <Card title="스케줄 REST 읽기" icon="calendar-clock">
    트윗 검색 또는 트렌드 보고를 위해 주기적으로 TwexAPI를 호출합니다.
  </Card>

  <Card title="프라이빗 컴포넌트 패키지" icon="boxes">
    전체 팀이 동일한 작업이 필요할 때 반복 인증 요청을 패키지화합니다.
  </Card>
</CardGroup>

검색, 웹훅 핸드오프, 팔로워 보내기, 승인된 쓰기를 별도 워크플로로 분리하세요. 워크플로가 작을수록 오류와 속도 제한이 더 명확하게 드러납니다.

## 전제조건

* [TwexAPI API 키](https://twexapi.io/dashboard)
* Pipedream 계정
* 선택적 Slack, Google Sheets, Airtable 또는 데이터베이스 연결 계정
* `https://api.twexapi.io/mcp`에 연결된 선택적 MCP 지원 에이전트

## 서버리스 API 통합

모든 TwexAPI 요청은 `https://api.twexapi.io`에서 시작합니다. `Authorization: Bearer` 헤더로 API 키를 전송합니다. 키는 단계보내기나 로그가 아닌 Pipedream 환경 변수에 보관하세요.

```bash
export TWEXAPI_API_KEY="YOUR_API_KEY"
```

`GET /balance`를 첫 인증 확인으로 사용하세요. X 계정을 변경하지 않고 API 키를 검증합니다.

## 공유 요청 헬퍼

```javascript
export default defineComponent({
  props: {
    twexapi: {
      type: "string",
      label: "TwexAPI API Key",
      secret: true,
    },
  },
  methods: {
    async twexapiRequest($, { method, path, body, params }) {
      const url = new URL(`https://api.twexapi.io${path}`);
      if (params) {
        Object.entries(params).forEach(([key, value]) => {
          if (value !== undefined && value !== null) {
            url.searchParams.set(key, String(value));
          }
        });
      }

      const response = await fetch(url, {
        method,
        headers: {
          Authorization: `Bearer ${this.twexapi}`,
          "Content-Type": "application/json",
        },
        body: body ? JSON.stringify(body) : undefined,
      });

      if (!response.ok) {
        throw new Error(`TwexAPI request failed with HTTP ${response.status}`);
      }

      return response.json();
    },
  },
});
```

## 시작 작업

| 작업 | TwexAPI 경로 |
| --- | --- |
| 트윗 검색 | `POST /twitter/advanced_search/page` |
| 사용자 프로필 조회 | `GET /twitter/{screen_name}/about` |
| 사용자 검색 | `GET /twitter/search-user/{keyword}/{target_count}` |
| 트렌드 조회 | `GET /twitter/global-trending/tweets` |
| 팔로워 목록 | `POST /v3/twitter/users/followers` |
| 트윗 생성 | `POST /twitter/tweets/create` |

### 트윗 검색 코드 단계

```javascript
export default defineComponent({
  async run({ steps, $ }) {
    const response = await fetch("https://api.twexapi.io/twitter/advanced_search/page", {
      method: "POST",
      headers: {
        Authorization: `Bearer ${process.env.TWEXAPI_API_KEY}`,
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        searchTerms: ["AI agents lang:en"],
        sortBy: "Latest",
        nextCursor: "",
      }),
    });

    if (!response.ok) {
      throw new Error(`TwexAPI request failed with HTTP ${response.status}`);
    }

    return response.json();
  },
});
```

## 웹훅 우선 흐름

1. Pipedream에서 HTTP 트리거를 생성합니다.
2. MCP 지원 에이전트에 TwexAPI 행을 수집하고 엄격한 JSON을 반환하도록 요청합니다.
3. JSON을 Pipedream 엔드포인트에 POST합니다.
4. 코드 단계에서 행을 정규화하고 중복을 제거합니다.

### JavaScript 정규화 단계

```javascript
export default defineComponent({
  async run({ steps }) {
    const payload = steps.trigger.event.body;

    return (payload.tweets || []).map((tweet) => ({
      id: tweet.tweet_id || tweet.id,
      url: tweet.public_url ?? `https://x.com/i/web/status/${tweet.tweet_id || tweet.id}`,
      author: tweet.author_username,
      text: tweet.text || tweet.full_text,
      created_at: tweet.created_at,
      route_used: payload.route_used,
      next_cursor: payload.next_cursor,
    }));
  },
});
```

권장 MCP 에이전트 프롬프트:

```text
Use Twexapi MCP to get quote tweets for tweet ID 1803006263529541838.
Return only JSON with route_used, source_tweet_id, has_more, next_cursor, and tweets.
Each tweet must include tweet_id, author_username, text, created_at, and public_url.
Do not call write endpoints.
```

## 결과 핸드오프

<CardGroup cols={2}>
  <Card title="트윗 페이지" icon="search">
    `tweet_count`, `has_more`, `next_cursor`를 보냅니다. `tweet_id`, `text`, `author_username`, `created_at`이 포함된 행을 반환합니다.
  </Card>

  <Card title="프로필 행" icon="user-round">
    `user_id`, `username`, `name`, 팔로워 수, 인증 필드를 보냅니다.
  </Card>

  <Card title="트렌드 배치" icon="trending-up">
    국가, 주제, 콘텐츠 태그, 워크플로 메타데이터가 포함된 트윗 행을 보냅니다.
  </Card>

  <Card title="쓰기 작업" icon="send">
    [CLI](/sdks/cli) `--dry-run`으로 미리 봅니다. 쓰기 작업에는 쿠키 또는 `auth_token`이 필요합니다.
  </Card>
</CardGroup>

## 오류 처리

다운스트림 행을 보내기 전에 각 상태를 라우팅합니다.

| 상태 | 조치 |
| ------ | ------ |
| `400` | 요청 필드를 수정합니다. 변경 없이 재시도하지 마세요. |
| `401` | API 키를 교체합니다. |
| `403` | 계정 액세스 또는 크레딧을 해결합니다. |
| `429` | 백오프하고 커서를 보존합니다. |
| `5xx` | 제한된 백오프로 안전한 읽기를 재시도합니다. |

다운스트림 처리가 성공한 후에만 페이지 커서를 유지합니다.

## 레시피

### 트윗 검색 → Slack

1. 보고 주기에 맞춰 워크플로를 스케줄합니다.
2. `POST /twitter/advanced_search/page`를 호출합니다.
3. 참여 임계값으로 트윗을 필터링합니다.
4. 선택한 트윗 텍스트, 작성자, 링크를 Slack으로 보냅니다.

### 에이전트 핸드오프 → Google Sheets

1. HTTP 트리거가 MCP 핸드오프 JSON을 수신합니다.
2. 트윗 행을 정규화합니다.
3. `tweet_id`로 Sheets에 upsert합니다.

### 팔로워 페이지 → CRM

1. HTTP 또는 스케줄 단계가 `POST /v3/twitter/users/followers`를 호출합니다.
2. 팔로워 행을 정규화합니다.
3. CRM이 `user_id`로 upsert합니다.
4. 데이터 저장소에 `next_cursor`를 유지합니다.

## 테스트 체크리스트

* 트리거 본문이 유효한 JSON인지 확인합니다.
* `tweet_id` 또는 `user_id`를 중복 제거 키로 사용합니다.
* 스케줄 연속 실행을 위해 Pipedream 데이터 저장소에 `next_cursor`를 저장합니다.
* `TWEXAPI_API_KEY`는 환경 변수에만 보관합니다.
* 단계 출력에 Bearer 토큰을 기록하지 않습니다.

## 다음 단계

* [Make](/guides/make)
* [Zapier](/guides/zapier)
* [n8n](/guides/n8n)
* [Agent MCP Handoff](/mcp/agent-handoff)
* [API Reference](/api-reference/overview)
