WP Residence Help WP Residence Help

  • WPRESIDENCE
  • Video Tutorials
  • Client Support
  • API
Home / WPResidence / WPEstate CRM / WPResidence CRM Twilio SMS — Developer Reference

WPResidence CRM Twilio SMS — Developer Reference

57 views 0

Developer documentation for the Twilio SMS integration in the WPResidence real estate CRM. Entry point is libs/twilio.php.

Send API

wpestate_crm_send_notification_sms( $event, $data )

Flow:

  1. Check global flag crm_twilio_enabled. Abort if falsy.
  2. Check per-event flag crm_notify_sms_{event}_enabled. Defaults to true unless explicitly ‘0’.
  3. Validate all three credentials present (crm_twilio_account_sid, crm_twilio_auth_token, crm_twilio_from_number).
  4. Determine recipient phone: $data[‘agent_phone’], or user meta crm_phone, or user meta billing_phone.
  5. Resolve placeholders in the body template via wpestate_crm_resolve_placeholders().
  6. POST to Twilio REST API.
  7. Record sms_sent activity on the contact on success.

Twilio REST Call

  • Endpoint: https://api.twilio.com/2010-04-01/Accounts/{account_sid}/Messages.json
  • Method: POST via wp_remote_post()
  • Auth: Basic Auth header, value base64_encode(“account_sid:auth_token”).
  • Body: form-encoded with From, To, Body.

Settings

Key Default
crm_twilio_enabled false
crm_twilio_account_sid empty
crm_twilio_auth_token empty
crm_twilio_from_number empty
crm_notify_sms_new_contact_enabled true
crm_notify_sms_new_contact_body see below

Default body template: New lead: {contact_name} ({contact_email}). {listing_title}. View: {crm_contact_url}

Event Integration

Currently called from wpestate_crm_on_new_contact_notification() (libs/notifications.php) after email sending if the function exists. The design anticipates future events (deal_won, task_overdue) – add them by calling wpestate_crm_send_notification_sms($new_event, $data) from the relevant hook.

Test SMS AJAX

Property Value
Action wpestate_crm_send_test_sms (no _nopriv – admin-only)
Nonce via wpestate_crm_verify_ajax_nonce(‘send_test_sms’)
Capability manage_options
POST param phone
Test message Test SMS from {site_name} CRM. If you received this, Twilio is configured correctly.

Returns JSON success/error with the Twilio response body or a descriptive error (missing credentials, invalid phone, HTTP error code from Twilio).

Placeholder Support

Uses the shared wpestate_crm_resolve_placeholders() function – same 20 placeholders as the email module. No SMS-specific placeholders.

Error Handling

  • wp_remote_post() errors: logged, function returns false, no activity record.
  • HTTP >= 400: logged with response body, no activity record.
  • Missing phone on recipient: silent skip (expected – not every agent has a phone on file).

Security

Credentials stored plain-text in the CRM settings array (standard WordPress pattern). For production deployments, consider storing the crm_twilio_auth_token in wp-config.php as a constant and reading it via a filter rather than exposing it in the admin UI.

Extending

  • Add a new SMS event by registering a new settings pair (crm_notify_sms_{event}_enabled and crm_notify_sms_{event}_body) and calling the send API from the relevant hook.
  • Replace Twilio with another provider by forking libs/twilio.php into a child plugin and overriding wpestate_crm_send_notification_sms with your own implementation.
WPResidence / WPEstate CRM

Related Articles

  • WPResidence CRM Security Model — Developer Reference
  • CRM Security and Data Privacy
  • WPResidence CRM Installation and Updates — Developer Reference
  • Installing and Updating the WPResidence CRM

Help Categories

  • 18Agent, Agency & Developers
  • 5Blog Posts & Blog Lists
  • 38Elementor Shortcodes Built-In
  • 45FAQ
  • 15Footer
  • 5Getting Started
  • 37Header
  • 2IDX & MLSImport
  • 6Installation & Setup
  • 23Installation FAQ
  • 23Maps & Location Settings
  • 21Multi-Language Third Party Plugins
  • 6Other Third party Plugins
  • 19Pages
  • 4Payments & Monetization
  • 20Property Lists, Categories & Archive
  • 36Property Pages & Layouts
  • 31Search & Filtering
  • 162Technical how to | Custom Code Required
  • 8Technical: Actions and filters
  • 6Technical: Child Theme
  • 86Theme Options & Global Settings
  • 6Translations & Languages
  • 16WPBakery Shortcodes
  • 51WPResidence / WPEstate CRM
  • 50WPResidence 5.0 Documentation
  • 8WPResidence Elementor Studio
  • 50WPResidence Translate Plugin

Join Us On

Powered by WP Estate - All Rights Reserved
  • WPRESIDENCE
  • Video Tutorials
  • Client Support
  • API