@sinch/mcp
Version:
Sinch MCP server
60 lines • 3.1 kB
JavaScript
;
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 utils_1 = require("../../utils");
const send_message_builder_1 = require("./utils/send-message-builder");
const types_1 = require("../../types");
const registerSendMediaMessage = (server, tags) => {
if (!(0, utils_1.hasMatchingTag)(['all', 'conversation', 'notification'], tags)) {
return;
}
server.tool('send-media-message', '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 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: {
media_message: {
url: url
}
}
}
};
let response;
let reply;
try {
response = await sinchClient.conversation.messages.sendMediaMessage(request);
reply = `Media message submitted on channel ${channel}! The message ID is ${response.message_id}`;
}
catch (error) {
reply = `An error occurred when trying to send the media 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.sendMediaMessageHandler = sendMediaMessageHandler;
//# sourceMappingURL=send-media-message.js.map