Skip to main content

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.
params
TextSendParams
required
message_id
string
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.
event
WebhookEventBase
required
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).
message_id
string
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.
id
string
required
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
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.
action
'add' | 'remove'
required
Whether to add or remove the reaction.
params
TextReactParams
required
message_id
string
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'
});

Build docs developers (and LLMs) love