/
inbound-inquiry.php
79 lines (64 loc) · 2.2 KB
/
inbound-inquiry.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
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
<?php
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
require_once("service/SimplePdoLeadConnectService.php");
require_once("entity/Account.php");
require_once("entity/Vendor.php");
require_once("entity/Prospect.php");
require_once("entity/Inquiry.php");
$service = new SimplePdoLeadConnectService();
if (isset($_REQUEST['To'])){
$sid = $_REQUEST['CallSid'];
$live = "true";
$phone = substr($_REQUEST['From'], -10);
$name = NULL;
$email = NULL;
$note = NULL;
$account = $service->loadAccountFromPhone(substr($_REQUEST['To'], -10));
}else{
$live = "false";
$number_sid = $_POST['number_sid'];
$phone = $_POST['phone'];
$name = $_POST['name'];
$email = $_POST['email'];
$note = $_POST['note'];
$account = $service->loadAccountFromNumberSid($number_sid);
}
$vendors = $service->loadAccountVendors($account->id);
if (!$service->loadProspectByPhone($phone, $account->id)){
$p = new Prospect();
$p->account_id = $account->id;
$p->name = $name;
$p->email = $email;
$p->phone = $phone;
$service->saveProspect($p);
}
$prospect = $service->loadProspectByPhone($phone, $account->id);
$inquiry_key = md5(microtime().rand());
$i = new Inquiry();
$i->inquiry_key = $inquiry_key;
$i->prospect_id = $prospect->id;
$i->status = "new";
$i->note = $note;
$service->saveInquiry($i);
require 'twilio-php-master/Services/Twilio.php';
$version = "2010-04-01";
$account_sid = 'AC3b2e8a3fabcbfe627c092046e3023ce4';
$token = '7a64549301ead0ae9fcfdc6f4d5cd5f4';
$phonenumber = $account->phone;
$name = urlencode($name);
foreach ($vendors as $vendor){
$client = new Services_Twilio($account_sid, $token, $version);
try {
$call = $client->account->calls->create($phonenumber,'+1'.$vendor->phone,'http://'.$_SERVER["HTTP_HOST"].'/vendor-connect.php?phone='.$phone.'&name='.$name.'&inquiry-key='.$inquiry_key.'&vendor-id='.$vendor->id.'&live='.$live.'&sid='.$sid);
} catch (Exception $e) {
echo 'Error: ' . $e->getMessage();
}
}
?>
<Response>
<Say>Please hold while we try to reach one of our associates.</Say>
<Dial>
<Conference><?php echo $sid?></Conference>
</Dial>
</Response>