简体   繁体   中英

How to do a callback with user's number when user replies STOP via SMS using Twilio?

I would like to know how to get user's number or some data to update the database to be opted-out in my server using callback from Twilio when user replies STOP via SMS.

I'm using PHP.

How can I solve this issue?

I managed to compare $_POST['Body'] with some filter functions, here is my complete code:

// You need to include Twilio library path here... for example require_once '/path/to/twilio-lib/autoload.php';
use Twilio\Twiml;

global $wpdb;

$response = new Twiml;


    if (!empty($_POST))
    {
        $number = $_POST['From'];
        $body = $_POST['Body'];
        $default = "Hi " .$number. ", I'm a bot, please do not reply until you will get an update in some day. Have a nice day!";   


        $result = preg_replace("/[^A-Za-z0-9]/u", " ", $body); 
        $result = trim($result); 
        $result = strtolower($result); 



        //words to match and $result must be lowercase to define.
        if ($result == 'stop' || $result == 'stopall' || $result == 'cancel' || || $result == 'end') || $result == 'quit' || $result == 'unsubscribe'{
         //Your function to update database with $number

        }
        else if ($result == 'start' || $result == 'yes' || $result == 'unstop'){
            $response->message('Thanks for re-subscribing');
           //Your function to update database, again with $number
        }   
         else {
            $response->message($default);
        }

        print $response;
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM