Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit b71634e1815bb8caf289dbb7570b42483e5bfa5d @Beans0063 committed Jun 1, 2011
@@ -0,0 +1,2 @@
+.DS_Store
+*.swp
3 README
@@ -0,0 +1,3 @@
+Demo app for call tracking with Twilio.com
+Download and customize me
+Free $30 trial credit at http://www.twilio.com
@@ -0,0 +1,37 @@
+Text-to-Vote
+============
+
+Text-to-Vote is a simple web app that allows you to do realtime polling through
+SMS.
+
+Text-to-Vote works with the Twilio API, so you'll need an account and phone
+number at Twilio before you can get started. Twilio sells simple, pay as you
+go phone services, and you can sign up for a free account with $30 of free
+credits at [http://www.twilio.com](http://www.twilio.com).
+
+Installation
+============
+
+Installation of Text-to-Vote is as simple as copying the folder, making it
+writeable, editing the configuration file, creating the database and pointing
+Twilio to the correct handlers.
+
+1. Copy the folder to your server.
+
+2. Make the folder writeable.
+
+3. Edit `/include/config.php`
+
+4. Run `create_database.php` by browsing to `http://yourserver/Text-to-Vote/create_database.php`
+
+5. Go to your [Twilio numbers page](https://www.twilio.com/user/account/phone-numbers/)
+ and point the Voice URL to `http://yourserver/Text-to-Vote/handle_incoming_call.xml`
+ (leave the default POST method selected) and point the SMS URL to
+ `http://yourserver/Text-to-Vote/handle_incoming_sms.php`
+
+License
+=======
+
+Copyright (C) 2011 Rahim Sonawalla ([rahim@twilio.com](mailto:rahim@twilio.com) / [@rahims](http://twitter.com/rahims)) and Will Light ([wrl@illest.net](mailto:wrl@illest.net) / [@dudestache](http://twitter.com/dudestache)).
+
+Released under the [MIT license](http://www.opensource.org/licenses/mit-license.php).
Binary file not shown.
@@ -0,0 +1,14 @@
+<?php
+ require_once('./include/db.php');
+
+ if (file_exists('votes.sqlite') != true)
+ {
+ $db = new DB();
+ $db->init();
+
+ echo 'Database created.';
+ }
+ else {
+ echo 'Database already exists. Feel free to delete me.';
+ }
+?>
@@ -0,0 +1,87 @@
+html {
+ background-color: #fdfdfd;
+}
+
+body {
+ font: 1em Helvetica, Arial, sans-serif;
+ color: #222;
+}
+
+#container {
+ width: 80%;
+ margin: 0 auto;
+ margin-top: 1em;
+}
+
+#footer{
+ margin-top:2em;
+}
+
+h1 {
+ font-size: 2.2em;
+ text-align: center;
+}
+
+h3 {
+ font-size: 1.4em;
+ float:left;
+}
+
+p img {
+ float:right;
+}
+
+strong {
+ font-weight: bold;
+ text-shadow: #bbb 0px 1px 3px;
+}
+
+.confirm {
+ background-color:#9CFF9F;
+ border:1px solid #96ED9B;
+ font-size:1em;
+}
+#rounded-corner
+{
+ font-family: "Lucida Sans Unicode", "Lucida Grande", Sans-Serif;
+ font-size: 12px;
+ width: 100%;
+ text-align:left;
+ border-collapse: collapse;
+ margin-bottom:10px;
+}
+#rounded-corner thead th.rounded-company
+{
+ background: #b9c9fe url('../images/left.png') left -1px no-repeat;
+}
+#rounded-corner thead th.rounded-q4
+{
+ background: #b9c9fe url('../images/right.png') right -1px no-repeat;
+}
+#rounded-corner th
+{
+ padding: 8px;
+ font-weight: normal;
+ font-size: 13px;
+ color: #039;
+ background: #b9c9fe;
+}
+#rounded-corner td
+{
+ padding: 8px;
+ background: #e8edff;
+ border-top: 1px solid #fff;
+ color: #669;
+}
+#rounded-corner tfoot td.rounded-foot-left
+{
+ background: #e8edff url('../images/botleft.png') left bottom no-repeat;
+}
+#rounded-corner tfoot td.rounded-foot-right
+{
+ background: #e8edff url('../images/botright.png') right bottom no-repeat;
+}
+#rounded-corner tbody tr:hover td
+{
+ background: #d0dafd;
+}
@@ -0,0 +1,126 @@
+/*
+Copyright (c) 2009, Yahoo! Inc. All rights reserved.
+Code licensed under the BSD License:
+http://developer.yahoo.net/yui/license.txt
+version: 3.0.0
+build: 1549
+*/
+/*
+ TODO will need to remove settings on HTML since we can't namespace it.
+ TODO with the prefix, should I group by selector or property for weight savings?
+*/
+html{
+ color:#000;
+ background:#FFF;
+}
+/*
+ TODO remove settings on BODY since we can't namespace it.
+*/
+/*
+ TODO test putting a class on HEAD.
+ - Fails on FF.
+*/
+body,
+div,
+dl,
+dt,
+dd,
+ul,
+ol,
+li,
+h1,
+h2,
+h3,
+h4,
+h5,
+h6,
+pre,
+code,
+form,
+fieldset,
+legend,
+input,
+textarea,
+p,
+blockquote,
+th,
+td {
+ margin:0;
+ padding:0;
+}
+table {
+ border-collapse:collapse;
+ border-spacing:0;
+}
+fieldset,
+img {
+ border:0;
+}
+/*
+ TODO think about hanlding inheritence differently, maybe letting IE6 fail a bit...
+*/
+address,
+caption,
+cite,
+code,
+dfn,
+em,
+strong,
+th,
+var {
+ font-style:normal;
+ font-weight:normal;
+}
+/*
+ TODO Figure out where this list-style rule is best set. Hedger has a request to investigate.
+*/
+li {
+ list-style:none;
+}
+
+caption,
+th {
+ text-align:left;
+}
+h1,
+h2,
+h3,
+h4,
+h5,
+h6 {
+ font-size:100%;
+ font-weight:normal;
+}
+q:before,
+q:after {
+ content:'';
+}
+abbr,
+acronym {
+ border:0;
+ font-variant:normal;
+}
+/* to preserve line-height and selector appearance */
+sup {
+ vertical-align:text-top;
+}
+sub {
+ vertical-align:text-bottom;
+}
+input,
+textarea,
+select {
+ font-family:inherit;
+ font-size:inherit;
+ font-weight:inherit;
+}
+/*to enable resizing for IE*/
+input,
+textarea,
+select {
+ *font-size:100%;
+}
+/*because legend doesn't inherit in IE */
+legend {
+ color:#000;
+}
@@ -0,0 +1,13 @@
+<?php
+ require_once('./include/db.php');
+
+ $db = new DB();
+ $teams = $db->get_teams();
+
+ foreach ($teams as $team)
+ {
+ $votes[] = (int) $team['votes'];
+ }
+
+ echo json_encode($votes);
+?>
@@ -0,0 +1,9 @@
+<?php
+ require_once('./include/config.php');
+ header('Content-type: text/xml');
+ $db = new DB();
+ $db->save_call();
+?>
+<Response>
+ <Dial action="record_call.php" method="GET" record="true"><?php echo(AGENT_NUMBER);?></Dial>
+</Response>
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<Response>
+ <Dial action="record_call.php" record="true"></Dial>
+</Response>
@@ -0,0 +1,22 @@
+<?php
+ require_once('./include/db.php');
+
+ header('Content-type: text/xml');
+ echo '<Response>';
+
+ $phone_number = $_REQUEST['From'];
+ $team_number = (int) $_REQUEST['Body'];
+
+ if ( (strlen($phone_number) >= 10) && ($team_number > 0) )
+ {
+ $db = new DB();
+
+ $response = $db->save_vote($phone_number, $team_number);
+ }
+ else {
+ $response = 'Sorry, I didn\'t understand that. Text the team number to vote. For example, texting 1 will vote for Team 1.';
+ }
+
+ echo '<Sms>'.$response.'</Sms>';
+ echo '</Response>';
+?>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,34 @@
+<?php
+ require "twilio.php";
+ require "db.php";
+ define('AGENT_NUMBER', '8583829141');
+ $ApiVersion = "2010-04-01";
+ $AccountSid = "AC55887ef8de75bc64ab60f38bd7c8b42e";
+ $AuthToken = "2fa7a06401bf56a71a8fb6e044977a6f";
+
+ function format_phone($phone)
+ {
+ $phone = preg_replace("/[^0-9]/", "", $phone);
+
+ if(strlen($phone) == 7)
+ return preg_replace("/([0-9]{3})([0-9]{4})/", "$1-$2", $phone);
+ elseif(strlen($phone) == 10)
+ return preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/", "($1) $2-$3", $phone);
+ else
+ return $phone;
+ }
+
+ class Util {
+ public static function get_all_twilio_numbers() {
+ global $ApiVersion, $AccountSid, $AuthToken;
+ $twilio_numbers=array();
+ $client = new TwilioRestClient($AccountSid, $AuthToken);
+ $response = $client->request("/$ApiVersion/Accounts/$AccountSid/IncomingPhoneNumbers", "GET"); // Get all twilio phone numbers
+ foreach($response->ResponseXml->IncomingPhoneNumbers->IncomingPhoneNumber AS $number){
+ $twilio_numbers[format_phone($number->PhoneNumber)]=$number->FriendlyName;
+ }
+ return $twilio_numbers;
+ }
+ }
+
+?>
Oops, something went wrong.

0 comments on commit b71634e

Please sign in to comment.