forked from systers/FirstAide-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
twilioCall.php
90 lines (76 loc) · 2.49 KB
/
twilioCall.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
80
81
82
83
84
85
86
87
88
89
90
<!-- Created by Akanksha
Desc: Twilio Call API used to make voive call
-->
<!DOCTYPE html>
<html>
<head>
<title>FirstAide</title>
<link rel="stylesheet" type="text/css" href="css files/gethelpnow-style.css"/>
<link rel="stylesheet" href="css files/sweetalert.css"/>
<form method="POST"/>
</head>
<body>
<?php
if(!isset($_SESSION))
session_start();
if(!isset($_SESSION['email']))
{
header("location:login.php");
}
include('menu.php');
if(isset($_POST['getnum']))
$number = $_POST['getnum'];//get number from twilio-sms.js
else if(isset($_POST['number']))
$number = $_POST['number'];//get number from the form input 'number'
else
header("location:getHelpNow.php")
?>
<center>
<div class="window">
<div>
<h1 class="text">Make Call</h1>
<hr class="line">
<input id="input" name="number" value="<?php echo $number; ?>" readonly>
</div>
<div>
<input class="small-button" value="Call" type="submit" id="submit" name="submit">
</div>
</div>
</center>
<script src="javascripts/sweetalert.min.js"></script>
<script src="javascripts/sweetalert.js"></script>
<script src="javascripts/twilio-call.js"></script>
</body>
</html>
<?php
// Include the Twilio PHP library for making a call
if(isset($_POST['number']))
{
require_once ("Services/Twilio.php");
// Twilio REST API version
$version = "2010-04-01";
// Set Account SID and AuthToken - from twilio.com
$sid = '';
$token = '';
// A phone number you have previously validated with Twilio
$fromphonenumber = '';
$tophonenumber = $number;
$http = new Services_Twilio_TinyHttp('https://api.twilio.com', array('curlopts' => array(
CURLOPT_SSL_VERIFYPEER => false
)));
// Instantiate a new Twilio Rest Client
$client = new Services_Twilio($sid, $token, $version, $http);
try {
// Initiate a new outbound call
$call = $client->account->calls->create(
$fromphonenumber, // The number of the phone initiating the call
$tophonenumber, // The number of the phone receiving call
'http://demo.twilio.com/welcome/voice/' // The URL Twilio will request when the call is answered
);
echo "<script type='text/javascript'>salert('Success','Call started','success');</script>";
}
catch (\Services_Twilio_RestException $e) {
$error = $e->getMessage();
echo "<script type='text/javascript'>salert('Error','$error','error');</script>";
}
}