UNPKG

@sinch/mcp

Version:

Sinch MCP server

64 lines 3.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.sendMediaMessageHandler = exports.registerSendMediaMessage = void 0; const zod_1 = require("zod"); const prompt_schemas_1 = require("./prompt-schemas"); const conversation_service_helper_1 = require("./utils/conversation-service-helper"); const conversation_tools_helper_1 = require("./utils/conversation-tools-helper"); const utils_1 = require("../../utils"); const send_message_builder_1 = require("./utils/send-message-builder"); const types_1 = require("../../types"); const TOOL_KEY = 'sendMediaMessage'; const TOOL_NAME = (0, conversation_tools_helper_1.getToolName)(TOOL_KEY); const registerSendMediaMessage = (server, tags) => { if (!(0, utils_1.matchesAnyTag)(tags, conversation_tools_helper_1.toolsConfig[TOOL_KEY].tags)) return; server.tool(TOOL_NAME, 'Send a media message from URL given in parameter to a contact on the specified channel. The contact can be a phone number in E.164 format, or the identifier for the specified channel. The media must be specified with its URL.', { recipient: prompt_schemas_1.Recipient, url: zod_1.z.string().describe('The URL of the media that will be the content of the message.'), channel: prompt_schemas_1.ConversationChannel, appId: prompt_schemas_1.ConversationAppIdOverride, sender: prompt_schemas_1.MessageSenderNumberOverride, region: prompt_schemas_1.ConversationRegionOverride }, exports.sendMediaMessageHandler); }; exports.registerSendMediaMessage = registerSendMediaMessage; const sendMediaMessageHandler = async ({ recipient, channel, url, appId, sender, region }) => { const maybeAppId = (0, conversation_service_helper_1.getConversationAppId)(appId); if ((0, utils_1.isPromptResponse)(maybeAppId)) { return maybeAppId.promptResponse; } const conversationAppId = maybeAppId; const maybeService = (0, conversation_service_helper_1.getConversationService)(TOOL_NAME); if ((0, utils_1.isPromptResponse)(maybeService)) { return maybeService.promptResponse; } const conversationService = maybeService; const usedRegion = (0, conversation_service_helper_1.setConversationRegion)(region, conversationService); const requestBase = await (0, send_message_builder_1.buildMessageBase)(conversationService, conversationAppId, recipient, channel, sender); const request = { sendMessageRequestBody: { ...requestBase, message: { media_message: { url: url } } } }; try { const response = await conversationService.messages.sendMediaMessage(request); return new types_1.PromptResponse(JSON.stringify({ success: true, message_id: response.message_id })).promptResponse; } catch (error) { return new types_1.PromptResponse(JSON.stringify({ success: false, error: (error instanceof Error ? error.message : String(error)) + `. Are you sure you are using the right region to send your message? The current region is ${usedRegion}.` })).promptResponse; } }; exports.sendMediaMessageHandler = sendMediaMessageHandler; //# sourceMappingURL=send-media-message.js.map