Skip to main content
Glama
test.tsβ€’3 kB
/** * iMessage Kit Playground * Run with: pnpm tsx src/test.ts */ import { IMessageSDK } from "@photon-ai/imessage-kit"; import { getAllContacts, searchContacts, findContactByPhone, } from "./utils/contacts.js"; const sdk = new IMessageSDK({ debug: false, }); async function main() { console.log("πŸ”Œ iMessage SDK Playground\n"); // ═══════════════════════════════════════════════════════════════ // πŸ“‡ CONTACTS DATABASE // ═══════════════════════════════════════════════════════════════ // Get all contacts const contacts = getAllContacts(); console.log(`πŸ“‡ Found ${contacts.length} contacts in macOS Contacts\n`); // Show first 10 contacts with phone numbers console.log("First 10 contacts:"); for (const contact of contacts.slice(0, 10)) { const phones = contact.phoneNumbers.join(", ") || "no phone"; console.log(` β€’ ${contact.fullName}: ${phones}`); } console.log(); // Search for a contact by name // const results = searchContacts("john"); // console.log(`πŸ” Search "john": ${results.length} results`); // for (const contact of results) { // console.log(` β€’ ${contact.fullName}: ${contact.phoneNumbers.join(", ")}`); // } // Find contact by phone number // const contact = findContactByPhone("+1234567890"); // if (contact) { // console.log(`πŸ“± Found: ${contact.fullName}`); // } // ═══════════════════════════════════════════════════════════════ // πŸ’¬ iMESSAGE SDK // ═══════════════════════════════════════════════════════════════ // List recent chats const chats = await sdk.listChats({ limit: 5 }); console.log("πŸ“± Recent chats:"); for (const chat of chats) { const id = chat.chatId.split(";").pop() || ""; const name = chat.displayName || id; // Try to find contact name if displayName is missing let resolvedName = name; if (!chat.displayName && id) { const contact = findContactByPhone(id); if (contact) { resolvedName = `${contact.fullName} (${id})`; } } console.log(` β€’ ${resolvedName}`); } console.log(); // Get recent messages // const messages = await sdk.getMessages({ limit: 5 }); // console.log("πŸ’¬ Recent messages:"); // for (const msg of messages.messages) { // const sender = msg.isFromMe ? "Me" : msg.senderName || msg.sender; // console.log(` [${sender}]: ${msg.text?.slice(0, 50) || "[attachment]"}`); // } console.log("πŸ‘‹ Done!"); } main().catch(console.error);

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/sameelarif/imessage-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server