Skip to content

Send SMS to All Contacts

Send SMS messages to all available contacts in your database. The operation is asynchronous: the API records every message in persistence, schedules delivery in BullMQ, and returns an enqueue summary.

  • Include the bearer token in Authorization: Bearer <token>.
  • Only members that accepted the current terms can trigger messaging actions; otherwise the service returns 403 Forbidden.
interface SmsAllMessagePayload {
message: string; // Text body, keep under the per-provider character limit
type?: MessageType; // Defaults to MessageType.SMS when omitted
country?: string; // Optional ISO 3166-1 alpha-2 code for number normalization
}
FieldTypeRequiredDescription
messagestringYesSMS message content
typeMessageTypeNoMessage type (defaults to SMS)
countrystringNoISO 3166-1 alpha-2 country code
{
"message": "Important! Update on our terms of service available on our website.",
"type": "SMS",
"country": "CO"
}

The API responds with the shared MessageEnqueueResultDto contract:

interface MessageEnqueueResultDto {
queueId: string; // BullMQ job identifier, empty when nothing was enqueued
channel: 'sms';
messages: Array<{
id: string; // UUID of the persisted message
recipient: string; // Phone number normalized by the backend
}>;
}
{
"queueId": "sms-queue-67890",
"channel": "sms",
"messages": [
{
"id": "msg-uuid-1",
"recipient": "+573001234567"
},
{
"id": "msg-uuid-2",
"recipient": "+573009876543"
},
{
"id": "msg-uuid-3",
"recipient": "+573007654321"
}
]
}

When there are no valid contacts in the database, the service responds with 200 OK, an empty queueId, and an empty messages array.

{
"queueId": "",
"channel": "sms",
"messages": []
}
async function sendSmsToAll(token: string, payload: SmsAllMessagePayload) {
const response = await fetch('/api/messages/sms/all', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
},
body: JSON.stringify(payload),
});
if (!response.ok) {
throw new Error(`SMS broadcast failed: ${response.status}`);
}
const data: MessageEnqueueResultDto = await response.json();
return data;
}
// Usage
const result = await sendSmsToAll('your-token', {
message: 'Special promotion: 50% off all our products until Friday.',
country: 'CO'
});
console.log(`SMS sent to ${result.messages.length} contacts`);
console.log(`Queue ID: ${result.queueId}`);
  • The backend removes duplicated recipients per batch and silently skips invalid destinations.
  • Balance validation runs before queuing; insufficient credits return an error response without enqueuing messages.
  • Use the returned queueId to correlate delivery status inside the admin UI or via dedicated status endpoints.
  • Each message persists provider metadata and can be audited through the messaging module filters.
  • Important: Consider carefully the impact of sending to all contacts, especially for cost and message relevance.