Most apps should start with Spectrum. It gives you one API across iMessage, WhatsApp Business, and other channels. Use
@photon-ai/advanced-imessage directly when you need low-level iMessage features that Spectrum does not expose.Before You Start
You need three things: a runtime, Photon credentials, and a recipient that can receive iMessage.Runtime
Use Node.js>=18.17 or Bun. If you are using Node, check your version first:
Photon Credentials
Copy these two values:| Value | Format |
|---|---|
| Server address | host:port, for example "imessage.example.com:443" |
| Bearer token | A token string for the server |
https://. For the first working example, put the server address directly in send.ts.
IMESSAGE_TOKEN through your deployment platform or secret manager.
Recipient
Prepare an address that can receive iMessage:- an email address, such as
[email protected] - an E.164 phone number, such as
+15551234567
chat.guid.
Install
Send Your First Message
The first send has three steps:- Create a client with your server address and token.
- Resolve the recipient with
im.chats.create(...). This gives you achat.guid. - Send text with
im.messages.sendText(...).
send.ts, then replace imessage.example.com:443 and [email protected]:
im.chats.create(...) returns a server chat GUID. Direct chats and group chats use different shapes:
| Chat type | GUID shape | Example |
|---|---|---|
| Direct chat | any;-;{recipient} | any;-;[email protected] |
| Group chat | any;+;{group-id} | any;+;group-id |
chat.guid, not the raw email address or phone number:
Run It
Node.js can run TypeScript throughtsx. Bun runs .ts files directly.
message.guid. Seeing that GUID means the message was accepted and sent.
Client Options
createClient(...) accepts these options:
| Option | Type | Required | Description |
|---|---|---|---|
address | string | Yes | Server address in host:port format. Do not include https://. |
token | string | Yes | Bearer token. |
tls | boolean | No | Encrypt the gRPC connection. Defaults to true; keep the default for hosted servers. |
timeout | number | No | Timeout, in milliseconds, for unary requests. Streams stay open. |
retry | boolean | RetryOptions | No | Retry retryable unary failures. Streams are not retried automatically. |
SDK Overview
The client is organized by resource:| Namespace | What it does |
|---|---|
im.messages | Send text, attachments, mini app cards, multipart messages, replies, reactions, stickers, edits, unsends, list queries, and message events |
im.chats | Create chats, read chat state, count chats, mark read, set typing, share contact cards, and manage chat backgrounds |
im.groups | Rename groups, manage participants, set group icons, and leave groups |
im.attachments | Upload files, read metadata, and stream downloads |
im.polls | Create polls, vote, unvote, add options, and subscribe to poll events |
im.addresses | Check address metadata, Focus silence state, and iMessage availability |
im.locations | Read Find My shared friend locations, request location sharing, and watch live updates |
im.events | Replay durable events after a disconnect |
Next Steps
Core path:- Messages — send text, attachments, mini app cards, multipart messages, reactions, edits, unsends, and subscribe to message events
- Chats — create chats, mark read, set typing, and manage chat backgrounds
- Events — catch up on durable events after a disconnect
- Error Handling — understand error classes, retries, and idempotency keys
- Groups — manage group names, participants, icons, and leaving
- Attachments — upload files, read metadata, and stream downloads
- Polls — create polls, vote, and subscribe to poll events
- Addresses — check addresses, Focus state, and iMessage availability
- Locations — read Find My shared friend locations and request location sharing