Add clickup_task_id param to write_press_releases for chat-triggered sync
When a press release is triggered via chat with a ClickUp task ID, the tool now uploads .docx attachments, posts a result comment, and updates task status — matching what the scheduler does automatically. ClickUp sync is wrapped in try/except so failures don't lose PR results. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>cora-start
parent
46bc38106e
commit
a7171673fc
|
|
@ -370,6 +370,7 @@ def write_press_releases(
|
||||||
url: str = "",
|
url: str = "",
|
||||||
lsi_terms: str = "",
|
lsi_terms: str = "",
|
||||||
required_phrase: str = "",
|
required_phrase: str = "",
|
||||||
|
clickup_task_id: str = "",
|
||||||
ctx: dict = None,
|
ctx: dict = None,
|
||||||
) -> str:
|
) -> str:
|
||||||
"""Run the full press-release pipeline and return results + cost summary."""
|
"""Run the full press-release pipeline and return results + cost summary."""
|
||||||
|
|
@ -585,6 +586,66 @@ def write_press_releases(
|
||||||
output_parts.append(f"| {c['step']} | {c['model']} | {c['elapsed_s']} |")
|
output_parts.append(f"| {c['step']} | {c['model']} | {c['elapsed_s']} |")
|
||||||
output_parts.append(f"| **Total** | | **{round(total_elapsed, 1)}** |")
|
output_parts.append(f"| **Total** | | **{round(total_elapsed, 1)}** |")
|
||||||
|
|
||||||
|
# ── ClickUp sync (when triggered from chat with a task ID) ───────────
|
||||||
|
if clickup_task_id and ctx and ctx.get("config") and ctx["config"].clickup.enabled:
|
||||||
|
try:
|
||||||
|
from ..clickup import ClickUpClient
|
||||||
|
|
||||||
|
config = ctx["config"]
|
||||||
|
client = ClickUpClient(
|
||||||
|
api_token=config.clickup.api_token,
|
||||||
|
workspace_id=config.clickup.workspace_id,
|
||||||
|
task_type_field_name=config.clickup.task_type_field_name,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Upload each .docx as an attachment
|
||||||
|
uploaded_count = 0
|
||||||
|
for path in docx_files:
|
||||||
|
if client.upload_attachment(clickup_task_id, path):
|
||||||
|
uploaded_count += 1
|
||||||
|
else:
|
||||||
|
log.warning("ClickUp: failed to upload %s for task %s", path, clickup_task_id)
|
||||||
|
|
||||||
|
# Post a result comment
|
||||||
|
attach_note = f"\n📎 {uploaded_count} file(s) attached." if uploaded_count else ""
|
||||||
|
comment = (
|
||||||
|
f"✅ CheddahBot completed this task (via chat).\n\n"
|
||||||
|
f"Skill: write_press_releases\n"
|
||||||
|
f"Result:\n{'\n'.join(output_parts)[:3000]}{attach_note}"
|
||||||
|
)
|
||||||
|
client.add_comment(clickup_task_id, comment)
|
||||||
|
|
||||||
|
# Update task status to review
|
||||||
|
client.update_task_status(clickup_task_id, config.clickup.review_status)
|
||||||
|
|
||||||
|
# Update kv_store state if one exists
|
||||||
|
db = ctx.get("db")
|
||||||
|
if db:
|
||||||
|
import json as _json
|
||||||
|
kv_key = f"clickup:task:{clickup_task_id}:state"
|
||||||
|
existing = db.kv_get(kv_key)
|
||||||
|
if existing:
|
||||||
|
from datetime import timezone
|
||||||
|
state = _json.loads(existing)
|
||||||
|
state["state"] = "completed"
|
||||||
|
state["completed_at"] = datetime.now(timezone.utc).isoformat()
|
||||||
|
state["deliverable_paths"] = docx_files
|
||||||
|
db.kv_set(kv_key, _json.dumps(state))
|
||||||
|
|
||||||
|
client.close()
|
||||||
|
|
||||||
|
output_parts.append(f"\n## ClickUp Sync\n")
|
||||||
|
output_parts.append(f"- Task `{clickup_task_id}` updated")
|
||||||
|
output_parts.append(f"- {uploaded_count} file(s) uploaded")
|
||||||
|
output_parts.append(f"- Status set to '{config.clickup.review_status}'")
|
||||||
|
|
||||||
|
log.info("ClickUp sync complete for task %s", clickup_task_id)
|
||||||
|
except Exception as e:
|
||||||
|
log.error("ClickUp sync failed for task %s: %s", clickup_task_id, e)
|
||||||
|
output_parts.append(f"\n## ClickUp Sync\n")
|
||||||
|
output_parts.append(f"- **Sync failed:** {e}")
|
||||||
|
output_parts.append("- Press release results are still valid above")
|
||||||
|
|
||||||
return "\n".join(output_parts)
|
return "\n".join(output_parts)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue