Skip to main content
Glama

Postman MCP Generator

by ramborau
send-text-message.js2.4 kB
/** * Function to send a text message via WhatsApp. * * @param {Object} args - Arguments for sending the message. * @param {string} args.recipientPhoneNumber - The phone number of the recipient. * @param {string} args.messageContent - The content of the text message to be sent. * @returns {Promise<Object>} - The response from the API after sending the message. */ const executeFunction = async ({ recipientPhoneNumber, messageContent }) => { const baseUrl = '<API_URL>'; // will be provided by the user const version = '<Version>'; // will be provided by the user const businessPhoneNumberId = '<PHONE_NUMBER_ID>'; // will be provided by the user const token = process.env.BOTPE_MCP_API_KEY; try { const url = `${baseUrl}/${version}/${businessPhoneNumberId}/messages`; const headers = { 'Content-Type': 'application/json', 'Authorization': `Bearer ${token}` }; const body = JSON.stringify({ messaging_product: "whatsapp", recipient_type: "individual", to: recipientPhoneNumber, type: "text", text: { preview_url: false, body: messageContent } }); const response = await fetch(url, { method: 'POST', headers, body }); if (!response.ok) { const errorData = await response.json(); throw new Error(JSON.stringify(errorData)); } const data = await response.json(); return data; } catch (error) { console.error('Error sending text message:', error); return { error: `An error occurred while sending the text message: ${error instanceof Error ? error.message : JSON.stringify(error)}` }; } }; /** * Tool configuration for sending text messages via WhatsApp. * @type {Object} */ const apiTool = { function: executeFunction, definition: { type: 'function', function: { name: 'send_text_message', description: 'Send a text message via WhatsApp.', parameters: { type: 'object', properties: { recipientPhoneNumber: { type: 'string', description: 'The phone number of the recipient.' }, messageContent: { type: 'string', description: 'The content of the text message to be sent.' } }, required: ['recipientPhoneNumber', 'messageContent'] } } } }; export { apiTool };

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/ramborau/botpe-mcp-2'

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