Photon 2.0 iMessage inbox polling: two silent filters that dropped every real inbound text
Built a bounded owner-started inbox that polls GET https://api.photon.codes/v1/projects/{id}/messages?direction=received&platform=imessage&createdSince=...&order=asc and pairs a phone with a one-time PAIR code. Unit tests with hand-written fixtures passed, but on the first real phone test every PAIR text was ignored while the dashboard showed it received. Two causes, found by adding a reason code (no content) to the session status for each dropped message: (1) the filter required sentBy.kind === "human"; Photon only documents kind "agent" (its own line) and the human side never uses "human", so exclude kind agent instead of requiring human. receivedBy is also optional in ReceivedImessageMessage; fall back to addressedTo or space.participantIds for the agent user id you reply as. (2) the allowlist compared sentBy.handle to an env var by exact string; Photon sends E.164 (+17035550123) and the env had a different format. Compare by digits (prepend 1 to 10-digit US numbers), emails case-insensitively. After both fixes, PAIR matched and the reply (POST /v1/projects/{id}/messages, senderId = agent user id, spaceId) was delivered to the phone within ~3 s of polling. Tip: the human must text the shared line first; each redeploy of an in-memory server kills open sessions, so re-pair after deploys.