Skip to main content

Method Signature

async sendAttachment(options: SendAttachmentOptions): Promise<MessageResponse>
Send a file attachment to an iMessage conversation. Supports any file type that iMessage can handle, including images, videos, documents, and more.

Parameters

options
SendAttachmentOptions
required
Configuration object for sending the attachment

Returns

MessageResponse
object
The sent message object containing the attachment metadata

Examples

Send an Image

const message = await client.attachment.sendAttachment({
  chatGuid: "iMessage;+;chat123456",
  filePath: "/path/to/photo.jpg"
});

console.log(`Image sent: ${message.guid}`);

Send with Custom Filename

const message = await client.attachment.sendAttachment({
  chatGuid: "iMessage;+;chat123456",
  filePath: "/tmp/download.pdf",
  fileName: "Report-Q1-2024.pdf"
});

Send as a Reply

const message = await client.attachment.sendAttachment({
  chatGuid: "iMessage;+;chat123456",
  filePath: "/path/to/screenshot.png",
  selectedMessageGuid: "original-message-guid"
});

Send Video

const message = await client.attachment.sendAttachment({
  chatGuid: "iMessage;+;chat123456",
  filePath: "/path/to/video.mp4",
  fileName: "vacation.mp4"
});

Behavior

  • If the specified chat doesn’t exist, it will be created automatically before sending
  • The method is queued to ensure messages are sent in order
  • File is read from disk and uploaded as multipart form data
  • All file types supported by iMessage can be sent

Error Handling

try {
  const message = await client.attachment.sendAttachment({
    chatGuid: "iMessage;+;chat123456",
    filePath: "/path/to/file.jpg"
  });
} catch (error) {
  if (error.code === 'ENOENT') {
    console.error('File not found');
  } else {
    console.error('Failed to send attachment:', error);
  }
}

See Also

Build docs developers (and LLMs) love