Browse Source

feat: add comment CRUD tools (add_comment, update_comment, delete_comment)

ShadowMan Service User 2 ngày trước cách đây
mục cha
commit
012a88c92f
3 tập tin đã thay đổi với 108 bổ sung1 xóa
  1. 29 0
      index.js
  2. 39 1
      lib/tasks.js
  3. 40 0
      manifest.json

+ 29 - 0
index.js

@@ -74,3 +74,32 @@ shadowman.tools.register('search_tasks', function(args, context) {
     if (!args.query) return { error: 'Missing query parameter' };
     return tasks.searchTasks(token, args);
 });
+
+// Comment tools
+shadowman.tools.register('add_comment', function(args, context) {
+    var token = auth.getValidToken();
+    if (!token) return { error: 'Not authenticated. Run setup_auth with a grant token first.' };
+    if (!args.project_id) return { error: 'Missing project_id parameter' };
+    if (!args.task_id) return { error: 'Missing task_id parameter' };
+    if (!args.content) return { error: 'Missing content parameter' };
+    return tasks.addComment(token, args.project_id, args.task_id, args.content);
+});
+
+shadowman.tools.register('update_comment', function(args, context) {
+    var token = auth.getValidToken();
+    if (!token) return { error: 'Not authenticated. Run setup_auth with a grant token first.' };
+    if (!args.project_id) return { error: 'Missing project_id parameter' };
+    if (!args.task_id) return { error: 'Missing task_id parameter' };
+    if (!args.comment_id) return { error: 'Missing comment_id parameter' };
+    if (!args.content) return { error: 'Missing content parameter' };
+    return tasks.updateComment(token, args.project_id, args.task_id, args.comment_id, args.content);
+});
+
+shadowman.tools.register('delete_comment', function(args, context) {
+    var token = auth.getValidToken();
+    if (!token) return { error: 'Not authenticated. Run setup_auth with a grant token first.' };
+    if (!args.project_id) return { error: 'Missing project_id parameter' };
+    if (!args.task_id) return { error: 'Missing task_id parameter' };
+    if (!args.comment_id) return { error: 'Missing comment_id parameter' };
+    return tasks.deleteComment(token, args.project_id, args.task_id, args.comment_id);
+});

+ 39 - 1
lib/tasks.js

@@ -263,6 +263,41 @@ function searchTasks(token, args) {
     return { tasks: allTasks, total: allTasks.length, query: query };
 }
 
+function addComment(token, projectId, taskId, content) {
+    var portalId = shadowman.config.value('portal_id');
+    if (!portalId) {
+        return { error: 'Missing portal_id in plugin config.' };
+    }
+    return apiCall(token, 'POST',
+        '/restapi/portal/{PORTALID}/projects/{PROJECTID}/tasks/{TASKID}/comments/'
+        .replace('{PROJECTID}', projectId)
+        .replace('{TASKID}', taskId), { content: content });
+}
+
+function updateComment(token, projectId, taskId, commentId, content) {
+    var portalId = shadowman.config.value('portal_id');
+    if (!portalId) {
+        return { error: 'Missing portal_id in plugin config.' };
+    }
+    return apiCall(token, 'POST',
+        '/restapi/portal/{PORTALID}/projects/{PROJECTID}/tasks/{TASKID}/comments/{COMMENTID}/'
+        .replace('{PROJECTID}', projectId)
+        .replace('{TASKID}', taskId)
+        .replace('{COMMENTID}', commentId), { content: content });
+}
+
+function deleteComment(token, projectId, taskId, commentId) {
+    var portalId = shadowman.config.value('portal_id');
+    if (!portalId) {
+        return { error: 'Missing portal_id in plugin config.' };
+    }
+    return apiCall(token, 'DELETE',
+        '/restapi/portal/{PORTALID}/projects/{PROJECTID}/tasks/{TASKID}/comments/{COMMENTID}/'
+        .replace('{PROJECTID}', projectId)
+        .replace('{TASKID}', taskId)
+        .replace('{COMMENTID}', commentId), {});
+}
+
 module.exports = {
     listProjects: listProjects,
     listTasks: listTasks,
@@ -271,5 +306,8 @@ module.exports = {
     updateTask: updateTask,
     deleteTask: deleteTask,
     getMyTasks: getMyTasks,
-    searchTasks: searchTasks
+    searchTasks: searchTasks,
+    addComment: addComment,
+    updateComment: updateComment,
+    deleteComment: deleteComment
 };

+ 40 - 0
manifest.json

@@ -119,6 +119,46 @@
         "required": ["project_id", "task_id"]
       }
     },
+    {
+      "name": "add_comment",
+      "description": "Add a comment to a task",
+      "parameters": {
+        "type": "object",
+        "properties": {
+          "project_id": { "type": "string", "description": "Zoho Projects project ID" },
+          "task_id": { "type": "string", "description": "Task ID" },
+          "content": { "type": "string", "description": "Comment text (HTML allowed)" }
+        },
+        "required": ["project_id", "task_id", "content"]
+      }
+    },
+    {
+      "name": "update_comment",
+      "description": "Update an existing comment on a task",
+      "parameters": {
+        "type": "object",
+        "properties": {
+          "project_id": { "type": "string", "description": "Zoho Projects project ID" },
+          "task_id": { "type": "string", "description": "Task ID" },
+          "comment_id": { "type": "string", "description": "Comment ID to update" },
+          "content": { "type": "string", "description": "New comment text (HTML allowed)" }
+        },
+        "required": ["project_id", "task_id", "comment_id", "content"]
+      }
+    },
+    {
+      "name": "delete_comment",
+      "description": "Delete a comment from a task",
+      "parameters": {
+        "type": "object",
+        "properties": {
+          "project_id": { "type": "string", "description": "Zoho Projects project ID" },
+          "task_id": { "type": "string", "description": "Task ID" },
+          "comment_id": { "type": "string", "description": "Comment ID to delete" }
+        },
+        "required": ["project_id", "task_id", "comment_id"]
+      }
+    },
     {
       "name": "my_tasks",
       "description": "Get tasks assigned to the authenticated user across all projects",