create_message
Send messages in Webex rooms by specifying room ID, text, or attachments. Supports replies, markdown formatting, and file attachments for effective communication.
Instructions
Create a message in a Webex room.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| attachments | No | An array of attachment objects. | |
| files | No | An array of file URLs to attach to the message. | |
| markdown | No | The message in markdown format. | |
| parentId | No | The ID of the parent message (if this is a reply). | |
| roomId | Yes | The ID of the room where the message will be sent. | |
| text | Yes | The plain text message to send. | |
| toPersonEmail | No | The email of the person to whom the message is directed. | |
| toPersonId | No | The ID of the person to whom the message is directed. |
Implementation Reference
- The executeFunction that implements the core logic of the 'create_message' tool. It constructs a payload from input parameters and sends a POST request to the Webex /messages endpoint using fetch, handling errors and returning the API response.const executeFunction = async ({ roomId, parentId, toPersonId, toPersonEmail, text, markdown, files = [], attachments = [] }) => { try { // Debug: Log received parameters console.error('[DEBUG] create-a-message received parameters:', { roomId, parentId, toPersonId, toPersonEmail, text, markdown, files, attachments }); // Construct the message payload (only include defined parameters) const payload = {}; if (roomId) payload.roomId = roomId; if (parentId) payload.parentId = parentId; if (toPersonId) payload.toPersonId = toPersonId; if (toPersonEmail) payload.toPersonEmail = toPersonEmail; if (text) payload.text = text; if (markdown) payload.markdown = markdown; if (files && files.length > 0) payload.files = files; if (attachments && attachments.length > 0) payload.attachments = attachments; // Get the API URL and headers using the centralized config const url = getWebexUrl('/messages'); const headers = getWebexJsonHeaders(); // Perform the fetch request const response = await fetch(url, { method: 'POST', headers, body: JSON.stringify(payload) }); // Check if the response was successful if (!response.ok) { const errorText = await response.text(); let errorMessage = `HTTP ${response.status}: ${response.statusText}`; try { const errorData = JSON.parse(errorText); errorMessage = errorData.message || errorData.error || JSON.stringify(errorData); } catch (e) { errorMessage = errorText || errorMessage; } throw new Error(errorMessage); } // Parse and return the response data const data = await response.json(); return data; } catch (error) { console.error('Error creating message:', error); return { error: error.message || 'An error occurred while creating the message.', details: error.stack }; } };
- The JSON schema definition for the 'create_message' tool, including input parameters with types, descriptions, and required fields.type: 'function', function: { name: 'create_message', description: 'Create a message in a Webex room.', parameters: { type: 'object', properties: { roomId: { type: 'string', description: 'The ID of the room where the message will be sent.' }, parentId: { type: 'string', description: 'The ID of the parent message (if this is a reply).' }, toPersonId: { type: 'string', description: 'The ID of the person to whom the message is directed.' }, toPersonEmail: { type: 'string', description: 'The email of the person to whom the message is directed.' }, text: { type: 'string', description: 'The plain text message to send.' }, markdown: { type: 'string', description: 'The message in markdown format.' }, files: { type: 'array', items: { type: 'string' }, description: 'An array of file URLs to attach to the message.' }, attachments: { type: 'array', items: { type: 'object' }, description: 'An array of attachment objects.' } }, required: ['text'] } } }
- The apiTool constant that bundles the handler function and schema definition, exported for use in tool registration (likely loaded dynamically in the MCP server).const apiTool = { function: executeFunction, definition: { type: 'function', function: { name: 'create_message', description: 'Create a message in a Webex room.', parameters: { type: 'object', properties: { roomId: { type: 'string', description: 'The ID of the room where the message will be sent.' }, parentId: { type: 'string', description: 'The ID of the parent message (if this is a reply).' }, toPersonId: { type: 'string', description: 'The ID of the person to whom the message is directed.' }, toPersonEmail: { type: 'string', description: 'The email of the person to whom the message is directed.' }, text: { type: 'string', description: 'The plain text message to send.' }, markdown: { type: 'string', description: 'The message in markdown format.' }, files: { type: 'array', items: { type: 'string' }, description: 'An array of file URLs to attach to the message.' }, attachments: { type: 'array', items: { type: 'object' }, description: 'An array of attachment objects.' } }, required: ['text'] } } } }; export { apiTool };
- Import of helper functions getWebexUrl and getWebexJsonHeaders from lib/webex-config.js, used to obtain the API endpoint and authorization headers.import { getWebexUrl, getWebexJsonHeaders } from '../../../lib/webex-config.js';