- Twilio Cookbook(Second Edition)
- Roger Stringer
- 239字
- 2021-07-16 12:06:39
Adding tracking for each user
We want to be able to track each user's response to the survey we sent and this is how we will do that.
In the previous recipe, we stored the phone number, survey ID, and the unique session ID for each person we sent the survey to.
Now we want to store each user's response for tracking later.
Getting ready
The complete source code for this recipe can be found in the Chapter3/
folder.
How to do it...
Let's set up tracker.php
that listens for responses from our subscribers using the following steps:
- On your web server, create a file and name it
tracker.php
with the following code:<?php include("config.php"); include("pdo.class.php"); $pdo = Db::singleton(); if( isset($_POST['Body']) ){ $phone = $_POST['From']; $phone = str_replace('+','',$phone); $action = strtolower($_POST['Body']); $sid = $_POST['SmsSid']; $sql = "UPDATE responses SET answer='{$action}' WHERE phone_number='{$phone}' AND sms_sid='{$sid}'"; $pdo->exec( $sql ); $msg = "Your answer has been recorded"; print_sms_reply($msg); } function print_sms_reply ($sms_reply){ echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; echo "<Response>\n<Sms>\n"; echo $sms_reply; echo "</Sms></Response>\n"; } ?>
- Finally, you have to point your Twilio phone number to it.
Insert the URL to this page in the SMS Request URL box. Then, any calls that you receive on this number will be processed via
tracker.php
.
How it works...
When a user replies to a survey, the tracker.php
file is triggered.
We then perform a look-up based on their phone number and unique session ID and store their response in the Responses
table.
Then, when we display the results later, we can use the responses, associate them with the answers we sent, and get a look at what people think.
- 網(wǎng)絡(luò)云百問(wèn)百答
- 物聯(lián)網(wǎng)標(biāo)準(zhǔn)化指南
- Cisco OSPF命令與配置手冊(cè)
- SOA用戶(hù)指南
- Mastering Machine Learning for Penetration Testing
- Learning Karaf Cellar
- Drush User’s Guide
- Wireshark網(wǎng)絡(luò)分析就這么簡(jiǎn)單
- 6G:面向2030年的移動(dòng)通信
- Learning Storm
- 高級(jí)網(wǎng)絡(luò)技術(shù)
- 轉(zhuǎn)化:提升網(wǎng)站流量和轉(zhuǎn)化率的技巧
- 園區(qū)網(wǎng)絡(luò)架構(gòu)與技術(shù)
- 物聯(lián)網(wǎng)與智慧農(nóng)業(yè)
- SRv6網(wǎng)絡(luò)部署指南