DOCS/troubleshooting/251014_slack_lists_file_attachment.md
happybell80 bea06e3069 docs: Slack Lists 첨부파일 업로드 구현 계획
- skill-rag-file: GET /api/download/{document_id} 추가 필요
- skill-slack: POST /api/v1/files/upload 추가 필요
- coldmail_briefing.py:159-204: 파일 다운로드 → 업로드 → file_id 통합 필요

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-14 00:53:42 +09:00

2.6 KiB

Slack Lists 첨부파일 업로드 구현

날짜: 2025-10-14 작성자: happybell80 관련 파일: rb8001/app/scheduler/jobs/coldmail_briefing.py


문제 상황

  • coldmail_briefing.py:204: attachment 필드에 document_id 문자열 전달
  • Slack Lists API는 file_id 필요 (skill-slack/tests/test_slack_lists.py:112)

현재 상태

skill-rag-file

  • main.py:54: POST /api/upload 존재
  • upload.py:108: storage_path에 파일 저장
  • 다운로드 API 없음

skill-slack

  • lists.py:47: POST /lists/items 존재 (slackLists.items.create)
  • messages.py:19: POST /send 존재 (chat_postMessage)
  • files_upload_v2 통합 없음

test_slack_lists.py (검증된 동작)

  • 81-88줄: files_upload_v2(channel, file, title) → file_id 반환
  • 112줄: attachment 필드에 [file_id] 전달
  • 192줄: channel 파라미터 있으면 메시지 생성, 없으면 업로드만

해결 방안

우선순위 1: skill-rag-file 다운로드 API

파일: skill-rag-file/app/api/download.py (신규)

  • GET /api/download/{document_id}
  • TeamDocument.query(id=document_id) → storage_path, filename 조회
  • from fastapi.responses import FileResponse
  • return FileResponse(path=storage_path, filename=filename)

파일: skill-rag-file/app/main.py:55

  • from app.api import download
  • app.include_router(download.router, prefix="/api", tags=["download"])

DB: app/models/database.py:7-28

  • TeamDocument.storage_path (Text)
  • TeamDocument.filename (String(255))

우선순위 2: skill-slack 파일 업로드 API

파일: skill-slack/app/api/endpoints/files.py (신규)

  • POST /api/v1/files/upload (multipart/form-data)
  • from slack_sdk import WebClient
  • client = WebClient(token=token)
  • result = client.files_upload_v2(file=file, title=title)
  • return {"file_id": result['file']['id']}

참고: messages.py:17 (WebClient 초기화), test_slack_lists.py:81-88

우선순위 3: coldmail_briefing.py 통합

위치: rb8001/app/scheduler/jobs/coldmail_briefing.py:159-204

  • GET {SKILL_RAG_FILE_URL}/api/download/{document_id}
  • 파일 /tmp/{filename} 저장
  • POST {SKILL_SLACK_URL}/api/v1/files/upload (multipart)
  • 204줄: attachment: [file_id]

교훈

테스트 파일 확인 누락

  • test_slack_lists.py에 완전한 구현 예시 존재
  • 문서만 보고 추측으로 작성
  • 교훈: 테스트 파일 우선 확인 필수

API 스펙 미확인

  • attachment 필드 타입 확인 안 함
  • document_id 문자열 전달 (오류)
  • 교훈: Slack API 필드 타입 사전 확인 필수