Skip to main content

SendSms

The SendSms method sends a transactional SMS to a user.

Usage​

err := client.SendSms(ctx, payload)

Parameters​

NameTypeDescription
ctxcontext.ContextContext for the request.
payloadcdp.SmsPayloadStruct containing SMS details.

SmsPayload Struct​

FieldTypeRequiredDescription
Identifierscdp.Identifiers✅User identifiers (exactly one of ID, Email, or CioID).
TransactionalMessageIDstringID of the SMS template.
TostringRecipient phone number (E.164 format).
FromstringSender phone number (E.164 format).
BodystringSMS message body (required if no template).
MessageDatamap[string]interface{}Data for template variables.

Validation Rules​

  • Identifiers must contain exactly one of: ID, Email, or CioID
  • When not using a template (TransactionalMessageID empty): Body is required
  • To and From must be in E.164 format (e.g., +1234567890)
  • Body cannot be an empty string if provided

Example​

Using a Template​

payload := cdp.SmsPayload{
Identifiers: cdp.Identifiers{ID: "user_123"},
TransactionalMessageID: "order_confirmation",
MessageData: map[string]interface{}{
"order_id": "ORD-12345",
},
}

if err := client.SendSms(context.Background(), payload); err != nil {
log.Println("Error sending SMS:", err)
}

Raw SMS​

payload := cdp.SmsPayload{
Identifiers: cdp.Identifiers{ID: "user_123"},
To: "+14155551234",
Body: "Your order has been shipped!",
}

if err := client.SendSms(context.Background(), payload); err != nil {
log.Println("Error sending SMS:", err)
}