UNPKG

@sinch/mcp

Version:

Sinch MCP server

55 lines 2.87 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 (!tags.includes('all') && !tags.includes('conversation') && !tags.includes('notification')) { return; } server.tool('list-all-templates', 'Get a list of all templates (omni-channel or channel specific) belonging to an account', 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-templates.js.map