Skip to main content

getChats

Retrieve a list of chat conversations with optional filtering and pagination.
await sdk.chats.getChats(options?): Promise<ChatResponse[]>

Parameters

options
object
Optional configuration for querying chats
withLastMessage
boolean
Include the last message in each chat response
withArchived
boolean
Include archived chats in the results
offset
number
Number of chats to skip for pagination
limit
number
Maximum number of chats to return
sort
string
Sort order for the chats

Returns

chats
ChatResponse[]
Array of chat objects
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)
messages
MessageResponse[]
Array of messages (if requested)
lastMessage
MessageResponse
Most recent message in the chat (if withLastMessage is true)
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 all chats with last message
const chats = await sdk.chats.getChats({
  withLastMessage: true,
  limit: 50
});

console.log(`Found ${chats.length} chats`);
chats.forEach(chat => {
  console.log(`${chat.displayName}: ${chat.lastMessage?.text}`);
});

// Get chats with pagination
const page1 = await sdk.chats.getChats({
  offset: 0,
  limit: 20
});

const page2 = await sdk.chats.getChats({
  offset: 20,
  limit: 20
});

// Include archived chats
const allChats = await sdk.chats.getChats({
  withArchived: true
});

getChatCount

Get the total count of chats with optional breakdown.
await sdk.chats.getChatCount(options?): Promise<{ total: number; breakdown: Record<string, number> }>

Parameters

options
object
Optional configuration for counting chats
includeArchived
boolean
Include archived chats in the count

Returns

result
object
Chat count information
total
number
Total number of chats
breakdown
Record<string, number>
Breakdown of chat counts by category

Example

import { SDK } from '@photon-ai/advanced-imessage-kit';

const sdk = SDK({ serverUrl: 'http://localhost:1234' });

// Get total chat count
const count = await sdk.chats.getChatCount();
console.log(`Total chats: ${count.total}`);
console.log('Breakdown:', count.breakdown);

// Include archived chats in count
const fullCount = await sdk.chats.getChatCount({
  includeArchived: true
});
console.log(`Total chats (including archived): ${fullCount.total}`);

Build docs developers (and LLMs) love