Skip to main content
Glama

Postman MCP Generator

by ramborau
send-message-template-media.js6.2 kB
/** * Function to send a message template media via WhatsApp. * * @param {Object} args - Arguments for sending the message. * @param {string} args.recipientPhoneNumber - The phone number of the recipient. * @param {string} args.templateName - The name of the template to be used. * @param {string} args.languageCode - The language and locale code for the template. * @param {string} args.imageUrl - The URL of the image to be included in the message. * @param {string} args.textString - The text string to be included in the message body. * @param {Object} args.currency - The currency object containing fallback value, code, and amount. * @param {Object} args.dateTime - The date-time object containing fallback value and date components. * @returns {Promise<Object>} - The result of the message sending operation. */ const executeFunction = async ({ recipientPhoneNumber, templateName, languageCode, imageUrl, textString, currency, dateTime }) => { const baseUrl = '<API_URL>'; // will be provided by the user const token = process.env.BOTPE_MCP_API_KEY; const version = '<Version>'; // will be provided by the user const businessPhoneNumberId = '<PHONE_NUMBER_ID>'; // will be provided by the user const url = `${baseUrl}/${version}/${businessPhoneNumberId}/messages`; const body = { messaging_product: "whatsapp", recipient_type: "individual", to: recipientPhoneNumber, type: "template", template: { name: templateName, language: { code: languageCode }, components: [ { type: "header", parameters: [ { type: "image", image: { link: imageUrl } } ] }, { type: "body", parameters: [ { type: "text", text: textString }, { type: "currency", currency: { fallback_value: currency.fallbackValue, code: currency.code, amount_1000: currency.amount } }, { type: "date_time", date_time: { fallback_value: dateTime.fallbackValue, day_of_week: dateTime.dayOfWeek, year: dateTime.year, month: dateTime.month, day_of_month: dateTime.dayOfMonth, hour: dateTime.hour, minute: dateTime.minute, calendar: "GREGORIAN" } } ] } ] } }; try { const response = await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${token}` }, body: JSON.stringify(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 message template media:', error); return { error: `An error occurred while sending the message: ${error instanceof Error ? error.message : JSON.stringify(error)}` }; } }; /** * Tool configuration for sending message template media via WhatsApp. * @type {Object} */ const apiTool = { function: executeFunction, definition: { type: 'function', function: { name: 'send_message_template_media', description: 'Send a message template media via WhatsApp.', parameters: { type: 'object', properties: { recipientPhoneNumber: { type: 'string', description: 'The phone number of the recipient.' }, templateName: { type: 'string', description: 'The name of the template to be used.' }, languageCode: { type: 'string', description: 'The language and locale code for the template.' }, imageUrl: { type: 'string', description: 'The URL of the image to be included in the message.' }, textString: { type: 'string', description: 'The text string to be included in the message body.' }, currency: { type: 'object', properties: { fallbackValue: { type: 'string', description: 'The fallback value for the currency.' }, code: { type: 'string', description: 'The currency code.' }, amount: { type: 'integer', description: 'The amount in cents.' } }, required: ['fallbackValue', 'code', 'amount'] }, dateTime: { type: 'object', properties: { fallbackValue: { type: 'string', description: 'The fallback value for the date-time.' }, dayOfWeek: { type: 'integer', description: 'The day of the week (0-6).' }, year: { type: 'integer', description: 'The year.' }, month: { type: 'integer', description: 'The month (1-12).' }, dayOfMonth: { type: 'integer', description: 'The day of the month (1-31).' }, hour: { type: 'integer', description: 'The hour (0-23).' }, minute: { type: 'integer', description: 'The minute (0-59).' } }, required: ['fallbackValue', 'dayOfWeek', 'year', 'month', 'dayOfMonth', 'hour', 'minute'] } }, required: ['recipientPhoneNumber', 'templateName', 'languageCode', 'imageUrl', 'textString', 'currency', 'dateTime'] } } } }; 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