Twilio Integration
Overview
Twilio is used for sending SMS messages — OTPs, viewing notifications, friend invitations, and agent alerts.
Configuration
Twilio credentials are hardcoded/stored as globals:
// Account SID
$sid = "ACb82f79aecb94132848c1c7b40cfc3d36";
// Auth token (from configdb.php)
$ttoken = "4ea7d07a2987e497774d559c1ba60432";The auth token ($ttoken) is set in api/include/configdb.php and available globally.
Sending SMS
Via notificationUtils.php
function sendText(array $numbers, string $text)
{
$client = new Twilio\Rest\Client($sid, $ttoken);
foreach ($numbers as $number) {
$client->messages->create(
normaliseNumber($number),
[
'from' => $USA ? '+14027611623' : 'Housr',
'body' => $text
]
);
}
}Via sendSMS.php (standalone)
function sendSMS(array $numbers, string $text)Identical logic to sendText(), implemented in a separate file for inclusion by endpoints that don’t use the notification utils.
Via otpUtils.php (OTP-specific)
function sendText($token, $phoneNumber, $otp)Slightly different signature (single number, not array). Used specifically for OTP delivery.
Regional Differences
| Aspect | UK | US |
|---|---|---|
| Sender | Housr (alphanumeric sender ID) | +14027611623 (phone number) |
| OTP message | OTP: 123456\n\nThanks,\n\nHousr Team | OTP: 123456\n\nThanks,\n\nmyhousr Team |
| Agent SMS | Links to housrportal.co.uk | Links to portal.myhousr.com |
Phone Number Normalisation
File: api/utils/normaliseNumber.php
All phone numbers are normalised before sending via the normaliseNumber() function. This handles various input formats and converts them to E.164 format required by Twilio.
Usage Contexts
| Context | Trigger |
|---|---|
| OTP | send_otp.php - Password reset/verification |
| Viewing Request | requestViewing.php - SMS to agent (if opted in via landlord_preferences.contact_through_sms) |
| Friend Invitation | sendInviteSMS.php - Invite someone to join Housr |
| Scheduled Notifications | addScheduledViewingText.php - Pre/post viewing reminders |
Dependencies
"twilio/sdk": "^7.0"Last updated on