getMessageStats()
Retrieves overall message statistics from the server.
const stats = await sdk . server . getMessageStats ();
Returns
Message statistics including totals, sent, and received counts Show Message Statistics Object
Total number of messages in the database Example: 15420
Number of messages sent by you Example: 8234
Number of messages received from others Example: 7186
Retrieves statistics about media attachments across all chats.
const mediaStats = await sdk . server . getMediaStatistics ();
Parameters
Options to filter the media statistics Array of MIME type prefixes to filter by Example: ["image", "video"]
Returns
Media statistics aggregated across all conversations The structure varies based on the media types present. Common fields include counts and sizes for different media types.
Example
Get statistics only for images and videos:
const imageVideoStats = await sdk . server . getMediaStatistics ({
only: [ 'image' , 'video' ]
});
Retrieves media statistics broken down by individual chat.
const statsByChat = await sdk . server . getMediaStatisticsByChat ();
Parameters
Options to filter the media statistics Array of MIME type prefixes to filter by Example: ["image", "video"]
Returns
Media statistics organized by chat GUID Each key is a chat GUID, and the value contains media statistics for that specific chat.
Example
Get per-chat statistics for documents only:
const docStats = await sdk . server . getMediaStatisticsByChat ({
only: [ 'application' ]
});
getServerLogs()
Retrieves recent server log entries.
const logs = await sdk . server . getServerLogs ( 50 );
Parameters
Number of log entries to retrieve Default: Returns all available logs Example: 50
Returns
Array of log entry strings, ordered from most recent to oldest
Examples
Complete Server Statistics Overview
Get and display all server statistics:
import { AdvancedIMessageKit } from '@photon-ai/advanced-imessage-kit' ;
const sdk = new AdvancedIMessageKit ({
serverUrl: 'http://localhost:1234' ,
password: 'your-password'
});
await sdk . connect ();
// Message statistics
const messageStats = await sdk . server . getMessageStats ();
console . log ( 'Message Statistics' );
console . log ( '==================' );
console . log ( `Total Messages: ${ messageStats . total ?. toLocaleString () || 'N/A' } ` );
console . log ( `Sent: ${ messageStats . sent ?. toLocaleString () || 'N/A' } ` );
console . log ( `Received: ${ messageStats . received ?. toLocaleString () || 'N/A' } ` );
if ( messageStats . total && messageStats . total > 0 ) {
const sentPercentage = (( messageStats . sent / messageStats . total ) * 100 ). toFixed ( 1 );
console . log ( `Sent: ${ sentPercentage } % | Received: ${ 100 - sentPercentage } %` );
}
// Media statistics
console . log ( ' \n Media Statistics' );
console . log ( '================' );
try {
const mediaStats = await sdk . server . getMediaStatistics ();
console . log ( JSON . stringify ( mediaStats , null , 2 ));
} catch ( error ) {
console . log ( 'Media statistics not available' );
}
// Recent logs
console . log ( ' \n Recent Server Logs' );
console . log ( '==================' );
try {
const logs = await sdk . server . getServerLogs ( 10 );
if ( logs && logs . length > 0 ) {
logs . forEach (( log , i ) => {
console . log ( ` ${ i + 1 } . ${ log } ` );
});
} else {
console . log ( 'No logs available' );
}
} catch ( error ) {
console . log ( 'Logs not available' );
}
Analyze media storage by type:
// Get all media statistics
const allMedia = await sdk . server . getMediaStatistics ();
// Get only image statistics
const imageStats = await sdk . server . getMediaStatistics ({
only: [ 'image' ]
});
// Get only video statistics
const videoStats = await sdk . server . getMediaStatistics ({
only: [ 'video' ]
});
console . log ( 'Media Breakdown:' );
console . log ( `Images: ${ JSON . stringify ( imageStats ) } ` );
console . log ( `Videos: ${ JSON . stringify ( videoStats ) } ` );
Find chats with the most media:
const mediaByChat = await sdk . server . getMediaStatisticsByChat ({
only: [ 'image' , 'video' ]
});
// Convert to array and sort by media count
const chatStats = Object . entries ( mediaByChat ). map (([ guid , stats ]) => ({
guid ,
stats
}));
// Display top 10 chats by media count
console . log ( 'Top 10 Chats by Media:' );
chatStats
. slice ( 0 , 10 )
. forEach (({ guid , stats }, i ) => {
console . log ( ` ${ i + 1 } . ${ guid } :` , stats );
});
Server Health Monitoring
Monitor server logs for errors:
// Get last 100 logs
const logs = await sdk . server . getServerLogs ( 100 );
// Filter for errors or warnings
const errors = logs . filter ( log =>
log . toLowerCase (). includes ( 'error' ) ||
log . toLowerCase (). includes ( 'warning' )
);
if ( errors . length > 0 ) {
console . log ( `⚠️ Found ${ errors . length } errors/warnings:` );
errors . forEach ( err => console . log ( ` - ${ err } ` ));
} else {
console . log ( '✅ No errors found in recent logs' );
}
getServerInfo() - Get server metadata and configuration
Statistics data is retrieved directly from the server’s iMessage database and may take a moment to compute for large message histories.
The getServerLogs() method may not be available on all BlueBubbles server versions. Always wrap calls in a try-catch block.