UNPKG

@sinch/mcp

Version:

Sinch MCP server

110 lines 6.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.sendContactInfoMessageHandler = exports.registerSendContactInfoMessage = void 0; const zod_1 = require("zod"); const conversation_service_helper_1 = require("./utils/conversation-service-helper"); const send_message_builder_1 = require("./utils/send-message-builder"); const utils_1 = require("../../utils"); const prompt_schemas_1 = require("./prompt-schemas"); const types_1 = require("../../types"); const NameModel = zod_1.z.object({ fullName: zod_1.z.string().describe('Full name of the contact.'), firstName: zod_1.z.string().optional().describe('First name of the contact.'), lastName: zod_1.z.string().optional().describe('Last name of the contact.'), middleName: zod_1.z.string().optional().describe('Middle name of the contact.'), prefix: zod_1.z.string().optional().describe('Prefix of the contact.'), suffix: zod_1.z.string().optional().describe('Suffix of the contact.') }); const PhoneNumberModel = zod_1.z.object({ phoneNumber: zod_1.z.string().describe('Phone number of the contact with country code included.'), type: zod_1.z.string().optional().describe('Type of the phone number, e.g., mobile, home, work.') }); const EmailAddressModel = zod_1.z.object({ emailAddress: zod_1.z.string().describe('Email address of the contact.'), type: zod_1.z.string().optional().describe('Type of the email address, e.g., mobile, home, work.') }); const AddressModel = zod_1.z.object({ city: zod_1.z.string().optional().describe('City of the contact.'), country: zod_1.z.string().optional().describe('Country of the contact.'), state: zod_1.z.string().optional().describe('State of the contact.'), zipCode: zod_1.z.string().optional().describe('ZIP code of the contact.'), type: zod_1.z.string().optional().describe('Type of the address, e.g., home, work.'), countryCode: zod_1.z.string().optional().describe('Two letters country code of the contact.') }); const registerSendContactInfoMessage = (server, tags) => { if (!tags.includes('all') && !tags.includes('conversation') && !tags.includes('notification')) { return; } server.tool('send-contact-info-message', 'Send a contact info message to a recipient.', { recipient: prompt_schemas_1.Recipient, channel: prompt_schemas_1.ConversationChannel, contactName: NameModel.describe('The name of the contact.'), contactPhoneNumbers: zod_1.z.array(PhoneNumberModel).describe('Array of contact\'s phone numbers (E.164 format).'), contactEmailAddresses: zod_1.z.array(EmailAddressModel).optional().describe('Array of contact\'s email addresses.'), contactAddresses: zod_1.z.array(AddressModel).optional().describe('Array of contact\'s physical addresses.'), appId: prompt_schemas_1.ConversationAppIdOverride, sender: prompt_schemas_1.MessageSenderNumberOverride, region: prompt_schemas_1.ConversationRegionOverride, }, exports.sendContactInfoMessageHandler); }; exports.registerSendContactInfoMessage = registerSendContactInfoMessage; const sendContactInfoMessageHandler = async ({ recipient, channel, contactName, contactPhoneNumbers, contactEmailAddresses, contactAddresses, 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 maybeClient = (0, conversation_service_helper_1.getConversationService)(); if ((0, utils_1.isPromptResponse)(maybeClient)) { return maybeClient.promptResponse; } const sinchClient = maybeClient; const conversationRegion = (0, conversation_service_helper_1.getConversationRegion)(region); sinchClient.conversation.setRegion(conversationRegion); const requestBase = await (0, send_message_builder_1.buildMessageBase)(sinchClient, conversationAppId, recipient, channel, sender); const request = { sendMessageRequestBody: { ...requestBase, message: { contact_info_message: { name: { full_name: contactName.fullName, first_name: contactName.firstName, last_name: contactName.lastName, middle_name: contactName.middleName, prefix: contactName.prefix, suffix: contactName.suffix }, phone_numbers: contactPhoneNumbers.map(phone => ({ phone_number: phone.phoneNumber, type: phone.type })), email_addresses: contactEmailAddresses?.map(email => ({ email_address: email.emailAddress, type: email.type })) || [], addresses: contactAddresses?.map(address => ({ city: address.city, country: address.country, state: address.state, zip_code: address.zipCode, type: address.type, country_code: address.countryCode })) || [] } } } }; let response; let reply; try { response = await sinchClient.conversation.messages.sendContactInfoMessage(request); reply = `Contact Info message submitted on channel ${channel}! The message ID is ${response.message_id}`; } catch (error) { reply = `An error occurred when trying to send the text message: ${JSON.stringify(error)}. Are you sure you are using the right region to send your message? The current region is ${region}.`; } return new types_1.PromptResponse(reply).promptResponse; }; exports.sendContactInfoMessageHandler = sendContactInfoMessageHandler; //# sourceMappingURL=send-contact-info-message.js.map