forked from maltzj/HackRU-2012
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwilioEndpoint.php
54 lines (38 loc) · 1.05 KB
/
twilioEndpoint.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
require 'configuration.php';
require 'twilio-php/Services/Twilio.php';
$text = trim(strtolower($_REQUEST["Body"]));
if($text === "fortune")
{
$account_id = $TWILIO_ACCOUNT_SID;
$token = $TWILIO_AUTH_TOKEN;
$client = new Services_Twilio($account_id, $token);
$mongo_db= $MONGO_URI;
$m= new Mongo($mongo_db);
$url = parse_url($mongo_db);
$db_name = preg_replace('/\/(.*)/', '$1', $url['path']);
// use the database we connected to
$db = $m->selectDB($db_name);
$collection = $db->selectCollection("Fortunes");
$results = $collection->find();
var_dump($results->count());
$all_fortunes = array();
/*while($results->hasNext())
{
array_push($all_fortunes, $results->next());
}*/
foreach($results as $doc)
{
if($doc["fortune"] != FALSE)
{
array_push($all_fortunes, $doc["fortune"]);
var_dump($doc);
}
}
$fortune_to_get = rand(0, count($all_fortunes)-1);
$message = $client->account->sms_messages->create(
"+14159686840",
$_REQUEST["From"],
$all_fortunes[$fortune_to_get]);
}
?>