该提交实现了完整的ClickUp聊天渠道插件,包含以下核心功能: 1. 基础的@提及提取与格式化能力 2. 账号配对与会话管理 3. 消息流与流式回复支持 4. 重试限流与消息去重 5. 富文本格式转换与内容 sanitize 6. 安全策略与配置校验 7. Webhook接收与自动轮询回退 8. 消息收发、编辑、删除与回复 9. 频道与私信管理、反应功能 10. 完整的状态监控与健康检查
71 lines
2.1 KiB
Python
71 lines
2.1 KiB
Python
import logging
|
|
|
|
import httpx
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
API_V3_BASE = "https://api.clickup.com/api/v3"
|
|
|
|
|
|
async def add_reaction(
|
|
workspace_id: str,
|
|
message_id: str,
|
|
reaction: str,
|
|
api_token: str,
|
|
) -> bool:
|
|
url = f"{API_V3_BASE}/workspaces/{workspace_id}/chat/messages/{message_id}/reactions"
|
|
|
|
headers = {"Authorization": api_token, "Content-Type": "application/json"}
|
|
payload = {"reaction": reaction.lower()}
|
|
|
|
async with httpx.AsyncClient(timeout=15.0) as client:
|
|
try:
|
|
resp = await client.post(url, json=payload, headers=headers)
|
|
if resp.status_code == 201:
|
|
return True
|
|
logger.error("ClickUp add_reaction failed: status=%d", resp.status_code)
|
|
return False
|
|
except Exception as e:
|
|
logger.exception("ClickUp add_reaction exception: %s", e)
|
|
return False
|
|
|
|
|
|
async def get_reactions(
|
|
workspace_id: str,
|
|
message_id: str,
|
|
api_token: str,
|
|
) -> list[dict]:
|
|
url = f"{API_V3_BASE}/workspaces/{workspace_id}/chat/messages/{message_id}/reactions"
|
|
|
|
headers = {"Authorization": api_token}
|
|
|
|
async with httpx.AsyncClient(timeout=15.0) as client:
|
|
try:
|
|
resp = await client.get(url, headers=headers)
|
|
if resp.status_code == 200:
|
|
data = resp.json()
|
|
return data.get("reactions", [])
|
|
return []
|
|
except Exception as e:
|
|
logger.exception("ClickUp get_reactions exception: %s", e)
|
|
return []
|
|
|
|
|
|
async def remove_reaction(
|
|
workspace_id: str,
|
|
message_id: str,
|
|
reaction: str,
|
|
api_token: str,
|
|
) -> bool:
|
|
url = f"{API_V3_BASE}/workspaces/{workspace_id}/chat/messages/{message_id}/reactions/{reaction.lower()}"
|
|
|
|
headers = {"Authorization": api_token}
|
|
|
|
async with httpx.AsyncClient(timeout=15.0) as client:
|
|
try:
|
|
resp = await client.delete(url, headers=headers)
|
|
return resp.status_code == 204
|
|
except Exception as e:
|
|
logger.exception("ClickUp remove_reaction exception: %s", e)
|
|
return False
|