This document explains the SMS notification system for Quarry Rentals using SignalWire.
The SMS integration sends automated text message notifications to customers for:
The following environment variables are configured in .env and .kamal/secrets:
SIGNALWIRE_PROJECT_ID=f44e91f7-e99f-4d00-938b-32abd1f56440
SIGNALWIRE_SPACE_URL=quarryllc.signalwire.com
SIGNALWIRE_TOKEN=PT6cb78671dcc14ad5992fb218c8012fcfa9663c7cf5130502
SIGNALWIRE_FROM_NUMBER=+14157611123
app/services/sms_service.rb)Core service for sending SMS messages via SignalWire API.
Methods:
send_sms(to:, body:, from:) - Send SMS to a single recipientsend_delivery_reminder(order) - Send delivery reminder for an ordersend_pickup_reminder(order) - Send pickup reminder for an ordersend_order_status_update(order, status) - Send order status updateExample:
sms_service = SmsService.new
result = sms_service.send_delivery_reminder(order)
# => { success: true, message_sid: "...", status: "queued", ... }
Sends delivery reminder SMS for a specific order.
SendDeliveryReminderSmsJob.perform_later(order.id)
Sends pickup reminder SMS for a specific order.
SendPickupReminderSmsJob.perform_later(order.id)
Sends status update SMS when order status changes.
SendOrderStatusSmsJob.perform_later(order.id, "confirmed")
Daily job that queues reminders for tomorrow's deliveries and pickups.
SendSmsRemindersJob.perform_now
The Order model automatically sends status update SMS when the status changes:
after_update :send_status_update_sms, if: :saved_change_to_status?
Orders table includes fields to track SMS notifications:
delivery_reminder_sent_at - Timestamp when delivery reminder was sentdelivery_reminder_sms_sid - SignalWire message SID for delivery reminderpickup_reminder_sent_at - Timestamp when pickup reminder was sentpickup_reminder_sms_sid - SignalWire message SID for pickup reminderHandles incoming SMS messages from SignalWire.
Endpoint: POST /webhooks/sms
The webhook:
SMS notifications are sent automatically when order status changes to:
confirmed - Order confirmationscheduled - Delivery scheduled notificationactive - Delivery completed notificationcompleted - Pickup completed notificationSet up a cron job to run daily at 5 PM:
# Using cron
0 17 * * * cd /path/to/app && bin/rails sms:send_reminders
# Or using whenever gem
every 1.day, at: '5:00 pm' do
rake "sms:send_reminders"
end
# Send delivery reminder for a specific order
sms_service = SmsService.new
result = sms_service.send_delivery_reminder(order)
# Send custom SMS
result = sms_service.send_sms(
to: "+15551234567",
body: "Your custom message here"
)
# Rails console
order = Order.last
sms_service = SmsService.new
# Test delivery reminder
result = sms_service.send_delivery_reminder(order)
puts result.inspect
# Test pickup reminder
result = sms_service.send_pickup_reminder(order)
puts result.inspect
# Test status update
result = sms_service.send_order_status_update(order, "confirmed")
puts result.inspect
# Test individual job
SendDeliveryReminderSmsJob.perform_now(order.id)
# Test daily reminders job
SendSmsRemindersJob.perform_now
bin/rails sms:send_reminders
Send a test SMS to +1 (415) 761-1123 to verify webhook is working.
Quarry Rentals: Your [product] delivery is scheduled for [date].
We'll call 30 min before arrival. Questions? Reply to this message or call us.
Quarry Rentals: Your [product] pickup is scheduled for [date].
Please ensure the container is accessible. Questions? Reply to this message.
# Find orders with sent delivery reminders
Order.where.not(delivery_reminder_sent_at: nil)
# Find orders with sent pickup reminders
Order.where.not(pickup_reminder_sent_at: nil)
# Check Rails logs
tail -f log/production.log | grep "SMS"
Monitor SMS delivery, costs, and responses at: https://quarryllc.signalwire.com/logs
The SmsService includes error handling for:
All errors are logged to Rails logger and return a hash with success: false and error message.
Check environment variables are loaded:
ENV['SIGNALWIRE_PROJECT_ID']
ENV['SIGNALWIRE_TOKEN']
ENV['SIGNALWIRE_SPACE_URL']
Verify customer has valid phone number:
order.contact&.phone.present?
Check SignalWire logs for delivery status
curl -X POST https://admin.quarryrents.com/webhooks/smsEnsure Solid Queue is running:
bin/rails solid_queue:start
Check job queue:
SolidQueue::Job.all