forked from aaronpk/Google-Voice-PHP-API
-
Notifications
You must be signed in to change notification settings - Fork 4
/
example.php
48 lines (38 loc) · 1.42 KB
/
example.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
<?php
include('GoogleVoice.php');
$gv = new GoogleVoice('your.name', 'password');
// call a phone from one of your forwarding phones
$gv->callNumber('9995551212', '5558675309', 'mobile');
// send an SMS to a phone number
$gv->sendSMS('9995551212', 'Sending a message!');
// fetch new voicemails
$voicemails = $gv->getNewVoicemail();
$msgIDs = array();
foreach( $voicemails as $s )
{
preg_match('/\+1([0-9]{3})([0-9]{3})([0-9]{4})/', $s['phoneNumber'], $match);
$phoneNumber = '(' . $match[1] . ') ' . $match[2] . '-'. $match[3];
echo 'Message from: ' . $phoneNumber . ' on ' . $s['date'] . "\n" . $s['message'] . "\n\n";
if( !in_array($s['msgID'], $msgIDs) )
{
// mark the conversation as "read" in google voice
$gv->markSMSRead($s['msgID']);
$msgIDs[] = $s['msgID'];
}
}
// get all new SMSs
$sms = $gv->getNewSMS();
$msgIDs = array();
foreach( $sms as $s )
{
preg_match('/\+1([0-9]{3})([0-9]{3})([0-9]{4})/', $s['phoneNumber'], $match);
$phoneNumber = '(' . $match[1] . ') ' . $match[2] . '-'. $match[3];
echo 'Message from: ' . $phoneNumber . ' on ' . $s['date'] . ': ' . $s['message'] . "\n";
if( !in_array($s['msgID'], $msgIDs) )
{
// mark the conversation as "read" in google voice
$gv->markSMSRead($s['msgID']);
$msgIDs[] = $s['msgID'];
}
}
?>