twitter feed0xdecafbad.com

Google Voice Command Line Script

by on Jul.28, 2009, under Telephony

UPDATE: Aug-20-2009 I added the ability to use a ~/.netrc file (if Net::Netrc is installed, if its not it will not use that :)  I also fixed the meta following problem.  Fixed a couple other bugs – like the username/pass incorrect not reporting that error properly.  You should upgrade to the new version now.

UPDATE: Sept-10-2009 I added the ability to send calls/sms messages to named contacts.  It will use your google voice contact data, so if you want to use this feature you have to create a contact in google voice and use the nickname that you gave them.  I changed the way arguments are passed, run the program for usage information.  If you were already using this you will have to adjust how you call the program.

I wrote a perl script that lets you interface with your Google Voice account.  You can place a call, cancel a call, and send a SMS message easily.  This is ideal for people that want to send SMS messages for system alerts, or for other reasons.

In order to use this script you must first download it.  Then edit the username, password and default number variables near the top of the script.  Install any missing perl modules based on whatever distribution you have, if you run the script it will tell you what it is missing.  Invalid args or no args will give you a help screen.

To send an SMS message to 12345678

./googlevoice.pl sms 12345678 this is a test sms message

To place a call to 12345678 (optionally set the ‘forwarding number’)

./googlevoice.pl call 12345678

./googlevoice.pl call 12345678 90123456

To cancel a call placed through the web (or this script)

./googlevoice.pl cancel

In the future I may access the HTTP based inbox so  that you can periodically check for messages, and react to triggers on them.  In order to do this you would access the following URLs.  If anyone is bored I will gladly accept patches to my script to add this functionality.

Inbox XML:
https://www.google.com/voice/inbox/recent/inbox/

Starred Calls XML:
https://www.google.com/voice/inbox/recent/starred/

All Calls XML:
https://www.google.com/voice/inbox/recent/all/

Spam XML:
https://www.google.com/voice/inbox/recent/spam/

Trash XML:
https://www.google.com/voice/inbox/recent/trash/

Voicemail XML:
https://www.google.com/voice/inbox/recent/voicemail/

SMS XML:
https://www.google.com/voice/inbox/recent/sms/

Recorded Calls XML:
https://www.google.com/voice/inbox/recent/recorded/

Placed Calls XML:
https://www.google.com/voice/inbox/recent/placed/

Received Calls XML:
https://www.google.com/voice/inbox/recent/received/

Missed Calls XML:
https://www.google.com/voice/inbox/recent/missed/


60 Comments for this entry

  • Steve

    Hi Bret (or anyone who can help) –
    I run a Little League and need a utility that will let me send Googel SMS messages to our membership. WOuld it be possible for someone to compile this into a simple .exe with parameters? I don’t know anything about Perl.

    It would work something like this:
    GV.exe SMS 2135551212 /U user@gmail.com /P P4$$w0rd “Games cancelled due to rain tomorrow”

    I would then be able to view the status of each message in the normal Google Voice page.

    please contact me at sdix00 (at) gmail dot com to discuss.

    Thanks!!!
    Steve

  • N3o

    Hi Trixter, great work and congratulations for made this script =)….

    I got the same 500 error, but I solved it adding phoneType=2 on this line 241 from :

    $postdata = “outgoingNumber=$dst_number&forwardingNumber=$from_number&subscriberNumber=undefined&remember=0&_rnr_se=$rnr_se”;

    to this:

    $postdata = “outgoingNumber=$dst_number&forwardingNumber=$from_number&subscriberNumber=undefined&remember=0&_rnr_se=$rnr_se&phoneType=2″;

    As mentioned in past post,

    Success!..

  • Magic

    I tried the code. It sends SMS perfectly.

    I got the dreaded 500 error and so I made the change to add the call type, and cleared the error. It tells me that the call has been sent but the call never seems to connect

  • trixter

    Since writing this I noticed that there is a small issue, well I noticed two issues.

    1. I do not detect the captcha when it happens. They occasionally do that, particularly if an IP has been flagged for some reason (noticed it when I tried it from the server)

    2. You may only send calls from a registered phone now, no more can you use any arbitrary telephone number. It appears to send the call but it wont if you use any other number. It will also only let 1 call for each source/destination number per account. If you have 2 accounts and they both have the same registered phone number you can place two calls, one from each account, using the same source/destination numbers, but no more than 1 per account. Again, it will appear that it worked but it doesnt.

    I also realized that google would be able to lower their web transaction costs if they would provide something like XML-RPC or something to interface with the account. It would also make my life easier :)

  • jay

    Hi. I am hugely interested in getting this to work. I have installed Active State Perl, Windows 7 Pro, all modules etc.

    I was originally getting errors but easily saw that I needed to install the WWW Mech. & plugin.

    No, I run the script but I just keep getting the help screen every time.

    I have substituted the variables in the script as:
    my $username = “jvitz\@gmail.com”;
    my $password = “myrealpasswordhere”;
    my $default_number = “8435551212″;

    When i try to run the script from the command promtp I am doing it as:

    googlevoice.pl sms 8435551212 mytestmessage

    when in hit ENTER, i get the following:

    C:\RmDemo17\googlevoice.pl -c [-p phone] [-t type] [-f from] [args]
    Commands:
    sms -p
    call -p
    cancel
    -t is only used if you specify a contact name for -p and not a number

    So, I also tried it using the syntax shown as:
    googlevoice.pl -c SMS -p 8435551212 mymessagetest

    and I get the same help screen…

    Any assistance would be greatly appreciated
    jay

  • VoIP Mike

    There are two additions I’d like to see, if you could include them:

    First, the ability to specify the username and password (in addition to the number you want to call, and the number and type of phone you want to be called back on) in the command line. The reason for this is in case you are using multiple Google Voice accounts. If this were possible it might be possible to use your script rather than pygooglevoice on Asterisk systems (similar to what’s described at http://michigantelephone.wordpress.com/2010/05/21/how-to-use-google-voice-for-free-outgoing-calls-on-an-asteriskfreepbx-system-the-easy-way/ ). There’s a lot of us that know a little Perl (though not as well as you do, at least not in my case) but no Python at all.

    The other thing I’d like to see is a way to download and then delete all voicemails to a specified directory. pygooglevoice can list them but when you actually try to download you get an error message, and since I don’t know python I don’t know how to fix the problem (and the creators of that script apparently don’t respond to e-mails anymore). My ultimate goal would be to download the voicemails (and associated envelope information), then translate them into Asterisk voicemails which could be placed into an Asterisk voicemail box, so that Asterisk users would only need to check their Asterisk voicemail to receive all their messages.

  • trixter

    I will look into doing that. I personally use FreeSWITCH.org and not Asterisk due to performance and stability issues. I have not worked on this in a while, and have not even done the things I wanted to do. Too many other things going on.

  • Mike Gerwitz

    I noticed the following comment in your license:

    “The GPL restricts freedom.”

    This seems like a contradictory statement and brings into question your definition of “freedom”. Had you used the GPL in order to license this work, you ensure that the source code will be freely available indefinitely. You would have in fact been protecting the freedom of your users.

    You impose only restrictions on your license. You impose no restrictions whatsoever on the source code itself. This means that someone would be able take your script and use it in their own proprietary project, obfuscating or otherwise compiling the code, and still follow the license terms so long as they distribute your license and do not modify it. In doing so, the freedoms of your users have just been assaulted. Should they receive a copy of this modified software, they are not free to study and alter the source code – it is in a state that makes doing so very difficult.

    By your statement, I assume you are referring to the “viral” nature of the GNU General Public license – that it forces any derivative works to also be free, released under a compatible license. Some people see this as an assault on their freedom to distribute and use the software however they please. But the GNU GPL protects the USER, not the developer – ensuring that users are not bullied and taken advantage of. With your license, are protecting the developer (permitting them to do whatever they wish with your code), but dooming the users of your software.

    It should also be noted that your software is stand-alone. It is not a library. Had it been released under the terms of the GPL, you would have protected the four essential freedoms. You also would have permitted developers to use your software in proprietary software, because they could simply call your script and use its output in their proprietary software.

    Therefore, you have gained nothing here by disallowing the GPL, but instead have forfeited the four essential freedoms.

  • trixter

    You are right, I do give people the freedom to take the script and use it in other programs. That is a freedom I freely give to them to use it. My code will remain free for all to use indefinitely, my users will be able to do that for as long as they choose. This is actual freedom, restrictions are not freedom, that is Orwellian doublespeak.

    I think what you meant to say was that you somehow feel that anyone who modifies this script should be forced to share with you any work they produce, that that person should not have the freedom to decide how their additions should be licensed, used and otherwise distributed. That is their work, you are not entitled to it, and it is not freedom to force their work to be distributed in some arbitrary way that I selected.

    What I have done, by disallowing the GPL is ensure freedom. Specifically, you have the freedom to use this script or to reject it. You have the freedom to add to this script or not. You have the freedom to take parts of this and use them as you see fit (something your “stand alone program” argument fails to acknowledge). You have the freedom to release it under whatever terms you want, so long as they do not take away freedoms from others. Licensing it under the GPL would remove some of these essential freedoms, and that is a choice I specifically opted to not limit others on.

    You can drink the kool-aid all you want, and advocate that placing restrictions on software somehow means freedom, but the reality is that by having something more free only removes the mentality of entitlement to other peoples work without choice. Keep in mind that I did leave open the door for others to share their work, if that is what they opted to do, but under this license you have no right to it, after all its theirs.

  • Norman Walsh

    FWIW, this script seems to have stopped working:

    Link not found at googlevoice.pl line 163

4 Trackbacks / Pingbacks for this entry

Leave a Reply

ERROR: si-captcha.php plugin says GD image support not detected in PHP!

Contact your web host and ask them why GD image support is not enabled for PHP.

ERROR: si-captcha.php plugin says imagepng function not detected in PHP!

Contact your web host and ask them why imagepng function is not enabled for PHP.

ERROR: si-captcha.php plugin says GD image support not detected in PHP!

Contact your web host and ask them why GD image support is not enabled for PHP.

ERROR: si-captcha.php plugin says imagepng function not detected in PHP!

Contact your web host and ask them why imagepng function is not enabled for PHP.

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!