Skip to main content

getChat

Retrieve a specific chat by its GUID with optional related data.
await sdk.chats.getChat(guid, options?): Promise<ChatResponse>

Parameters

guid
string
required
Unique identifier of the chat to retrieve
options
object
Optional configuration for what to include
with
string[]
Array of related data to include (e.g., [‘participants’, ‘messages’])

Returns

chat
ChatResponse
Chat object with requested data
originalROWID
number
Database row ID
guid
string
Unique identifier for the chat
chatIdentifier
string
Chat identifier string
displayName
string
Display name of the chat
style
number
Chat style (0 = individual, 43 = group)
isArchived
boolean
Whether the chat is archived
isFiltered
boolean
Whether the chat is filtered
groupId
string
Group identifier for group chats
participants
HandleResponse[]
Array of participant handles (if requested with ‘participants’)
messages
MessageResponse[]
Array of messages (if requested with ‘messages’)
lastMessage
MessageResponse
Most recent message in the chat
lastAddressedHandle
string | null
Last addressed handle in the chat
properties
object[] | null
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

chatGuid
string
required
Unique identifier of the chat
options
object
Optional configuration for querying messages
offset
number
Number of messages to skip for pagination
limit
number
Maximum number of messages to return
sort
'ASC' | 'DESC'
Sort order for messages (ascending or descending by date)
before
number
Only return messages before this timestamp (milliseconds)
after
number
Only return messages after this timestamp (milliseconds)
with
string[]
Array of related data to include (e.g., [‘attachments’, ‘handle’])

Returns

messages
MessageResponse[]
Array of message objects

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`);

Build docs developers (and LLMs) love