-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvoicemail.php
79 lines (62 loc) · 2.36 KB
/
voicemail.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
$recordingStatus = $_REQUEST['RecordingStatus'] ?? '';
$RecordingUrl = $_REQUEST['RecordingUrl'] ?? '';
$CallSid = $_REQUEST['CallSid'] ?? '';
if ($recordingStatus == 'completed') {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.twilio.com/2010-04-01/Accounts/xxxxxx/Calls/' . $CallSid . '.json',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'Authorization: Basic xxxxx'
),
));
$response = curl_exec($curl);
curl_close($curl);
$callDeatils = json_decode($response, true);
$to = $callDeatils['to'];
$from = $callDeatils['from'];
if ($to == '+1440300000') {
$toEmail = 'agent1@example.com';
} elseif ($to == '+14409992440') {
$toEmail = 'agent2@example.com';
} elseif ($to == '+14409992499') {
$toEmail = 'agent3@example.com';
} else {
$toEmail = 'agent1@example.com';
}
$msg = 'You recieved a new voicemail. Listen it here: ' . $RecordingUrl;
//send email
$headers = 'From: <info@example.com>' . "\r\n";
$sendMail = mail($toEmail, $from . " New Voicemail to " . $to, $msg, $headers);
//send sms
$msg = "Hi. We detected a voicemail. For the fastest service, please reply to this text message.";
sendSms($from, $to, $msg); //to and from will switch here as person who called need to recieve sms
}
function sendSms($to, $from, $msg)
{
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.twilio.com/2010-04-01/Accounts/xxxxx/Messages.json',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => 'To=' . $to . '&From=' . $from . '&Body=' . $msg . '',
CURLOPT_HTTPHEADER => array(
'Authorization: Basic xxxxx',
'Content-Type: application/x-www-form-urlencoded'
),
));
$response = curl_exec($curl);
curl_close($curl);
}