UNPKG

@sinch/mcp

Version:

Sinch MCP server

55 lines 3.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.listAllTemplatesHandler = exports.registerListAllTemplates = void 0; const utils_1 = require("../../utils"); const format_list_all_templates_response_1 = require("./utils/format-list-all-templates-response"); const conversation_service_helper_1 = require("./utils/conversation-service-helper"); const types_1 = require("../../types"); const registerListAllTemplates = (server, tags) => { if (!(0, utils_1.hasMatchingTag)(['all', 'conversation', 'notification'], tags)) { return; } server.tool('list-messaging-templates', 'Get a list of all messaging-related templates (omni-channel or channel specific) belonging to an account. Note that the Email templates are NOT included in this list - they can be found with another tool: list-email-templates. Do not try to use this tool to list Email templates, it will not work.', exports.listAllTemplatesHandler); }; exports.registerListAllTemplates = registerListAllTemplates; const listAllTemplatesHandler = async () => { const maybeClient = (0, conversation_service_helper_1.getConversationTemplateService)(); if ((0, utils_1.isPromptResponse)(maybeClient)) { return maybeClient.promptResponse; } const sinchClient = maybeClient; const responseUS = await sinchClient.conversation.templatesV2.list({}); sinchClient.conversation.setRegion('eu'); const responseEU = await sinchClient.conversation.templatesV2.list({}); sinchClient.conversation.setRegion('br'); const responseBR = await sinchClient.conversation.templatesV2.list({}); const replyParts = []; replyParts.push((0, format_list_all_templates_response_1.formatOmniChannelTemplates)(responseUS, responseEU, responseBR)); const whatsAppTemplates = await fetchWhatsAppSpecificTemplates(); replyParts.push((0, format_list_all_templates_response_1.formatChannelSpecificTemplates)(whatsAppTemplates)); replyParts.push(format_list_all_templates_response_1.renderInstructions.trim()); return new types_1.PromptResponse(replyParts.join('\n\n')).promptResponse; }; exports.listAllTemplatesHandler = listAllTemplatesHandler; const fetchWhatsAppSpecificTemplates = async () => { const resp = await fetch(`https://provisioning.api.sinch.com/v1/projects/${process.env.CONVERSATION_PROJECT_ID}/whatsapp/templates`, { method: 'GET', headers: { 'Content-Type': 'application/json', Authorization: 'Basic ' + Buffer.from(`${process.env.CONVERSATION_KEY_ID}:${process.env.CONVERSATION_KEY_SECRET}`).toString('base64') } }); if (!resp.ok) { console.error(`Failed to fetch WhatsApp templates: ${resp.status} ${resp.statusText}`); return []; } const data = (await resp.json()); return data.templates.map((template) => ({ channel: 'WhatsApp', name: template.name, language: template.language, category: template.category, state: template.state, })); }; //# sourceMappingURL=list-messaging-templates.js.map