-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent.php
More file actions
156 lines (118 loc) · 4.4 KB
/
Copy pathagent.php
File metadata and controls
156 lines (118 loc) · 4.4 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
session_start();
require_once('askfast/AskFast.php');
require_once('askfast/lib/session.php');
require_once('askfast/lib/answerresult.php');
$filename = 'agent.php';
$askfast = new AskFast();
define("MAX_BIDS",2);
// Please fill your database information and uncomment
//define("DB_SERVER", "");
//define("DB_USER", "");
//define("DB_PASS", "");
//define("DB_DB", "");
function getDBConn() {
$conn = mysql_connect(DB_SERVER, DB_USER, DB_PASS);
mysql_select_db(DB_DB);
return $conn;
}
function app_start() {
global $askfast;
global $filename;
$session = new Session();
$askfast->say('/audio/start.wav', $filename.'?function=bid&responder='.$session->getResponder());
$askfast->finish();
}
function app_bid() {
$session = new Session();
$responder = str_ireplace("@outbound","",$session->getResponder());
getDBConn();
$query = "SELECT * FROM bid";
$res = mysql_query($query);
$count = 0;
while(($row = mysql_fetch_assoc($res))!==false) {
if($row["Phonenumber"]==$responder)
return app_double_bid();
$count++;
}
if($count>=MAX_BIDS)
return app_bidding_closed();
return app_request_bid();
}
function app_receivebid() {
getDBConn();
$answer = new AnswerResult();
$responder = str_ireplace("@outbound","",$_GET["responder"]);
$query = "INSERT INTO bid (Amount, Phonenumber, DateTime) VALUES (".$answer->getAnswerText().", \"".$responder."\", NOW())";
$res = mysql_query($query);
return app_thankyou();
}
function app_request_bid() {
global $askfast;
global $filename;
$session = new Session();
$askfast->ask('/audio/bid.wav', AskFast::QUESTION_TYPE_OPEN, $filename.'?function=receivebid&responder='.$session->getResponder());
$askfast->finish();
}
function app_bidding_closed() {
global $askfast;
global $filename;
$askfast->say('/audio/closed.wav', $filename.'?function=hangup');
$askfast->finish();
}
function app_double_bid() {
global $askfast;
global $filename;
$askfast->say('/audio/double.wav', $filename.'?function=hangup');
$askfast->finish();
}
function app_thankyou() {
global $askfast;
global $filename;
getDBConn();
$query = "SELECT * FROM bid ORDER BY Amount DESC";
$res = mysql_query($query);
$count = mysql_numrows($res);
if($count >= MAX_BIDS) {
$row = mysql_fetch_assoc($res);
smsWinner($row["Phonenumber"], $row["Amount"]);
}
$askfast->say('/audio/thankyou.wav', $filename.'?function=hangup');
$askfast->finish();
}
function smsWinner($address, $amount) {
global $filename;
$publicKey = "timeout@ask-cs.com";
$privateKey = "1d5b31f0-dcea-11e2-a710-005056bc0d1b";
$askfast = new AskFast($publicKey, $privateKey);
$askfast->sms($address, $filename.'?function=winner&bid='.$amount);
}
function app_hangup() {
global $askfast;
$askfast->hangup();
$askfast->finish();
}
function app_winner() {
global $askfast;
global $filename;
$amount = $_GET["bid"];
$askfast->say("Congratulations! You have won with your bid of EUR ".$amount, $filename . '?function=hangup');
$askfast->finish();
}
function app_failure() {
$askfast->say('/audio/fout.wav');
$askfast->finish();
}
$function = 'start';
if (isset($_REQUEST['function']) && $_REQUEST['function'] != '') {
$function = $_REQUEST['function'];
}
switch ($function) {
case 'hangup': app_hangup(); break;
case 'start': app_start(); break;
case 'bid': app_bid(); break;
case 'receivebid': app_receivebid(); break;
case 'winner': app_winner(); break;
default: app_failure();
}
?>