@photon-ai/advanced-imessage is a TypeScript SDK that connects you to our advanced gRPC-based iMessage server.
It gives you a strongly-typed, resource-oriented API for everything iMessage - sending texts, reacting, scheduling, streaming events, and more.
Installation
Quick start
createClient
| Option | Type | Description |
|---|---|---|
address | string | Host (and optional port) of the Photon server |
token | string | () => Promise<string> | Static token or async token factory |
tls | boolean | Enable TLS (default: false) |
timeout | number | Request timeout in milliseconds |
retry | boolean | RetryOptions | Automatic retry on transient failures |
autoIdempotency | boolean | Attach x-idempotency-key to mutating RPCs |
AdvancedIMessage object exposes one property per resource:
Disposing the client
The client implementsSymbol.asyncDispose, so you can use await using in environments that support it:
Your first echo bot
An echo bot subscribes to incoming messages and replies with the same text. It’s the simplest end-to-end example - receiving and sending in one loop.subscribe("message.received")narrows the event type -messageandchatGuidare fully typed with no casts needed.- Messages without text (images, reactions, etc.) are skipped with the
continueguard. chatGuidis already aChatGuid- pass it directly tosend().
Prevent the bot from echoing itself
Filter out messages sent by the server account to avoid infinite loops:ChatGuid helpers
All APIs that target a conversation require aChatGuid. Never construct the raw GUID string yourself - use the helpers: