UNPKG

@sinch/mcp

Version:

Sinch MCP server

82 lines 3.53 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.conferenceCalloutHandler = exports.registerConferenceCallout = void 0; const crypto_1 = __importDefault(require("crypto")); const zod_1 = require("zod"); const voice_service_helper_1 = require("./utils/voice-service-helper"); const utils_1 = require("../../utils"); const types_1 = require("../../types"); const registerConferenceCallout = (server, tags) => { if (!(0, utils_1.hasMatchingTag)(['all', 'voice'], tags)) { return; } server.tool('conference-call', 'Call a phone number and connects it to a conference room when answered', { phoneNumbers: zod_1.z.array(zod_1.z.string()).describe('The phone numbers to call and connect to the conference room'), conferenceId: zod_1.z.string().optional().describe('The conference room ID. If not provided, a new one will be generated.'), }, exports.conferenceCalloutHandler); }; exports.registerConferenceCallout = registerConferenceCallout; const conferenceCalloutHandler = async ({ phoneNumbers, conferenceId }) => { const maybeVoiceService = (0, voice_service_helper_1.getVoiceService)(); if ((0, utils_1.isPromptResponse)(maybeVoiceService)) { return maybeVoiceService.promptResponse; } const voiceService = maybeVoiceService; const cli = process.env.CALLING_LINE_IDENTIFICATION; if (!conferenceId) { conferenceId = crypto_1.default.randomUUID(); } const errors = []; const successfulCalls = []; for (const phoneNumber of phoneNumbers) { const request = { conferenceCalloutRequestBody: { method: 'conferenceCallout', conferenceCallout: { destination: { type: 'number', endpoint: phoneNumber }, conferenceId } } }; if (cli) { request.conferenceCalloutRequestBody.conferenceCallout.cli = cli; } try { const response = await voiceService.callouts.conference(request); if (response.callId) { successfulCalls.push({ phoneNumber: request.conferenceCalloutRequestBody.conferenceCallout.destination.endpoint, callId: response.callId }); } } catch (error) { errors.push({ phoneNumber: request.conferenceCalloutRequestBody.conferenceCallout.destination.endpoint, error: error.message }); } } let result = ''; if (successfulCalls.length > 0) { result += `Here is the list of phone numbers joining the conference ${conferenceId} and their associated callId (to be presented as a table):\n`; for (const call of successfulCalls) { result += `- ${call.phoneNumber} | ${call.callId}\n`; } } if (errors.length > 0) { result += '\nThe following phone numbers couldn\'t be called (to be presented with a list and error message):\n'; for (const err of errors) { result += `- ${err.phoneNumber}\n`; } } return new types_1.PromptResponse(result).promptResponse; }; exports.conferenceCalloutHandler = conferenceCalloutHandler; //# sourceMappingURL=conference.js.map