Find Out Who Has a Crush On You With CrushGram
Time to read: 2 minutes
For CrushGram, we only needed to send outbound SMS. We just took the code sample from Twilio SMS Quickstart: Sending Text Messages via the REST API and created the function below sendSMS($number, $message)
[code lang=”php”]
function sendSMS($number, $message) {
// include the PHP TwilioRest library
$ApiVersion = "2010-04-01";
$AccountSid = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$AuthToken = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$twilioNumber = "xxx-xxx-xxx";
$client = new TwilioRestClient($AccountSid, $AuthToken);
// Send a new outgoinging SMS by POSTing to the SMS resource */
$response =
$client->request("/$ApiVersion/Accounts/$AccountSid/SMS/Messages",
"POST", array(
"To" => $number,
"From" => $twilioNumber,
"Body" => $message
));
if($response->IsError) echo "Error: {$response->ErrorMessage}";
}
[/code]
We then took this function and embedded it everywhere else that needed to send SMS, such as when someone inserts a crush with a name and number.
[code lang=”php”]
function insertCrush($fromNumber, $toNumber, $toFirstName = ”, $oneWord = ”) {
$conn = get_db_conn();
$sqlStr = sprintf(‘INSERT INTO crushes SET fromNumber = "%s",
toNumber = "%s", toFirstName = "%s", oneWord = "%s"’,
mysql_real_escape_string($fromNumber),
mysql_real_escape_string($toNumber),
mysql_real_escape_string($toFirstName),
mysql_real_escape_string($oneWord));
mysql_query($sqlStr, $conn);
if($oneWord != ”) $oneWord = ‘ with note: "’.$oneWord.’".’;
else $oneWord = ‘.’;
if(!checkMatch($fromNumber, $toNumber)) {
$message = ‘Hi ‘.$toFirstName.’! A secret admirer sent you a
crushgram’.$oneWord.’ Find out who at crushgram.com!’;
sendSMS($toNumber, $message);
} else {
$fromFirstName = userDetailsFromCell($fromNumber, ‘firstName’);
$message = ‘Congrats ‘.$toFirstName.’! Your crush,
‘.$fromFirstName.’, also has a crush on you.’;
sendSMS($toNumber, $message);
$message = ‘Congrats ‘.$fromFirstName.’! Your crush,
‘.$toFirstName.’, also has a crush on you.’;
sendSMS($fromNumber, $message);
}
}
[/code]
The site took one night and four energy drinks to get off the ground. Besides Red Bulls, other technologies we used included LAMP stack and lots of JQuery on top of Twilio’s API. We also quickly integrated Facebook Likes, Super Rewards for offers, and PayPal.
Right now, we’re listening to our users to figure out where to go next. One thing we’ve been hearing is that people want the opportunity to anonymously message friends without it being romantic. We think there’s a lot to innovate in social relationships and text messaging: it’s real time, people always read their text messages, and it feels more personal — having someone’s number means you’re more than Facebook friends. Twilio makes achieving all of this a snap.
Thanks to Henry for taking the time to write about CrushGram! Have a social text messaging idea of your own? Get started with Twilio SMS for free.
Related Posts
Related Resources
Twilio Docs
From APIs to SDKs to sample apps
API reference documentation, SDKs, helper libraries, quickstarts, and tutorials for your language and platform.
Resource Center
The latest ebooks, industry reports, and webinars
Learn from customer engagement experts to improve your own communication.
Ahoy
Twilio's developer community hub
Best practices, code samples, and inspiration to build communications and digital engagement experiences.