SendSms
The SendSms method sends a transactional SMS to a user.
Usage
err := client.SendSms(ctx, payload)
Parameters
| Name | Type | Description |
|---|---|---|
ctx | context.Context | Context for the request. |
payload | cdp.SmsPayload | Struct containing SMS details. |
SmsPayload Struct
| Field | Type | Required | Description |
|---|---|---|---|
Identifiers | cdp.Identifiers | ✅ | User identifiers (exactly one of ID, Email, or CioID). |
TransactionalMessageID | string | ID of the SMS template. | |
To | string | Recipient phone number (E.164 format). | |
From | string | Sender phone number (E.164 format). | |
Body | string | SMS message body (required if no template). | |
MessageData | map[string]interface{} | Data for template variables. |
Validation Rules
Identifiersmust contain exactly one of:ID,Email, orCioID- When not using a template (
TransactionalMessageIDempty):Bodyis required ToandFrommust be in E.164 format (e.g.,+1234567890)Bodycannot 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)
}