Fix: [3.0.3] JSON 파싱 강화 + Discord 전송 안정화
Some checks failed
news-summary-bot-cicd / build_push_deploy (push) Has been cancelled

- summarizer: 코드펜스/잡텍스트 포함된 Claude 응답도 안정적으로 파싱
- summarizer: 프롬프트에 코드펜스 금지 명시
- main: Discord embed용 summary 통합 필드 추가
- docs: n8n Discord 노드를 JSON.stringify() 방식으로 변경 (줄바꿈/따옴표 이스케이프)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
sm4640
2026-03-25 19:56:06 +09:00
parent 9c2bf7c1ce
commit 8aa03232e8
3 changed files with 68 additions and 43 deletions

View File

@@ -35,7 +35,7 @@ n8n(YouTube API로 새 영상 감지) → `POST /api/news/summarize` → 자막
```json
// 성공
{"video_url": "...", "title": "...", "channel_name": "...", "status": "ok", "oneliner": "한줄 요약", "main_points": "• 포인트1\n• 포인트2", "conclusion": "결론"}
{"video_url": "...", "title": "...", "channel_name": "...", "status": "ok", "oneliner": "한줄 요약", "main_points": "• 포인트1\n• 포인트2", "conclusion": "결론", "summary": "**한줄 요약**\n\n• 포인트1\n• 포인트2\n\n> 결론"}
// 스킵 (라이브/쇼츠)
{"video_url": "...", "title": "...", "channel_name": "...", "status": "skipped", "reason": "라이브/예정 영상은 요약 대상이 아닙니다"}
@@ -44,6 +44,8 @@ n8n(YouTube API로 새 영상 감지) → `POST /api/news/summarize` → 자막
{"video_url": "...", "title": "...", "channel_name": "...", "status": "error", "error_type": "ValueError", "error_message": "..."}
```
> `summary`는 `oneliner` + `main_points` + `conclusion`을 합친 Discord embed용 통합 필드.
## 환경변수
`ANTHROPIC_API_KEY` 필수. `API_SECRET`은 선택(n8n → FastAPI 인증용).
@@ -180,20 +182,25 @@ return $input.all().filter(item => {
- **Send Body**: ON
- **Body Content Type**: JSON
- **Specify Body**: Using JSON
- **Body (Expression 모드)**:
```json
{
"embeds": [{
"title": "📰 [{{ $json.channel_name }}] {{ $json.title }}",
"url": "{{ $json.video_url }}",
"description": "{{ $json.summary }}",
"color": 2829105,
"thumbnail": {
"url": "https://img.youtube.com/vi/{{ $json.video_url.split('v=')[1] }}/hqdefault.jpg"
- **Body**: Expression 모드 (`=` 클릭)로 전환 후 아래 입력:
> **주의**: `"Using JSON"` 모드에서 `{{ $json.summary }}` 같은 문자열 치환을 쓰면 요약 텍스트의 줄바꿈(`\n`)·따옴표(`"`) 때문에 JSON이 깨진다. 반드시 `JSON.stringify()`로 전체 객체를 직렬화해야 한다.
```javascript
{{ JSON.stringify({
embeds: [{
title: "📰 [" + $json.channel_name + "] " + $json.title,
url: $json.video_url,
description: $json.summary,
color: 2829105,
thumbnail: {
url: "https://img.youtube.com/vi/" + $json.video_url.split("v=")[1] + "/hqdefault.jpg"
},
"footer": { "text": "YouTube 뉴스 요약 봇 • {{ $json.channel_name }}" }
footer: {
text: "YouTube 뉴스 요약 봇 • " + $json.channel_name
}
}]
}
}) }}
```
#### 9. Discord 에러 알림 (status=error)
@@ -203,20 +210,23 @@ return $input.all().filter(item => {
- **Send Body**: ON
- **Body Content Type**: JSON
- **Specify Body**: Using JSON
- **Body (Expression 모드)**:
```json
{
"embeds": [{
"title": "❌ [{{ $json.channel_name }}] 뉴스 요약 실패",
"color": 15548997,
"fields": [
{ "name": "영상 제목", "value": "{{ $json.title }}", "inline": false },
{ "name": "에러 타입", "value": "`{{ $json.error_type }}`", "inline": true },
{ "name": "에러 내용", "value": "```\n{{ $json.error_message }}\n```", "inline": false }
- **Body**: Expression 모드 (`=` 클릭)로 전환 후 아래 입력:
```javascript
{{ JSON.stringify({
embeds: [{
title: "❌ [" + $json.channel_name + "] 뉴스 요약 실패",
color: 15548997,
fields: [
{ name: "영상 제목", value: $json.title, inline: false },
{ name: "에러 타입", value: "`" + $json.error_type + "`", inline: true },
{ name: "에러 내용", value: "```\n" + $json.error_message + "\n```", inline: false }
],
"footer": { "text": "봇 요약 처리 에러 — FastAPI 응답" }
footer: {
text: "봇 요약 처리 에러 — FastAPI 응답"
}
}]
}
}) }}
```
### YouTube Data API 키 발급