WhyBuy AI SMS Assistant (WordPress + Twilio + OpenAI) — AI‑Powered SMS Support with Reliable Webhooks
A WordPress plugin that receives inbound SMS via Twilio webhooks, routes messages through scenarios + FAQs, generates controlled AI responses, and logs every interaction for support teams.
Looking for custom WordPress plugin development that integrates AI with real communication channels? Browse my portfolio or services, and reach out to discuss your use case.
Overview
I built WhyBuy AI SMS Assistant to help businesses handle customer support over SMS without sacrificing control, reliability, or auditability. The plugin integrates Twilio SMS with an AI response layer, while keeping the operational pieces inside WordPress: settings, logs, scenarios, FAQs, and debugging tools.
Instead of responding with “free-form chatbot behavior,” messages are routed through a scenario + FAQ system so the assistant stays consistent, safe, and aligned with support workflows.
Challenge
The Problem: SMS support is high-volume and time-sensitive, but it’s also constrained: short messages, unpredictable user input, and webhook reliability requirements. A working SMS assistant needs to do more than “generate replies.”
The project needed to solve several practical issues:
- Webhook Reliability — Incoming POST requests must be processed without redirects or dropped parameters
- Controlled Responses — SMS replies must stay concise, clear, and within a predictable length
- Support Workflow Alignment — Route messages into scenarios/FAQs so replies match real operations
- Auditability — Store conversations and message logs for debugging and support visibility
- Operational Debugging — Provide internal debug logs and test tooling to validate webhooks end-to-end
- Maintainable Architecture — Keep Twilio handling, AI prompting, and routing cleanly separated
Solution Architecture
The Solution: A WordPress-first architecture that treats Twilio as a delivery mechanism and WordPress as the
system of record. Incoming SMS messages are received via WordPress REST API webhook endpoints, normalized and logged,
then routed through scenario/FAQ context before generating a controlled AI reply.
- Twilio Inbound SMS Webhooks
Twilio sends inbound message payloads to stable REST endpoints dedicated to webhook handling. - Webhook Processing Layer
Validates and normalizes fields (From/To/Body), logs the event, and updates the conversation state. - Scenario + FAQ Routing
Selects the most relevant support scenario/FAQ context so responses stay consistent and useful. - OpenAI Response Generation
Generates a concise SMS-ready reply with length constraints and support-friendly tone. - WordPress Admin UI
Provides settings, configuration URLs, logs, debug views, and scenario/FAQ management.
Implementation Highlights
1) REST-Based Webhooks (Built for Real-World Reliability)
Webhook endpoints were implemented using WordPress REST routes so Twilio POST requests are processed consistently. This avoids common issues where redirects or rewrites can cause webhook payloads to arrive empty.
2) Scenario + FAQ Context for Consistent Support
SMS conversations are routed using a scenario/FAQ system, which keeps responses aligned to the business and reduces randomness. Scenarios are prioritized (e.g., high/normal/low) so urgent flows can win routing decisions when multiple matches are possible.
- Structured routing — Match best scenario/FAQ instead of improvising
- Priority handling — Higher priority scenarios take precedence
- Message normalization — Normalize user input before matching
3) Admin-First Operations (Logs + Debugging Tools)
The plugin stores message logs and conversation history in WordPress so support teams and admins can troubleshoot quickly. Debug logs help confirm whether Twilio is reaching the site, what parameters were received, and how the AI response was produced.
Technical Implementation Details
WordPress Integration Patterns
- Webhook Endpoints — REST routes designed for external POST requests
- Data Handling — Strict field normalization and sanitization of inbound payload values
- Persistence — Custom DB tables for logs, conversations, FAQs, and scenarios
- Admin UX — Clear Twilio configuration URLs, system info, and debug tools
Code Examples (Simplified)
1) REST API endpoint for incoming Twilio SMS (accept POST payload + return TwiML):
add_action('rest_api_init', function () {
register_rest_route('whybuy-sms/v1', '/webhook/incoming', array(
'methods' => 'POST',
'permission_callback' => '__return_true',
'callback' => function (WP_REST_Request $request) {
$params = $request->get_params();
$twilio = WhyBuy_SMS_Twilio::get_instance();
$twiml = $twilio->process_incoming_sms($params);
return new WP_REST_Response($twiml, 200, array('Content-Type' => 'text/xml'));
},
));
});
2) Normalize + validate inbound SMS fields (From/To/Body):
$from = isset($params['From']) ? sanitize_text_field($params['From']) : '';
$to = isset($params['To']) ? sanitize_text_field($params['To']) : '';
$body = isset($params['Body']) ? sanitize_textarea_field($params['Body']) : '';
if ($from === '' || $to === '' || $body === '') {
// Log debug event for troubleshooting
// Return minimal TwiML to keep Twilio happy
}
3) Scenario/FAQ routing before generating the AI reply (controlled workflow):
$router = new WhyBuy_SMS_Router($scenario_repository, $faq_repository);
$match = $router->match_best($body, array(
'from' => $from,
'to' => $to,
));
$context = $match ? $match->build_context() : '';
$reply = $ai->generate_sms_reply($body, $context, array(
'max_chars' => 600,
));
Results & Impact
🚀 Measurable Improvements
Faster response times — Customers receive immediate replies for common questions and triage flows.
Higher support consistency — Scenario/FAQ routing keeps responses aligned with documented policies and workflows.
Operational Benefits
- Reduced repetitive manual replies — Common SMS questions can be handled automatically
- Better triage quality — Scenarios guide the assistant to ask the right questions
- Clear visibility — Admin logs show exactly what happened for each message
Technical Achievements
- Webhook stability — REST-based POST handling improves delivery reliability
- Audit-friendly data model — Conversations + logs stored for debugging and operations
- Maintainable structure — Twilio processing, routing, and AI generation are cleanly separated
Technologies & Standards
Lessons Learned
- Reliability beats cleverness — Webhooks must work predictably before anything else matters
- Routing improves quality — Scenarios/FAQs reduce randomness and increase consistency
- Logs are part of the product — Debugging tools save time in real operations
Want an AI-powered SMS assistant integrated into WordPress?
Contact me
to discuss a similar build, or explore more of my
WordPress development work.
