send_message
Send text or media messages to Instagram or Facebook Messenger users using their platform APIs.
Instructions
Send a message to a user on Instagram or Facebook Messenger. Can send text or media (image, video, audio).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| platform | Yes | Platform to send message on | |
| recipientId | Yes | The user ID to send the message to | |
| text | No | Text message content (optional if sending media) | |
| mediaUrl | No | URL of media to send (optional) | |
| mediaType | No | Type of media being sent | |
| isHumanAgent | No | Set to true if message is from human agent (extends messaging window) |
Implementation Reference
- src/index.ts:390-410 (handler)Main handler for the 'send_message' MCP tool. Parses arguments with Zod schema and delegates to platform-specific API functions.case 'send_message': { const params = SendMessageSchema.parse(args); if (params.platform === 'instagram') { result = await api.sendInstagramMessage({ recipientId: params.recipientId, text: params.text, mediaUrl: params.mediaUrl, mediaType: params.mediaType, isHumanAgent: params.isHumanAgent }); } else { result = await api.sendFacebookMessage({ recipientId: params.recipientId, text: params.text, mediaUrl: params.mediaUrl, mediaType: params.mediaType, isHumanAgent: params.isHumanAgent }); } break; }
- src/index.ts:16-23 (schema)Zod schema used for input validation in the send_message handler.const SendMessageSchema = z.object({ platform: z.enum(['instagram', 'facebook']), recipientId: z.string(), text: z.string().optional(), mediaUrl: z.string().optional(), mediaType: z.enum(['image', 'video', 'audio']).optional(), isHumanAgent: z.boolean().optional() });
- src/index.ts:104-119 (registration)Tool registration in the ListTools response, defining name, description, and JSON schema for inputs.{ name: 'send_message', description: 'Send a message to a user on Instagram or Facebook Messenger. Can send text or media (image, video, audio).', inputSchema: { type: 'object', properties: { platform: { type: 'string', enum: ['instagram', 'facebook'], description: 'Platform to send message on' }, recipientId: { type: 'string', description: 'The user ID to send the message to' }, text: { type: 'string', description: 'Text message content (optional if sending media)' }, mediaUrl: { type: 'string', description: 'URL of media to send (optional)' }, mediaType: { type: 'string', enum: ['image', 'video', 'audio'], description: 'Type of media being sent' }, isHumanAgent: { type: 'boolean', description: 'Set to true if message is from human agent (extends messaging window)' } }, required: ['platform', 'recipientId'] } },
- src/facebook-api.ts:78-109 (helper)Core implementation for sending messages (text or media) to Instagram via Facebook Graph API.export async function sendInstagramMessage(options: SendMessageOptions): Promise<any> { const { recipientId, text, mediaUrl, mediaType, isHumanAgent = false } = options; const payload: any = { recipient: { id: recipientId } }; if (text) { payload.message = { text }; } else if (mediaUrl && mediaType) { payload.message = { attachment: { type: mediaType, payload: { url: mediaUrl, is_reusable: true } } }; } if (isHumanAgent) { payload.messaging_type = 'MESSAGE_TAG'; payload.tag = 'HUMAN_AGENT'; } return makeApiCall({ method: 'POST', endpoint: `/me/messages`, data: payload }); }
- src/facebook-api.ts:111-143 (helper)Core implementation for sending messages (text or media) to Facebook Messenger via Facebook Graph API.export async function sendFacebookMessage(options: SendMessageOptions): Promise<any> { const { recipientId, text, mediaUrl, mediaType, isHumanAgent = false } = options; const payload: any = { recipient: { id: recipientId }, access_token: config.fbPageAccessToken }; if (text) { payload.message = { text }; } else if (mediaUrl && mediaType) { payload.message = { attachment: { type: mediaType, payload: { url: mediaUrl, is_reusable: true } } }; } if (isHumanAgent) { payload.messaging_type = 'MESSAGE_TAG'; payload.tag = 'HUMAN_AGENT'; } return makeApiCall({ method: 'POST', endpoint: `/${config.fbPageId}/messages`, data: payload }); }