ImessageResource
The imessage resource provides methods for sending iMessages, managing typing indicators, reactions, and read receipts.
send()
await contiguity . imessage . send ( params : ImessageSendParams ): Promise < { message_id : string } >
Send an iMessage to a recipient.
params
ImessageSendParams
required
Recipient phone number or email address.
The message content to send.
Sender phone number. If not provided, a number will be automatically selected.
Array of attachment URLs to include with the message.
Fallback configuration for when iMessage fails or is unsupported. Array of conditions: imessage_unsupported or imessage_fails.
Fallback sender number for SMS delivery.
Enable fast-track delivery for time-sensitive messages.
Unique identifier for the sent message.
const result = await contiguity . imessage . send ({
to: '+1234567890' ,
from: '+0987654321' ,
message: 'Hello via iMessage!' ,
attachments: [ 'https://example.com/image.jpg' ],
fallback: {
when: [ 'imessage_unsupported' , 'imessage_fails' ],
from: '+0987654321'
}
});
console . log ( result . message_id ); // "msg_..."
reply()
await contiguity . imessage . reply (
event : WebhookEventBase ,
params : Omit < ImessageSendParams , 'to' | 'from' >
): Promise < { message_id : string } >
Reply to an incoming iMessage webhook. Automatically fills to and from fields from the webhook event.
The webhook event received from an incoming iMessage.
params
Omit<ImessageSendParams, 'to' | 'from'>
required
Message parameters (same as send() but without to and from).
Unique identifier for the sent reply.
app . post ( '/webhook' , async ( req , res ) => {
const event = contiguity . webhook . parse ( req . body );
if ( event . type === 'imessage.incoming' ) {
await contiguity . imessage . reply ( event , {
message: 'Thanks for your iMessage!'
});
}
res . sendStatus ( 200 );
});
typing()
await contiguity . imessage . typing ( params : ImessageTypingParams ): Promise < any >
Send a typing indicator to show that you’re composing a message.
params
ImessageTypingParams
required
Recipient phone number or email address.
Whether to start or stop the typing indicator.
// Show typing indicator
await contiguity . imessage . typing ({
to: '+1234567890' ,
from: '+0987654321' ,
action: 'start'
});
// Simulate composing message...
await new Promise ( resolve => setTimeout ( resolve , 2000 ));
// Stop typing indicator and send message
await contiguity . imessage . typing ({
to: '+1234567890' ,
from: '+0987654321' ,
action: 'stop'
});
await contiguity . imessage . send ({
to: '+1234567890' ,
from: '+0987654321' ,
message: 'Here is my response!'
});
get()
await contiguity . imessage . get ( id : string ): Promise < any >
Retrieve details about a specific iMessage by its ID.
The message ID returned from send() or reply().
const message = await contiguity . imessage . get ( 'msg_...' );
console . log ( message );
history()
await contiguity . imessage . history ( params : ConversationHistoryParams ): Promise < any >
Retrieve iMessage history for a conversation.
params
ConversationHistoryParams
required
One of the participants in the conversation.
The other participant in the conversation.
Maximum number of messages to retrieve. Defaults to 20.
const history = await contiguity . imessage . history ({
to: '+1234567890' ,
from: '+0987654321' ,
limit: 50
});
react()
await contiguity . imessage . react (
action : 'add' | 'remove' ,
params : ImessageReactParams
): Promise < any >
Add or remove a tapback reaction to an iMessage.
Whether to add or remove the reaction.
params
ImessageReactParams
required
Recipient phone number or email address.
The tapback type. One of: love, like, dislike, laugh, emphasize, question.
The message text to react to.
// Add a tapback
await contiguity . imessage . react ( 'add' , {
to: '+1234567890' ,
from: '+0987654321' ,
tapback: 'love' ,
message: 'Thanks for the help!'
});
// Remove a tapback
await contiguity . imessage . react ( 'remove' , {
to: '+1234567890' ,
from: '+0987654321' ,
tapback: 'love' ,
message: 'Thanks for the help!'
});
read()
await contiguity . imessage . read ( params : ImessageReadParams ): Promise < any >
Send a read receipt for a conversation.
params
ImessageReadParams
required
The recipient phone number or email address.
await contiguity . imessage . read ({
to: '+1234567890' ,
from: '+0987654321'
});