Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

SEND SMS

Send SMS text messages to phone numbers using various providers.

Syntax

' Basic SMS sending
SEND SMS phone, message

' With specific provider
SEND SMS phone, message, provider

Parameters

ParameterTypeRequiredDescription
phoneStringYesRecipient phone number (E.164 format recommended)
messageStringYesThe text message to send (max 160 chars for single SMS)
providerStringNoSMS provider: twilio, aws_sns, vonage, messagebird

Return Value

Returns true if the SMS was sent successfully, false otherwise.

Configuration

Configure SMS provider credentials in config.csv:

key,value
sms-provider,twilio
twilio-account-sid,YOUR_ACCOUNT_SID
twilio-auth-token,YOUR_AUTH_TOKEN
twilio-phone-number,+15551234567

Provider-Specific Configuration

Twilio:

sms-provider,twilio
twilio-account-sid,ACxxxxx
twilio-auth-token,your_token
twilio-phone-number,+15551234567

AWS SNS:

sms-provider,aws_sns
aws-access-key-id,AKIAXXXXXXXX
aws-secret-access-key,your_secret
aws-region,us-east-1

Vonage (Nexmo):

sms-provider,vonage
vonage-api-key,your_api_key
vonage-api-secret,your_secret
vonage-from-number,+15551234567

MessageBird:

sms-provider,messagebird
messagebird-access-key,your_access_key
messagebird-originator,YourBrand

Examples

Basic SMS

HEAR phone AS TEXT "Enter phone number:"
SEND SMS phone, "Hello from General Bots!"
TALK "SMS sent successfully!"

Order Confirmation

' Send order confirmation via SMS
order_id = "ORD-2025-001"
phone = customer.phone

message = "Your order " + order_id + " has been confirmed. "
message = message + "Estimated delivery: 2-3 business days."

result = SEND SMS phone, message

IF result THEN
    TALK "Confirmation SMS sent to " + phone
ELSE
    TALK "Failed to send SMS. We'll email you instead."
    SEND MAIL customer.email, "Order Confirmation", message
END IF

Two-Factor Authentication

' Generate and send OTP
otp = RANDOM(100000, 999999)
REMEMBER "otp_" + user.id, otp, "5 minutes"

message = "Your verification code is: " + otp + ". Valid for 5 minutes."
SEND SMS user.phone, message

HEAR entered_code AS TEXT "Enter the code sent to your phone:"

stored_otp = RECALL "otp_" + user.id

IF entered_code = stored_otp THEN
    TALK "✅ Phone verified successfully!"
    SET USER MEMORY "phone_verified", true
ELSE
    TALK "❌ Invalid code. Please try again."
END IF

Appointment Reminder

' Send appointment reminder
appointment_date = FORMAT(appointment.datetime, "MMMM D, YYYY")
appointment_time = FORMAT(appointment.datetime, "h:mm A")

message = "Reminder: Your appointment is on " + appointment_date
message = message + " at " + appointment_time + ". Reply YES to confirm."

SEND SMS patient.phone, message

' Set up response handler
ON "sms:received" FROM patient.phone
    IF UPPER(params.message) = "YES" THEN
        UPDATE "appointments", appointment.id, "status", "confirmed"
        SEND SMS patient.phone, "Thank you! Your appointment is confirmed."
    END IF
END ON

Multi-Language SMS

' Send SMS in user's preferred language
lang = GET USER MEMORY "language"

IF lang = "es" THEN
    message = "Gracias por tu compra. Tu pedido está en camino."
ELSE IF lang = "pt" THEN
    message = "Obrigado pela sua compra. Seu pedido está a caminho."
ELSE
    message = "Thank you for your purchase. Your order is on the way."
END IF

SEND SMS user.phone, message

Using Different Providers

' Use specific provider for different regions
country_code = LEFT(phone, 3)

IF country_code = "+1 " THEN
    ' Use Twilio for US/Canada
    SEND SMS phone, message, "twilio"
ELSE IF country_code = "+55" THEN
    ' Use local provider for Brazil
    SEND SMS phone, message, "vonage"
ELSE
    ' Default provider
    SEND SMS phone, message
END IF

Emergency Alert

' Send emergency notification to multiple recipients
alert_message = "⚠️ ALERT: System maintenance in 30 minutes. Save your work."

contacts = FIND "emergency_contacts", "notify=true"

FOR EACH contact IN contacts
    SEND SMS contact.phone, alert_message
    WAIT 100  ' Small delay between messages
NEXT

TALK "Emergency alert sent to " + COUNT(contacts) + " contacts"

Delivery Tracking

' Send delivery status updates
ON "delivery:status_changed"
    order = FIND "orders", "id=" + params.order_id
    
    SWITCH params.status
        CASE "shipped"
            message = "📦 Your order has shipped! Tracking: " + params.tracking_number
        CASE "out_for_delivery"
            message = "🚚 Your package is out for delivery today!"
        CASE "delivered"
            message = "✅ Your package has been delivered. Enjoy!"
        DEFAULT
            message = "Order update: " + params.status
    END SWITCH
    
    SEND SMS order.phone, message
END ON

Phone Number Formats

The keyword accepts various phone number formats:

FormatExampleRecommended
E.164+14155551234✅ Yes
National(415) 555-1234⚠️ Converted
Digits only4155551234⚠️ Needs country

Best Practice: Always use E.164 format (+ followed by country code and number).

Message Length

TypeCharactersNotes
Single SMS160Standard ASCII
Unicode SMS70Emojis, non-Latin scripts
Concatenated153 × segmentsLong messages split
' Check message length before sending
IF LEN(message) > 160 THEN
    TALK "Warning: Message will be sent as multiple SMS"
END IF

SEND SMS phone, message

Error Handling

' Handle SMS errors gracefully
TRY
    result = SEND SMS phone, message
    
    IF NOT result THEN
        ' Log the failure
        INSERT "sms_failures", phone, message, NOW()
        
        ' Fallback to email if available
        IF user.email <> "" THEN
            SEND MAIL user.email, "Notification", message
        END IF
    END IF
CATCH error
    TALK "SMS service unavailable: " + error.message
END TRY

Cost Considerations

SMS messages incur costs per message sent. Consider:

  • Using SEND WHATSAPP for free messaging when possible
  • Batching non-urgent messages
  • Using templates to keep messages under 160 characters

Compliance

When sending SMS messages, ensure compliance with:

  • TCPA (US) - Require consent before sending
  • GDPR (EU) - Document consent and provide opt-out
  • LGPD (Brazil) - Similar consent requirements
' Check opt-in before sending
IF GET USER MEMORY "sms_opt_in" = true THEN
    SEND SMS phone, message
ELSE
    TALK "User has not opted in to SMS notifications"
END IF

See Also

Implementation

The SEND SMS keyword is implemented in src/basic/keywords/sms.rs with support for multiple providers through a unified interface.