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:
The server address is only the host and port. Do not include
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:
Message APIs take
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:
SDK Overview
The client is organized by resource: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