Connect iMessage
Pair your phone with a shared iMessage line and send your agent its first message.
A shared line is the quickest way to try Photon. You add the phone number or email you text from, and Photon pairs it with a number from its shared pool. That number is your agent's. Text it, and the message reaches your project.
Prerequisites
You need:
- A project from Set up your project.
- An iPhone or Mac signed in to iMessage.
- A plan with shared iMessage capacity. See plans and billing.
Add the number you text from
Open iMessage in your project. If it asks you to choose a line, choose Shared line.
Under Add the number you or your user will send from, enter your iMessage phone number and select Add. To text from an Apple Account email instead, select Use an iMessage email instead.
Use the identity your device sends from. On iPhone, check Settings → Apps → Messages → Send & Receive. A phone number and an Apple Account email are different senders, even when both are yours.
Add the number with code instead
This replaces Add in the dashboard; don't do both. Your API key needs
platforms:write. Set the number in E.164 format, such as
+14155550123, or your exact iMessage email. Set a unique setup key and
reuse it if you retry:
export PHOTON_TEST_SENDER="+14155550123"
export PHOTON_SETUP_KEY="first-agent-imessage-$(date +%s)"Save the example as setup.ts, setup.py, src/main.rs, or main.go in the
directory you prepared in project setup.
import { Photon } from "@photon-ai/api";
const required = (name: string): string => {
const value = process.env[name];
if (!value) throw new Error(`Set ${name}`);
return value;
};
const photon = new Photon({
headers: { Authorization: `Bearer ${required("PHOTON_API_KEY")}` },
});
try {
const assignment = await photon.projects.platforms.imessage.assignments.create({
path: { id: required("PHOTON_PROJECT_ID") },
headers: { idempotencyKey: required("PHOTON_SETUP_KEY") },
body: { handle: required("PHOTON_TEST_SENDER") },
});
console.log(assignment.assignedPhoneNumber);
} catch {
console.error("Could not assign the shared line. Check the key, permissions, and plan capacity.");
process.exitCode = 1;
}import os
from photon_api import Photon, PhotonError
from photon_api.generated.models import CreateSharedLineAssignmentRequest
from photon_api.rpc_generated import (
CreateSharedLineAssignmentHeader,
CreateSharedLineAssignmentInput,
CreateSharedLineAssignmentPath,
)
try:
with Photon(headers={"Authorization": f"Bearer {os.environ['PHOTON_API_KEY']}"}) as photon:
assignment = photon.projects.platforms.imessage.assignments.create(
CreateSharedLineAssignmentInput(
path=CreateSharedLineAssignmentPath(id=os.environ["PHOTON_PROJECT_ID"]),
headers=CreateSharedLineAssignmentHeader.model_validate(
{"Idempotency-Key": os.environ["PHOTON_SETUP_KEY"]}
),
body=CreateSharedLineAssignmentRequest(
handle=os.environ["PHOTON_TEST_SENDER"]
),
)
)
print(assignment.assignedPhoneNumber)
except PhotonError:
raise SystemExit("Could not assign the shared line. Check the key, permissions, and plan capacity.") from Noneuse photon_ai_api::{types, Credential, PhotonClientBuilder, SecretString};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = PhotonClientBuilder::new()
.credential(
"projectApiKey",
Credential::Bearer(SecretString::from(std::env::var("PHOTON_API_KEY")?)),
)
.build()?;
let assignment = client
.create_shared_line_assignment(
std::env::var("PHOTON_SETUP_KEY")?,
std::env::var("PHOTON_PROJECT_ID")?,
&types::CreateSharedLineAssignmentRequest {
handle: std::env::var("PHOTON_TEST_SENDER")?,
email: None,
first_name: None,
last_name: None,
},
)
.await
.map_err(|_| "Could not assign the shared line. Check the key, permissions, and plan capacity.")?;
println!("{}", assignment.inner().assigned_phone_number);
Ok(())
}package main
import (
"context"
"fmt"
"log"
"os"
photonapi "github.com/photon-hq/api/packages/go"
)
func required(name string) string {
value := os.Getenv(name)
if value == "" {
log.Fatalf("Set %s", name)
}
return value
}
func main() {
client := photonapi.NewClient(photonapi.WithAPIKey(required("PHOTON_API_KEY")))
assignment, err := client.Projects.Platforms.Imessage.Assignments.Create(
context.Background(), &photonapi.CreateSharedLineAssignmentParams{
ID: required("PHOTON_PROJECT_ID"),
IdempotencyKey: required("PHOTON_SETUP_KEY"),
Body: photonapi.CreateSharedLineAssignmentRequest{
Handle: photonapi.ImessageHandle(required("PHOTON_TEST_SENDER")),
},
},
)
if err != nil {
log.Fatal("Could not assign the shared line. Check the key, permissions, and plan capacity.")
}
fmt.Println(assignment.AssignedPhoneNumber)
}node setup.tspython setup.pycargo run --bin photon-first-agentgo run main.goThe program prints your agent's number.
Text your agent's number
Photon assigns a number from the shared pool and shows Your assigned number is followed by the number. This is your agent's number.
Scan the code with your phone, or open Messages and start a new conversation with the agent's number. Send any message, such as hi. Make sure it sends as an iMessage (a blue bubble), not SMS.
Check that it arrived
The dashboard shows We received your message. From now on, everything you send to the agent's number reaches your project.
How a shared line works
- Only messages from the number or email you added reach your project. Add each person who should talk to your agent.
- The person texts first. Your agent can reply after their first message to the line, not before. This helps prevent spam.
- A shared line supports direct conversations, not group chats, and can't take calls.
For a number of your own that can send first, join group chats, and take calls, get a dedicated line in iMessage.
If your message doesn't arrive
| What you see | What to check |
|---|---|
| You can't add a number | Your plan's shared iMessage capacity. Members need write access to add people. |
| The message sends as SMS (green) | iMessage is off for that identity, or you texted from a different number or email than the one you added. |
| The dashboard keeps waiting | You sent from a different identity. Check Send & Receive on your device, or add that identity. |
Next: receive messages
Get each message to your agent's number as an event in your code.