Skip to main content

Overview

The Text resource provides methods to send SMS/MMS messages, manage reactions, retrieve conversation history, and reply to incoming messages via webhooks.

Sending Messages

Send a text message to a phone number.
const result = await contiguity.text.send({
  to: '+1234567890',
  message: 'Hello from Contiguity!',
  from: '+0987654321'
});

console.log(result.message_id);

Parameters

to
string
required
The recipient’s phone number in E.164 format
message
string
required
The text message content to send
from
string
The sender’s phone number. If not provided, a number will be automatically selected
attachments
string[]
Array of attachment URLs (images, videos, etc.). Maximum 3 attachments
fast_track
boolean
Enable fast-track delivery for time-sensitive messages

Returns

{
  message_id: string
}

Replying to Messages

Reply to an incoming text message webhook. This method automatically extracts to and from fields from the webhook event.
import { Contiguity } from 'contiguity';

const contiguity = new Contiguity('your-api-key');

// Inside your webhook handler
app.post('/webhook', async (req, res) => {
  const event = req.body;
  
  const result = await contiguity.text.reply(event, {
    message: 'Thanks for your message!'
  });
  
  res.json({ success: true });
});

Parameters

event
WebhookEventBase
required
The incoming webhook event object containing data.to and data.from
params
Omit<TextSendParams, 'to' | 'from'>
required
Send parameters excluding to and from (automatically populated from event)

Adding Reactions

Add a reaction to a text message.
const result = await contiguity.text.react('add', {
  message_id: 'msg_123456',
  reaction: 'love'
});

Parameters

action
'add' | 'remove'
required
Whether to add or remove the reaction
params
object
required
Reaction parameters
params.message_id
string
The ID of the message to react to
params.to
string
The recipient’s phone number
params.from
string
The sender’s phone number
params.message
string
The message content (alternative to message_id)
params.reaction
enum
required
The reaction type. One of: love, thumbsup, thumbsdown, haha, emphasized, questioned

Removing Reactions

Remove a reaction from a text message.
const result = await contiguity.text.react('remove', {
  message_id: 'msg_123456',
  reaction: 'love'
});

Retrieving Message History

Get conversation history between two phone numbers.
const history = await contiguity.text.history({
  to: '+1234567890',
  from: '+0987654321',
  limit: 50
});

Parameters

to
string
required
The recipient’s phone number
from
string
required
The sender’s phone number
limit
number
Maximum number of messages to retrieve (default: 20)

Getting a Single Message

Retrieve a specific message by its ID.
const message = await contiguity.text.get('msg_123456');

Parameters

id
string
required
The message ID to retrieve

Error Handling

try {
  const result = await contiguity.text.send({
    to: '+1234567890',
    message: 'Hello!'
  });
} catch (error) {
  if (error instanceof z.ZodError) {
    console.error('Validation error:', error.errors);
  } else {
    console.error('API error:', error);
  }
}
All methods validate input parameters using Zod schemas and throw validation errors for invalid input.

Build docs developers (and LLMs) love