UNPKG

@sinch/mcp

Version:

Sinch MCP server

63 lines 3.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.sendTextMessageHandler = exports.registerSendTextMessage = void 0; 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 prompt_schemas_1 = require("./prompt-schemas"); const types_1 = require("../../types"); const TOOL_KEY = 'sendTextMessage'; const TOOL_NAME = (0, conversation_tools_helper_1.getToolName)(TOOL_KEY); const registerSendTextMessage = (server, tags) => { if (!(0, utils_1.matchesAnyTag)(tags, conversation_tools_helper_1.toolsConfig[TOOL_KEY].tags)) return; server.tool(TOOL_NAME, 'Send a text message 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.', { recipient: prompt_schemas_1.Recipient, message: prompt_schemas_1.TextMessage, channel: prompt_schemas_1.ConversationChannel, appId: prompt_schemas_1.ConversationAppIdOverride, sender: prompt_schemas_1.MessageSenderNumberOverride, region: prompt_schemas_1.ConversationRegionOverride, }, exports.sendTextMessageHandler); }; exports.registerSendTextMessage = registerSendTextMessage; const sendTextMessageHandler = async ({ recipient, channel, message, 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: { text_message: { text: message } } } }; try { const response = await conversationService.messages.sendTextMessage(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.sendTextMessageHandler = sendTextMessageHandler; //# sourceMappingURL=send-text-message.js.map