landline number filtering before send
-
Before I write a custom plugin or modify the texty plugin Thought i would reach out and see if this is a feature y’all may want to intergrate. Twilio has a lookup API to verify if the number is a landline or mobile number, it would be cheaper to pay the $0.005 per lookup than to send an undeliverable message.
I linked to the post from twilio explaining it, also here is the code I am about to test to add verification to the phone number but should work directly in your plugin as well. I look forward to your reply, thank you!<?php
/**
* twilio_lookup.php
*/
require 'vendor/autoload.php';
use Twilio\Rest\Client;
function is_mobile_number($phone_number) {
$sid = 'YOUR_TWILIO_ACCOUNT_SID';
$token = 'YOUR_TWILIO_AUTH_TOKEN';
$client = new Client($sid, $token);
try {
$number = $client->lookups->v1->phoneNumbers($phone_number)->fetch(["type" => "carrier"]);
return $number->carrier['type'] === 'mobile';
} catch (Exception $e) {
error_log("Error: " . $e->getMessage());
return false;
}
}
// Example usage
$phone_number = '+1234567890';
if (is_mobile_number($phone_number)) {
echo "It's a mobile number.";
} else {
echo "It's not a mobile number.";
}<?php
/**
* twilio-texty-integration.php
* Plugin Name: Twilio Texty Integration
* Description: Integrates Twilio Lookup API with Texty plugin to filter landlines.
* Version: 1.0
* Author: Your Name
*/
function filter_landline_numbers($phone_number) {
require_once 'path/to/twilio_lookup.php';
return is_mobile_number($phone_number);
}
function custom_send_sms($message, $phone_number) {
if (filter_landline_numbers($phone_number)) {
// Call the original Texty send function
texty_send_sms($message, $phone_number);
} else {
error_log("The number $phone_number is not a mobile number.");
}
}
add_action('texty_send_sms', 'custom_send_sms', 10, 2);The page I need help with: [log in to see the link]
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- You must be logged in to reply to this topic.