Skip to content

Commit 249b362

Browse files
committed
fix(slack): show all draft statuses on Home, fix n8n webhook URL
- Remove status filter in get_recent_drafts — show all drafts including published/failed - Move n8n webhook URL to settings/env, switch from webhook-test to webhook - Add error logging for views.open calls - Add debug logging for all block_actions to trace missing trigger_id
1 parent 1a9d416 commit 249b362

5 files changed

Lines changed: 16 additions & 12 deletions

File tree

.env.example

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,10 @@ LLM_COST_THRESHOLD_CHARS=25000
4646
PUBMED_API_KEY=your_pubmed_api_key_here
4747

4848
SLACK_BOT_TOKEN=your_slack_key_here
49-
SLACK_SIGNING_SECRET=your_slack_here
49+
SLACK_SIGNING_SECRET=your_slack_here
50+
51+
# ==============================================================================
52+
# N8N WEBHOOK
53+
# ==============================================================================
54+
# Use /webhook/ for production, /webhook-test/ only when testing in n8n UI
55+
N8N_WEBHOOK_URL=http://127.0.0.1:5678/webhook/publish-post

backend/api/routes/feedback.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ async def slack_interactions(
8686
action = payload.get("actions", [])[0]
8787
action_id = action.get("action_id")
8888
response_url = payload.get("response_url")
89+
logger.info("slack_block_action", action_id=action_id, trigger_id=trigger_id)
8990
action_value = action.get("value", "temp_id|telegram")
9091
value_parts = action_value.split("|")
9192
draft_id = value_parts[0]
@@ -104,11 +105,13 @@ async def slack_interactions(
104105
if action_id == "action_open_manual_post_modal":
105106
modal_view = build_manual_post_modal()
106107
async with httpx.AsyncClient() as client:
107-
await client.post(
108+
res = await client.post(
108109
"https://slack.com/api/views.open",
109110
headers=headers,
110111
json={"trigger_id": trigger_id, "view": modal_view},
111112
)
113+
if not res.json().get("ok"):
114+
logger.error("manual_post_modal_open_error", error=res.json())
112115
return Response(status_code=200)
113116

114117
if action_id == "action_home_drafts_page":

backend/config/settings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class Settings(BaseSettings):
4949
# Slack
5050
SLACK_BOT_TOKEN: SecretStr = Field(default=SecretStr(""))
5151
SLACK_SIGNING_SECRET: SecretStr = Field(default=SecretStr(""))
52+
# n8n
53+
N8N_WEBHOOK_URL: str = "http://127.0.0.1:5678/webhook/publish-post"
5254
# Конфігурація Pydantic
5355
model_config = SettingsConfigDict(
5456
env_file=".env", env_file_encoding="utf-8", extra="ignore"

backend/repositories/draft_repository.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,7 @@ async def get_recent_drafts(
4646
self, limit: int = 10, offset: int = 0, platform: str | None = None
4747
) -> list[Draft]:
4848
"""Витягує останні драфти (для Дашборду в Slack)"""
49-
active_statuses = ("pending", "generating", "generated", "scheduled")
50-
stmt = (
51-
select(Draft)
52-
.where(Draft.status.in_(active_statuses))
53-
.order_by(Draft.updated_at.desc())
54-
)
49+
stmt = select(Draft).order_by(Draft.updated_at.desc())
5550
if platform:
5651
stmt = stmt.where(Draft.platform == platform)
5752
stmt = stmt.limit(limit).offset(offset)

backend/workers/tasks/publish_post.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import httpx
22
import structlog
33

4+
from backend.config.settings import settings
45
from backend.workers.broker import broker
56

67
logger = structlog.get_logger()
78

8-
# Тестовий URL n8n. Воркер запускається локально, тому 127.0.0.1:5678
9-
N8N_WEBHOOK_URL = "http://127.0.0.1:5678/webhook-test/publish-post"
10-
119

1210
@broker.task(task_name="publish_post", timeout=30, labels={"priority": "medium"})
1311
async def publish_post_task(
@@ -22,7 +20,7 @@ async def publish_post_task(
2220

2321
try:
2422
async with httpx.AsyncClient() as client:
25-
response = await client.post(N8N_WEBHOOK_URL, json=payload, timeout=10.0)
23+
response = await client.post(settings.N8N_WEBHOOK_URL, json=payload, timeout=10.0)
2624
response.raise_for_status()
2725

2826
logger.info("publish_task_success", post_id=post_id, platform=platform)

0 commit comments

Comments
 (0)