This n8n AI Agent Extracts Text From Anything (Images, PDFs, Google Docs)
원본 영상: This n8n AI Agent Extracts Text From Anything (Images, PDFs, Google Docs)
한 줄 요약
섹션 제목: “한 줄 요약”Telegram으로 파일을 받아 → 파일 유형 분기 → AI로 텍스트 추출 → 구조화 → Google Sheets 저장까지 전 과정을 n8n으로 자동화한다.
핵심 내용
섹션 제목: “핵심 내용”- 트리거: Telegram 메시지 수신. 파일 첨부 시
file_id만 전달되므로 실제 파일은 별도 다운로드 단계가 필요. - 파일 다운로드: Telegram 노드로
file_id를 넘겨 바이너리 파일을 취득. - Switch 분기: MIME type을 기준으로 PDF / image/jpeg / text/csv / Google Drive URL / video / audio 경로로 분기.
- Google Docs·Sheets·Slides는 파일이 아닌 **링크(텍스트 메시지)**로 전송 → 분기 조건이 다름.
- 파일 유형별 텍스트 추출:
- 이미지: OpenAI “Analyze an image” 노드 → OCR 프롬프트
- PDF: n8n 내장 “Extract from file” 노드
- CSV: n8n 내장 “Extract from file” 노드 (text 모드)
- Google Docs/Sheets/Slides: Google Drive 노드로 PDF 변환 후 추출
- 영상: Google Gemini API
- 오디오: OpenAI Whisper (Audio → Text 변환)
- 표준화(Edit Fields 노드): 각 경로마다 참조 경로가 다른 텍스트(
json[0].content[0].textvsjson.text등)를json.text하나로 통일해 AI 에이전트에 일관된 입력 제공. - AI 에이전트: 비구조화 텍스트를 JSON Schema 기반 Structured Output Parser로 구조화. 원하는 필드(invoice number, line items, date, total 등)를 자유 정의.
- Google Sheets 출력: 단일 행(인보이스 요약) 또는 Split Out 노드로 라인 아이템별 행 분리 후 Append.
- 완료 알림: Telegram에 “document has been uploaded” 메시지 반신.
전술·요소
섹션 제목: “전술·요소”| 파일 유형 | 추출 방법 | 필요 크레덴셜 |
|---|---|---|
| 이미지(JPEG 등) | OpenAI “Analyze image” + OCR 프롬프트 | OpenAI API Key ($5 최소 잔액) |
| n8n Extract from file | 없음 | |
| CSV | n8n Extract from file (text) | 없음 |
| Google Docs/Sheets/Slides | Google Drive → PDF 변환 → 추출 | Google OAuth (Client ID + Secret) |
| 영상 | Google Gemini API | Gemini API Key |
| 오디오 | OpenAI Whisper | OpenAI API Key |
- Telegram 오디오 파일은
message.audio.file_id로 참조 (일반 파일의message.document.file_id와 다름). - Switch 조건: 파일 전송 시
document.file_id절대경로 사용, 링크 전송 시message.text사용. - Structured Output Parser JSON은 ChatGPT에 “다음 항목을 뽑는 sample JSON을 만들어줘”로 생성 후 붙여넣기. 값 필드는 비워두어 AI가 임의 값을 채우지 않도록 설정.
수치·사례
섹션 제목: “수치·사례”- 오디오 테스트 결과: “automation services, 수량 1, 단가 $2,500, 세율 5%, 합계 자동 계산” — 본인 실측.
- 영상 테스트 결과: 세탁 서비스 인보이스 영상에서 서비스명·가격($11, $50, $7) 정상 추출 — 본인 실측.
- 이미지(Marshalls 영수증)에서 주소·라인 아이템 4건 정상 추출 — 본인 실측.
도구·워크플로
섹션 제목: “도구·워크플로”Telegram Trigger └─ Telegram: Get File (file_id 다운로드) └─ Switch (MIME type 분기) ├─ image/jpeg → OpenAI Analyze Image → Edit Fields ├─ application/pdf → Extract from File (PDF) → Edit Fields ├─ text/csv → Extract from File (text) → Edit Fields ├─ Google URL → Google Drive: Download as PDF → Extract from File → Edit Fields ├─ video/* → Google Gemini → Edit Fields └─ audio/* → Telegram: Get File (audio) → OpenAI Whisper → Edit Fields └─ (모든 경로 합류) AI Agent (Structured Output Parser) ├─ Google Sheets: Append (요약 1행) └─ Split Out (line items) → Google Sheets: Append (행별) └─ Telegram: Send Message ("uploaded")- OCR 프롬프트:
"Can you transcribe the image text using OCR?" - AI Agent 프롬프트:
"Please extract data from this document. Name: {filename}, Text: {text}" - 이미지 모델: GPT-4o Mini (비용 절감 목적, OCR에 충분한 성능)
- Gemini API Key 발급:
aistudio.google.com/app/api-keys