当用户使用Twilio通过SMS回复STOP时,如何用用户号码进行回叫?

时间:2018-09-28 20:48:08

标签: php twilio twilio-api twilio-php

我想知道当用户通过SMS回复STOP时,如何使用Twilio的回叫获取用户的号码或一些数据以更新数据库以选择退出服务器。

我正在使用PHP。

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

我设法将$_POST['Body']与某些过滤器功能进行了比较,这是我完整的代码:

// 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;
    }