@sinch/mcp
Version:
Sinch MCP server
41 lines • 2.4 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getMessageEventsHandler = exports.registerGetMessageEvents = void 0;
const zod_1 = require("zod");
const conversation_tools_helper_1 = require("./utils/conversation-tools-helper");
const types_1 = require("../../types");
const better_sqlite3_1 = __importDefault(require("better-sqlite3"));
const path_1 = __importDefault(require("path"));
const tools_config_1 = require("../../tools-config");
const TOOL_KEY = 'getMessageEvents';
const TOOL_NAME = (0, conversation_tools_helper_1.getToolName)(TOOL_KEY);
const registerGetMessageEvents = (server, tags) => {
if (!(0, conversation_tools_helper_1.shouldRegisterTool)(TOOL_KEY, tags))
return;
// Additional check for this tool to be able to open the ngrok tunnel
if (!process.env.NGROK_AUTH_TOKEN) {
tools_config_1.toolsStatusMap[TOOL_NAME] = 'NGROK_AUTH_TOKEN environment variable is not set';
return;
}
server.tool(TOOL_NAME, 'Get the events of a message in a conversation. The events include delivery, read, and other status updates related to the message.', {
messageId: zod_1.z.string().describe('The ID of the message to get the events for'),
}, exports.getMessageEventsHandler);
};
exports.registerGetMessageEvents = registerGetMessageEvents;
const getMessageEventsHandler = async ({ messageId }) => {
const dbPath = path_1.default.join(__dirname, '../../data/webhooks.db');
const db = new better_sqlite3_1.default(dbPath);
const rows = db
.prepare(`SELECT * FROM webhooks_events WHERE message_id = ? ORDER BY event_time ASC`)
.all(messageId);
let reply = 'Here are the events for the message with ID: ' + messageId + ' to present in an array\n\n';
rows.forEach(row => {
reply += `| ID: ${row.id} | Type: ${row.type} | App ID: ${row.app_id} | Event Time: ${row.event_time} | Message ID: ${row.message_id} | Channel Identity: ${row.channel_identity} | Status: ${row.status} | Reason: ${row.reason} | Submitted Message: ${row.submitted_message} |\n`;
});
return new types_1.PromptResponse(reply).promptResponse;
};
exports.getMessageEventsHandler = getMessageEventsHandler;
//# sourceMappingURL=get-message-events.js.map