Skip to content

feat: add iMessage channel#8

Open
KumarVandit wants to merge 8 commits intosachaa:masterfrom
photon-hq:feature/photon-imessage-support
Open

feat: add iMessage channel#8
KumarVandit wants to merge 8 commits intosachaa:masterfrom
photon-hq:feature/photon-imessage-support

Conversation

@KumarVandit
Copy link

@KumarVandit KumarVandit commented Mar 8, 2026

Adds iMessage as a new channel so the agent can receive and respond to iMessages. Messages automatically trigger the agent without requiring an @mention.

Changes
New channel (src/channels/imessage.ts)
IMessageChannel — Socket.IO client for real-time inbound messages, REST for outbound send and typing indicators
• GUID-based dedup with 60s TTL to prevent double-processing
• Exponential reconnection backoff (1s–30s) on disconnect
• 15s timeout on all REST calls so a hung server doesn’t block state
• Filters attachment-only messages before they reach the agent

Orchestrator (src/orchestrator.ts)
• iMessage init/teardown lifecycle alongside existing Telegram
im: prefixed group IDs auto-trigger the agent without @mention
• Delivery error handling so state resets cleanly on failure

Router (src/router.ts)
• Routes im:-prefixed group IDs to IMessageChannel

Settings UI (src/components/settings/SettingsPage.tsx)
• Server URL and API key fields for the iMessage bridge

Config & types
IMESSAGE_SERVER_URL and IMESSAGE_API_KEY added to src/config.ts
ChannelType union extended with 'imessage' in src/types.ts

Other
src/App.tsx — module-level Orchestrator singleton to avoid duplicate instances under React StrictMode
src/stores/orchestrator-store.ts — guard against duplicate event listener registration
README.md — setup instructions and updated architecture diagram
package.json — added socket.io-client

c50a732f185407f3194bade313058b8c.2.mp4

Adds a new iMessage integration via Photon SDKs, supporting two modes:

- **Local mode**: reads the iMessage SQLite DB directly on macOS via
  @photon-ai/imessage-kit (no server needed)
- **Remote mode**: connects to a Photon iMessage server via Socket.IO
  + REST, enabling edit, unsend, tapbacks, effects, typing indicators,
  polls, and group chat management

Changes:
- New `IMessageChannel` class with full Channel interface implementation
- Orchestrator wired to configure, start, and route iMessage messages
- Router extended with `im:` prefix for iMessage group routing
- Settings UI for mode selection, server URL, and API key
- Config keys for iMessage mode/server/API key in IndexedDB
- `ChannelType` union extended with 'imessage'
- Module-level Orchestrator singleton to prevent duplicate instances
  under React StrictMode
- Store init guard to prevent duplicate event listener registration
- PWA service worker disabled in dev mode to avoid stale cache issues
- README updated with setup instructions for both modes
… server

- Strip all local-mode code (LocalSDK, startLocal, local types/methods)
- Simplify IMessageConfig to just serverUrl + apiKey
- Remove IMESSAGE_MODE config key (no mode selector needed)
- Rename settings section from "Photon iMessage" to "iMessage"
- Mode label shows "Remote (Photon managed)" as static text
- Settings UI simplified: just server URL + API key fields
iMessage conversations are direct chats — requiring @mention for every
message is unnecessary friction. Messages from im: prefixed groups now
always trigger the agent, matching the browser chat behavior. Other
channels (Telegram) still require the @mention pattern.
- Remove default null value for imessage param in Router constructor
- Remove all dev-only console.log statements from orchestrator and imessage channel
- Replace "Photon managed" branding with neutral "remote" / "HTTPS + Socket.IO"
- Simplify iMessage server requirement description in README
- Fix security section to list Telegram and iMessage plaintext storage consistently
- Revert unrelated devOptions.enabled change in vite.config.ts
Remove editMessage, addReaction, removeReaction, getMessages,
getChatInfo, createPoll — all defined but never called from anywhere.
Also remove unused RemoteChat type, MESSAGE_EFFECTS, MessageEffect,
and the now-orphaned _get helper.

Update SettingsPage and README to not claim unsupported features.
- Add typing timer tracking to prevent overlapping POST/DELETE calls
- Guard send/setTyping with enabled check after disable
- Filter empty-text messages (attachment-only) before triggering agent
- Reset running flag if _startRemote() throws during startup
- Stop channel on auth-error instead of retrying with bad credentials
- Enable Socket.IO reconnection with exponential backoff (1s–30s)
- Catch router.send() failures in deliverResponse so state resets to idle
- Replace Photon placeholder URL with generic example.com
…dup TTL

- Reject socket events without a valid chat GUID instead of emitting
  groupId "im:" which collapses messages into a fake conversation
- Add 15s AbortController timeout to REST helpers (_post, _delete) via
  shared _request method so hung servers don't block state indefinitely
- Fix dedup cache to actually respect 60s TTL by checking stored
  timestamp on lookup, not just map membership
@KumarVandit KumarVandit changed the title Feature/photon imessage support feat: add iMessage channel Mar 8, 2026
@KumarVandit KumarVandit marked this pull request as ready for review March 8, 2026 06:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant