Skip to main content
Glama

get_new_comments

Retrieve recent Facebook and Instagram comments to monitor social media engagement and respond to customers promptly.

Instructions

Retrieve new comments from Facebook and Instagram posts for timely responses.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
platformNoOptional: filter by facebook or instagram
sinceHoursNoGet comments from last X hours (default: 24)

Implementation Reference

  • Handler for the 'get_new_comments' tool. Checks configuration, fetches recent Facebook comments using the socialMediaManager, and formats the response with comment details.
    case 'get_new_comments': { if (!socialMediaManager.isConfigured()) { return { content: [{ type: 'text', text: `⚠️ Social media not configured. See FACEBOOK_INSTAGRAM_SETUP.md for setup instructions.` }] }; } const sinceHours = Number(args?.sinceHours || 24); try { const comments = await socialMediaManager.getFacebookComments(sinceHours); if (comments.length === 0) { return { content: [{ type: 'text', text: `✅ No new comments in the last ${sinceHours} hours. All caught up!` }] }; } return { content: [{ type: 'text', text: `💬 New Comments (Last ${sinceHours} hours)\n\n${comments.map((comment, i) => `${i + 1}. From ${comment.from} on ${comment.platform}\n "${comment.text}"\n 🕐 ${new Date(comment.timestamp).toLocaleString()}` ).join('\n\n')}\n\n💡 Use 'suggest_comment_reply' to get AI-powered reply suggestions!` }] }; } catch (error: any) { return { content: [{ type: 'text', text: `❌ Failed to fetch comments: ${error.message}` }] }; }
  • Input schema definition for the 'get_new_comments' tool, specifying parameters like sinceHours and platform.
    name: 'get_new_comments', description: 'Retrieve new comments from Facebook and Instagram posts for timely responses.', inputSchema: { type: 'object', properties: { sinceHours: { type: 'number', description: 'Get comments from last X hours (default: 24)' }, platform: { type: 'string', description: 'Optional: filter by facebook or instagram' }, }, }, },
  • src/index.ts:516-518 (registration)
    Registration of the ListToolsRequestHandler which exposes all tools including 'get_new_comments' via the tools array.
    server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools }; });
  • Helper function getFacebookComments in SocialMediaManager class that implements the core logic to fetch recent comments from Facebook Graph API, filtering by time.
    async getFacebookComments(sinceHours: number = 24): Promise<Comment[]> { if (!this.isConfigured()) { throw new Error('Facebook API not configured'); } try { const url = `https://graph.facebook.com/${this.apiVersion}/${this.fbPageId}/feed`; const params = new URLSearchParams({ fields: 'id,message,comments{message,from,created_time}', access_token: this.fbPageToken, limit: '25' }); const response = await fetch(`${url}?${params}`); const result = await response.json() as any; const comments: Comment[] = []; if (result.data) { const cutoffTime = Date.now() - (sinceHours * 60 * 60 * 1000); for (const post of result.data) { if (post.comments && post.comments.data) { for (const comment of post.comments.data) { const commentTime = new Date(comment.created_time).getTime(); if (commentTime > cutoffTime) { comments.push({ id: comment.id, text: comment.message, from: comment.from.name, timestamp: comment.created_time, platform: 'facebook' }); } } } } } return comments; } catch (error: any) { throw new Error(`Failed to fetch comments: ${error.message}`); } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/wspotter/mcpart'

If you have feedback or need assistance with the MCP directory API, please join our Discord server