Skip to main content

getBackground

Retrieve the current background configuration for a chat.
await sdk.chats.getBackground(chatGuid): Promise<{
  hasBackground: boolean;
  backgroundChannelGUID?: string | null;
  imageUrl?: string | null;
  backgroundId?: string | null;
}>

Parameters

chatGuid
string
required
Unique identifier of the chat

Returns

background
object
Background configuration object
hasBackground
boolean
Whether the chat has a custom background
backgroundChannelGUID
string | null
GUID of the background channel
imageUrl
string | null
URL of the background image
backgroundId
string | null
Identifier for the background

Example

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

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

const chatGuid = 'iMessage;+;chat123456';

// Get current background
const background = await sdk.chats.getBackground(chatGuid);

if (background.hasBackground) {
  console.log('Background URL:', background.imageUrl);
  console.log('Background ID:', background.backgroundId);
} else {
  console.log('No custom background set');
}

setBackground

Set a custom background for a chat using an image URL, file path, or base64 data.
await sdk.chats.setBackground(
  chatGuid,
  options: string | { imageUrl?: string; filePath?: string; fileData?: string }
): Promise<void>

Parameters

chatGuid
string
required
Unique identifier of the chat
options
string | object
required
Background image source (can be a URL string or an object with one of the following properties)
imageUrl
string
URL of the image to use as background
filePath
string
Local file path to the image
fileData
string
Base64-encoded image data

Returns

Returns a Promise that resolves when the background is set.

Example

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

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

const chatGuid = 'iMessage;+;chat123456';

// Set background using image URL (shorthand)
await sdk.chats.setBackground(
  chatGuid,
  'https://example.com/images/background.jpg'
);

// Set background using image URL (object syntax)
await sdk.chats.setBackground(chatGuid, {
  imageUrl: 'https://example.com/images/background.jpg'
});

// Set background using local file path
const imagePath = path.join(__dirname, 'images', 'chat-bg.png');
await sdk.chats.setBackground(chatGuid, {
  filePath: imagePath
});

// Set background using base64 data
const imageBuffer = readFileSync(imagePath);
const base64Data = imageBuffer.toString('base64');
await sdk.chats.setBackground(chatGuid, {
  fileData: base64Data
});

console.log('Chat background updated successfully');

removeBackground

Remove the custom background from a chat.
await sdk.chats.removeBackground(chatGuid): Promise<void>

Parameters

chatGuid
string
required
Unique identifier of the chat

Returns

Returns a Promise that resolves when the background is removed.

Example

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

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

const chatGuid = 'iMessage;+;chat123456';

// Remove chat background
await sdk.chats.removeBackground(chatGuid);
console.log('Chat background removed');

Complete Background Management Example

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

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

const chatGuid = 'iMessage;+;chat123456';

// Check current background
const currentBg = await sdk.chats.getBackground(chatGuid);
console.log('Current background:', currentBg);

if (currentBg.hasBackground) {
  // Remove existing background
  await sdk.chats.removeBackground(chatGuid);
  console.log('Removed old background');
}

// Set new background
const newBgPath = path.join(__dirname, 'backgrounds', 'ocean.jpg');
await sdk.chats.setBackground(chatGuid, {
  filePath: newBgPath
});

// Verify new background is set
const updatedBg = await sdk.chats.getBackground(chatGuid);
console.log('New background set:', updatedBg.hasBackground);

Build docs developers (and LLMs) love