2-Way SMS Texting with Twilio - Implementation Status

Status: IMPLEMENTED - Awaiting A2P Approval

All code is complete and deployed. UI is hidden until A2P 10DLC approval.

Last Updated: December 24, 2025


What's Been Built


To Enable When A2P Approved

Step 1: Update Production .env

Add this line to /home/forge/leadmachine_fyi.on-forge.com/current/.env:


SMS_ENABLED=true

Step 2: Configure Twilio Webhook

In Twilio Console:

  1. Go to Phone Numbers+13215870133
  2. Under MessagingA message comes in:
- URL: https://app.leadmachine.fyi/api/webhooks/twilio-sms.php - Method: POST

Step 3: Test

  1. Go to Profile → Settings → SMS Notifications card should now appear
  2. Enable SMS notifications
  3. Share a contact via SMS to +13215870133 → should create a lead


Current Environment Variables (Production)


TWILIO_ACCOUNT_SID=AC469c85b936e7e72d5e58e61677c95521
TWILIO_AUTH_TOKEN=(configured)
TWILIO_FROM_NUMBER=+13215870133
SMS_ENABLED=(not set - UI hidden)

Feature Summary

Feature 1: SMS Lead Notifications

  • Users opt-in via Profile → Settings → SMS Notifications
  • When a lead is assigned, user gets SMS with lead details and link
  • User can reply with a number (1-5) to update lead status

Feature 2: vCard Contact Import

  • User shares a phone contact via SMS to Twilio number
  • System receives MMS with vCard attachment
  • Parses vCard and creates lead assigned to user
  • Sends confirmation SMS with link to new lead
  • Handles duplicates (warns if email already exists)

Files Modified

ComponentStatusLocation
-----------------------------
Twilio webhook✅ Done/api/webhooks/twilio-sms.php
SMS sending functions✅ Done/includes/sms-helpers.php
Lead assignment SMS✅ DoneCalled in create-lead.php, update-lead.php
SMS preferences storage✅ Donelm_users.sms_preferences (JSON)
SMS transaction logging✅ Donelm_sms_messages table
SMS preferences API✅ Done/api/user/update-sms-preferences.php
SMS opt-in UI✅ Done/pages/profile.php (hidden behind env flag)
vCard parsing✅ Doneparse_vcard() in /includes/sms-helpers.php
Lead from vCard✅ Donecreate_lead_from_vcard() in /includes/sms-helpers.php
MMS/vCard webhook handling✅ Done/api/webhooks/twilio-sms.php
Twilio media fetching✅ Donefetch_twilio_media() in webhook
FileWhat Was Added
----------------------
/pages/profile.phpSMS Notifications card with opt-in toggles (line 583-666)
/includes/sms-helpers.phpparse_vcard() and create_lead_from_vcard() functions
/api/webhooks/twilio-sms.phpfetch_twilio_media() and MMS handling block

Quick Resume Command

When A2P is approved, run:

bash
ssh [email protected] "cd /home/forge/leadmachine_fyi.on-forge.com/current && echo 'SMS_ENABLED=true' >> .env"

Then configure the Twilio webhook and test.