getChat
Retrieve a specific chat by its GUID with optional related data.
await sdk.chats.getChat(guid, options?): Promise<ChatResponse>
Parameters
Unique identifier of the chat to retrieve
Optional configuration for what to includeArray of related data to include (e.g., [‘participants’, ‘messages’])
Returns
Chat object with requested dataUnique identifier for the chat
Chat style (0 = individual, 43 = group)
Whether the chat is archived
Whether the chat is filtered
Group identifier for group chats
Array of participant handles (if requested with ‘participants’)
Array of messages (if requested with ‘messages’)
Most recent message in the chat
Last addressed handle in the chat
Additional chat properties
Example
import { SDK } from '@photon-ai/advanced-imessage-kit';
const sdk = SDK({ serverUrl: 'http://localhost:1234' });
// Get basic chat info
const chat = await sdk.chats.getChat('iMessage;+;chat123456');
console.log(`Chat name: ${chat.displayName}`);
// Get chat with participants
const chatWithParticipants = await sdk.chats.getChat('iMessage;+;chat123456', {
with: ['participants']
});
console.log('Participants:', chatWithParticipants.participants);
// Get chat with participants and messages
const fullChat = await sdk.chats.getChat('iMessage;+;chat123456', {
with: ['participants', 'messages']
});
console.log(`Chat has ${fullChat.messages?.length} messages`);
getChatMessages
Retrieve messages from a specific chat with filtering and pagination options.
await sdk.chats.getChatMessages(chatGuid, options?): Promise<MessageResponse[]>
Parameters
Unique identifier of the chat
Optional configuration for querying messagesNumber of messages to skip for pagination
Maximum number of messages to return
Sort order for messages (ascending or descending by date)
Only return messages before this timestamp (milliseconds)
Only return messages after this timestamp (milliseconds)
Array of related data to include (e.g., [‘attachments’, ‘handle’])
Returns
Example
import { SDK } from '@photon-ai/advanced-imessage-kit';
const sdk = SDK({ serverUrl: 'http://localhost:1234' });
const chatGuid = 'iMessage;+;chat123456';
// Get latest 50 messages
const recentMessages = await sdk.chats.getChatMessages(chatGuid, {
limit: 50,
sort: 'DESC'
});
// Get messages with pagination
const page1 = await sdk.chats.getChatMessages(chatGuid, {
offset: 0,
limit: 25,
sort: 'ASC'
});
// Get messages in a date range
const lastWeek = Date.now() - (7 * 24 * 60 * 60 * 1000);
const messages = await sdk.chats.getChatMessages(chatGuid, {
after: lastWeek,
sort: 'DESC'
});
// Get messages with attachments
const messagesWithAttachments = await sdk.chats.getChatMessages(chatGuid, {
with: ['attachments'],
limit: 100
});
console.log(`Retrieved ${messagesWithAttachments.length} messages`);