send_linkedin_post_comment
Post comments on LinkedIn posts and replies to engage with content using your LinkedIn account. Add your perspective to discussions and interact with professional content.
Instructions
Create a comment on a LinkedIn post or on another comment. Account ID is taken from environment.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | Comment text | |
| timeout | No | Timeout in seconds | |
| urn | Yes | URN of the activity or comment to comment on (e.g., 'activity:123' or 'comment:(activity:123,456)') |
Implementation Reference
- src/index.ts:932-970 (handler)Primary implementation: server.tool registration including Zod input schema, description, and async handler function. Validates post URN format, constructs request with account_id, calls API endpoint to send comment, returns response or error."send_linkedin_post_comment", "Comment on LinkedIn post (requires ACCOUNT_ID)", { post: z.string().describe("Post URN (activity: or comment:)"), text: z.string().describe("Comment text"), timeout: z.number().default(300).describe("Timeout in seconds") }, async ({ post, text, timeout }) => { const isActivityOrComment = post.includes("activity:") || post.includes("comment:"); if (!isActivityOrComment) { return { content: [{ type: "text", text: "URN must be for an activity or comment" }], isError: true }; } let urnObj; if (post.startsWith("activity:")) { urnObj = { type: "activity", value: post.replace("activity:", "") }; } else if (post.startsWith("comment:")) { urnObj = { type: "comment", value: post.replace("comment:", "") }; } else { urnObj = post; } const requestData = { timeout, text, urn: urnObj, account_id: ACCOUNT_ID }; log(`Creating LinkedIn comment on ${post}`); try { const response = await makeRequest(API_CONFIG.ENDPOINTS.POST_COMMENT, requestData); return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] }; } catch (error) { log("LinkedIn comment creation error:", error); return { content: [{ type: "text", text: `LinkedIn comment API error: ${formatError(error)}` }], isError: true }; } } );
- src/types.ts:69-73 (schema)TypeScript type definition for the tool input arguments (note: 'urn' vs 'post' in handler).export interface SendLinkedinPostCommentArgs { text: string; urn: string; timeout?: number; }
- src/types.ts:541-550 (schema)Type guard function for validating SendLinkedinPostCommentArgs input (TypeScript runtime checks).export function isValidSendLinkedinPostCommentArgs( args: unknown ): args is SendLinkedinPostCommentArgs { if (typeof args !== "object" || args === null) return false; const obj = args as Record<string, unknown>; if (typeof obj.text !== "string" || !obj.text.trim()) return false; if (typeof obj.urn !== "string" || !obj.urn.trim()) return false; if (obj.timeout !== undefined && typeof obj.timeout !== "number") return false; return true; }
- src/index.ts:100-145 (helper)Shared HTTP request helper function used by the handler to POST to the AnySite API endpoints with authentication.const makeRequest = (endpoint: string, data: any, method: string = "POST"): Promise<any> => { return new Promise((resolve, reject) => { const url = new URL(endpoint, API_CONFIG.BASE_URL); const postData = JSON.stringify(data); const options = { hostname: url.hostname, port: url.port || 443, path: url.pathname, method: method, headers: { "Content-Type": "application/json", "Content-Length": Buffer.byteLength(postData), "access-token": API_KEY, ...(ACCOUNT_ID && { "x-account-id": ACCOUNT_ID }) } }; const req = https.request(options, (res) => { let responseData = ""; res.on("data", (chunk) => { responseData += chunk; }); res.on("end", () => { try { const parsed = JSON.parse(responseData); if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) { resolve(parsed); } else { reject(new Error(`API error ${res.statusCode}: ${JSON.stringify(parsed)}`)); } } catch (e) { reject(new Error(`Failed to parse response: ${responseData}`)); } }); }); req.on("error", (error) => { reject(error); }); req.write(postData); req.end(); }); };
- src/index.ts:35-35 (helper)API endpoint constant used in the request: POST /api/linkedin/management/post/comment/POST_COMMENT: "/api/linkedin/management/post/comment",