The line’s device decides between iMessage and SMS when it sends, and the API can’t override it: the channel field accepts only auto. What you can do is know in advance, and plan for it.
Three reasons to bother:
- Your script. An SMS contact gets no typing bubble, no tapbacks and no message effects. An agent that plans to use them needs a plain version.
- Your reports. iSnap reports delivery and read status for iMessage only. For SMS contacts, “delivered” never comes, and a dashboard that counts it will look broken.
- Your route. A bring-your-own iPhone line may have no SMS route at all. There, a message to a contact who isn’t on iMessage fails.
Look up a number
POST /v1/lookup takes a handle, a phone number or an email address, and optionally from_line_id, one of your lines. With a line given, that line’s own lookup limits apply too (see below). The TypeScript version wraps the call in a small function that waits on a pending answer and gives up after three calls.
import { ISnapClient, QuotaExceededError } from '@isnap/sdk'
const client = new ISnapClient({ apiKey: process.env.ISNAP_API_KEY ?? '', maxRetries: 2 })
async function canReceiveImessage(handle: string): Promise<boolean | null> {
// Every call counts against the lookup limits, repeats included: repeat at most 3 times.
for (let attempt = 0; attempt < 3; attempt++) {
const result = await client.lookup.check({ handle, from_line_id: 'line_8Xk2mQ4vTn7Bw9Rz3Lc6Yp1Hd' })
if (!result.pending) return result.imessage
await new Promise(resolve => setTimeout(resolve, (result.retry_after ?? 4) * 1000))
}
return null // No definite answer after 3 calls: treat it as unknown.
}
try {
console.log(await canReceiveImessage('+14155550123'))
} catch (err) {
if (err instanceof QuotaExceededError && err.code === 'lookup_rate_limit_exceeded') {
console.error(`Lookup limit reached: retry after ${err.retryAfter} seconds`)
} else {
throw err
}
}curl -sS https://api.isnap.ai/v1/lookup \
-H "Authorization: Bearer $ISNAP_API_KEY" \
-H "Content-Type: application/json" \
-d '{"handle": "+14155550123", "from_line_id": "line_8Xk2mQ4vTn7Bw9Rz3Lc6Yp1Hd"}'The three answers
| Response | Meaning and next step |
|---|---|
200 imessage: true | On iMessage. Send, and plan typing, tapbacks and read receipts. |
200 imessage: false | Not on iMessage. Expect SMS: plain texts, no delivery or read status. |
200 imessage: null | No definite answer. Treat it as unknown. You can still send; the device decides. |
202 pending | Still checking. Wait retry_after seconds and ask again, at most 3 calls in all. |
The sample turns those into one return value: true, false, or null for unknown, including when three calls in a row stayed pending. Keep the three states apart in your own data. “Unknown” is not “no”, and a contact you mark as SMS by mistake loses the features iMessage would have given them.
One trap: a lookup accepts an email address, but a send goes to phone numbers only. An email handle that answers true still can’t be texted through iSnap.
Stay inside the lookup limits
Every call counts, repeats and pending answers included:
- 400 lookups per account per UTC day;
- with
from_line_id, also 30 per line per UTC hour and 100 per line per UTC day.
Over a limit, the SDK throws QuotaExceededError with the code lookup_rate_limit_exceeded and a retryAfter in seconds, which the sample prints. A definite answer is cached for 24 hours and shared across all iSnap accounts, so a number someone just checked answers at once.
At 400 a day, look up when a contact enters your system, not before every send, and store the answer with the contact. The docs’ advice on personal data applies here as everywhere: ask only when you need the answer, keep phone numbers out of your logs, and refer to a contact by an id of your own.
When a line falls back to SMS
iMessage is the default. The device sends SMS instead when it knows the contact isn’t registered with iMessage: from a lookup, from an earlier send, or from Apple while the device watches the send. It also keeps using an SMS conversation that already exists with that contact.
It does not fall back when an iMessage send times out, on other errors from Apple, after a message was already sent, or when Apple’s answer arrives late. In those cases iSnap does not resend the message as SMS, so a lookup before the first message is the reliable way to put a contact on the right route.
When a message does go out over SMS, or the device tries to send it that way, you get a message.fallback_triggered event. Its fallback_service names the service the device used, which Apple and the carrier choose. The message’s own service field reads the same once it is sent.
What changes for an SMS contact
- No delivery and no read status. iSnap reports neither for SMS, so an SMS message ends at
sent. Measure these contacts by replies, not by receipts. - No typing indicator and no tapbacks. Those calls answer 422 (
sms_typing_not_supported,sms_reactions_not_supported). Check before you call, or catch the error as the typing sample in recipe 03 does. - No effects. Bubble and screen effects are iMessage features.
On your own iPhone: make sure there is an SMS route
Rented iPhone lines have an SMS route. On a bring-your-own iPhone line, the route exists only when the iPhone forwards its text messages to the paired Mac, with Text Message Forwarding turned on in the iPhone’s Messages settings. Without it, a message to a contact who isn’t on iMessage fails, and no SMS is attempted.
Check the sms_fallback capability in runtime_capabilities on GET /v1/lines/{id}/health before you send from that line to numbers that looked up false, and listen for line.capability_changed in case it changes. The BYOD guide lists what the Mac and the iPhone need.
What a lookup can’t tell you
- Whether the answer still holds. People change phones and turn iMessage off. A definite answer can come from iSnap’s 24-hour cache, and it ages further once you store it. That is why the last step below updates the contact from events.
- Whether the person wants your message. A lookup says what a number can receive, not whether its owner agreed to hear from you. You still need permission to text people, and you honor opt-outs when they ask.
- Which route the send will take. It informs the device; it doesn’t command it. The device still chooses at send time, with everything it knows.
Put it together
- Look up once, when a contact enters your system, with the line that will text them.
- Store the answer as true, false or unknown, with the date, beside the contact.
- Branch your script. iMessage contacts get the full rhythm. SMS contacts get short, plain texts and reply-based tracking. Unknown contacts get the plain script.
- Learn from events. A
message.fallback_triggeredor adeliveredtells you more than a stale lookup. Update the contact when one arrives.
You now send each contact on the route they can read, with the features that route has. The last recipe connects a line of your own: pair a bring-your-own iPhone.
Next recipe: Pair your own iPhone. Or go back to all recipes and the API at a glance.