TextResource
The text resource provides methods for sending SMS/MMS messages, managing reactions, and retrieving message history.
send()
await contiguity.text.send(params: TextSendParams): Promise<{ message_id: string }>
Send an SMS or MMS text message.
Recipient phone number in E.164 format (e.g., +1234567890).
The text message content to send.
Sender phone number. If not provided, a number will be automatically selected from your leased numbers.
Array of attachment URLs (max 3). When attachments are included, the message is sent as MMS.
Enable fast-track delivery for time-sensitive messages.
Unique identifier for the sent message.
const result = await contiguity.text.send({
to: '+1234567890',
from: '+0987654321',
message: 'Hello from Contiguity!',
attachments: ['https://example.com/image.jpg']
});
console.log(result.message_id); // "msg_..."
reply()
await contiguity.text.reply(
event: WebhookEventBase,
params: Omit<TextSendParams, 'to' | 'from'>
): Promise<{ message_id: string }>
Reply to an incoming text message webhook. Automatically fills to and from fields from the webhook event.
The webhook event received from an incoming text message. The event data must contain to and from fields.
params
Omit<TextSendParams, 'to' | 'from'>
required
Message parameters (same as send() but without to and from).
Unique identifier for the sent reply.
// In your webhook handler
app.post('/webhook', async (req, res) => {
const event = contiguity.webhook.parse(req.body);
if (event.type === 'text.incoming.sms') {
await contiguity.text.reply(event, {
message: 'Thanks for your message!'
});
}
res.sendStatus(200);
});
get()
await contiguity.text.get(id: string): Promise<any>
Retrieve details about a specific message by its ID.
The message ID returned from send() or reply().
const message = await contiguity.text.get('msg_...');
console.log(message);
history()
await contiguity.text.history(params: ConversationHistoryParams): Promise<any>
Retrieve message history for a conversation between two phone numbers.
params
ConversationHistoryParams
required
One of the phone numbers in the conversation.
The other phone number in the conversation.
Maximum number of messages to retrieve. Defaults to 20.
const history = await contiguity.text.history({
to: '+1234567890',
from: '+0987654321',
limit: 50
});
console.log(history);
react()
await contiguity.text.react(
action: 'add' | 'remove',
params: TextReactParams
): Promise<{ message_id: string }>
Add or remove a reaction to a text message.
Whether to add or remove the reaction.
The ID of the message to react to.
The recipient phone number.
The message text to react to.
The type of reaction. One of: love, thumbsup, thumbsdown, haha, emphasized, questioned.
Unique identifier for the reaction.
// Add a reaction
await contiguity.text.react('add', {
message_id: 'msg_...',
reaction: 'love'
});
// Remove a reaction
await contiguity.text.react('remove', {
message_id: 'msg_...',
reaction: 'love'
});