Jump to content

Send Google Voice SMS using IE.au3 (UDF)


GoogleDude
 Share

Recommended Posts

I needed a simple UDF that would allow me to send a SMS to a mobile phone using my Google Voice Account in one of my scripts. Since I could not find one I made one and wanted to share it with everyone.

I know it is a down right dirty way of creating a UDF but feel free to make it better. I am working on making a UDF that uses winhttp.dll instead of IE.au3 but that will require me to learn more first.

This is the first UDF I am making public. mainly because my UDF making skills SUCK to be honest. but the below should work for the most part with out error. however there is no error checking really.

Things to note.

1.) A valid Google Voice Account is required in order to use this UDF. (http://www.google.com/voice) for more info on Google Voice.

2.) If a valid Google Voice Account is already logged into IE it will use that account to send the SMS otherwise it will use the specified GV account in the UDF params.

3.) No return codes/values have been put into this UDF (YET) feel free to add them yourself.

4.) I included a line that checks if the already logged in GV account was uses during the SMS send but it can be removed by changing a few lines.

~GoogleDude

The UDF to include

#include-once
#include 

; #FUNCTION# ;===============================================================================
; Name...........: _SendGVSMS
; Description ...: Sends a SMS Message using a valid Google Voice Account using IE.AU3
; Syntax.........: _SendGVSMS ($FromGVAccount,$FromGVPassword,$To_SMS_NUM, $To_SMS_TXT )
; Parameters ....: $FromGVAccount - Google Voice Account E-Mail to send SMS From
;                  $FromGVPassword - Google Voice Account Password to send SMS From
;                  $To_SMS_NUM - SMS Phone number to send SMS Message to
;                   $To_SMS_TXT - SMS Text Message to send to $To_SMS_NUM
;                  $GV_AllredyLoggedInTXT - Checks if logged in or not. This is passed regardless
;                    Needs to be worked on.
; Return values .: TBD / Not yet implemented
;
;
; Author ........: GoogleDude
; Modified.......:
; Remarks .......: Requires a Valid Google Voice Account.
; Related .......:
; Requires.......; IE.AU3 and a valid Google Voice Account
; Link ..........:
; Example .......: _SendGVSMS("mygvaccount@gmail.com","mygvpassword","4085551234", "You are such a pimp nugget!")
;============================================================================================

; Specify the TXT to be included in SMS message if SMS is sent with current logged in GV user rather than the one specified in function.
$GV_AllredyLoggedInTXT = @CRLF & @CRLF & "Already Signed In"

Func _SendGVSMS($FromGVAccount,$FromGVPassword,$To_SMS_NUM, $To_SMS_TXT )
    $GV_SMS_URL = _IECreate("https://www.google.com/voice/b/0/m/sms",0,0,1,1)
    $GV_Form = _IEFormGetObjByName($GV_SMS_URL, "gaia_loginform")
    $o_username = _IEFormElementGetObjByName($GV_Form, "Email")
    _IEFormElementSetValue($o_username, $FromGVAccount)
    $o_password = _IEFormElementGetObjByName($GV_Form, "Passwd")
    _IEFormElementSetValue($o_password, $FromGVPassword)
    _IEFormSubmit($GV_Form,1)
    If @error Then
         ; You will get a Warning from function _IEFormGetObjByName,  $_IEStatus_NoMatch and 5 others when this var is set. this is normal
        $SendSMSform = _IEFormGetCollection ($GV_SMS_URL, 0)
        $oQuery = _IEFormElementGetCollection ($SendSMSform, 2)
        $o_sms_num = _IEFormElementGetObjByName($SendSMSform, "number")
        _IEFormElementSetValue($o_sms_num, $To_SMS_NUM)
        $o_sms_txt = _IEFormElementGetObjByName($SendSMSform, "smstext")
        _IEFormElementSetValue($o_sms_txt, $To_SMS_TXT & $GV_AllredyLoggedInTXT)
        $GV_SEND_SMS = _IEFormSubmit($SendSMSform,1)
        _IEQuit($GV_SMS_URL)
    Else
        $SendSMSform = _IEFormGetCollection ($GV_SMS_URL, 0)
        $oQuery = _IEFormElementGetCollection ($SendSMSform, 2)
        $o_sms_num = _IEFormElementGetObjByName($SendSMSform, "number")
        _IEFormElementSetValue($o_sms_num, $To_SMS_NUM)
        $o_sms_txt = _IEFormElementGetObjByName($SendSMSform, "smstext")
        _IEFormElementSetValue($o_sms_txt, $To_SMS_TXT)
        $GV_SEND_SMS = _IEFormSubmit($SendSMSform,1)
        _IEQuit($GV_SMS_URL)
    EndIf
EndFunc

example

#include <_SendGVSMS_UDF.au3>

_SendGVSMS("mygvaccount@gmail.com","mygvpassword","4085551234", "this is pretty cool")
Edited by GoogleDude
Link to comment
Share on other sites

  • 3 weeks later...
  • 1 year later...

First off, I just wanted to say that I'm not resurrecting this topic to spam.

I wanted to say thanks for this UDF, it did exactly what I needed.

I also wanted to post a new portion of the UDF that I wrote. I needed a service to be run on a computer that could receive the texts into an AutoIt program running while I was away from the computer. So, I wrote the following two functions:

; #FUNCTION# ;===============================================================================
; Name...........: _GetGVSMS
; Description ...: Polls the Google Voice service for new texts
; Syntax.........: _GetGVSMS ( $FromGVAccount, $FromGVPassword [, $iCheckTime = 5000 ] )
; Parameters ....: $FromGVAccount   - Google Voice Account E-Mail to poll
;                  $FromGVPassword  - Google Voice Account Password to for the above account
;                  $iCheckTime      - The interval to poll the Google Voice account (in milliseconds)
; Return values .: Success          - Returns an array containing the phone number and text message
; Author ........: Fett8802, original IE code by GoogleDude
; Remarks .......: Requires a Valid Google Voice Account.
; Requires.......; IE.AU3 and a valid Google Voice Account
;============================================================================================
Func _GetGVSMS($FromGVAccount,$FromGVPassword, $iCheckTime = 5000)
    $GV_SMS_URL = _IECreate("https://www.google.com/voice/b/0/m/sms",0,0,1,1)
    $GV_Form = _IEFormGetObjByName($GV_SMS_URL, "gaia_loginform")
    $o_username = _IEFormElementGetObjByName($GV_Form, "Email")
    _IEFormElementSetValue($o_username, $FromGVAccount)
    $o_password = _IEFormElementGetObjByName($GV_Form, "Passwd")
    _IEFormElementSetValue($o_password, $FromGVPassword)
    _IEFormSubmit($GV_Form,1)
    Do
        _IENavigate($GV_SMS_URL,"https://www.google.com/voice/m",1)
        $objNewMsg = _IEPropertyGet($GV_SMS_URL,"outerhtml")
        $aText = _GetText($objNewMsg)
        Sleep($iCheckTime)
    Until IsArray($aText) = 1
    $iRefreshLink = StringRegExp($objNewMsg,"<A href=""/voice/m/archive(.*)"">archive",1)
    $iRefreshLink[0] = StringRegExpReplace($iRefreshLink[0],"&amp;","&")
    $sLink = "https://www.google.com/voice/m/archive" & $iRefreshLink[0]
    _IENavigate($GV_SMS_URL,$sLink,1)
    _IEQuit($GV_SMS_URL)
    Return $aText
EndFunc

Func _GetText($iText)
    $iMatches = StringRegExp($iText,"<DIV><SPAN class=sf>(.*)</SPAN>h</DIV>",3)
    If IsArray($iMatches) = 0 Then Return -1
    $iNumber = StringRegExp($iMatches[UBound($iMatches)-1],"<B>+(.*):h</B>",1)
    If IsArray($iNumber) = 0 Then Return -2
    $iText = StringRegExp($iMatches[UBound($iMatches)-1],"<SPAN>(.*)</SPAN>",1)
    If IsArray($iText) = 0 Then Return -3
    Dim $iReturn[2] = [$iNumber[0],$iText[0]]
    Return $iReturn
EndFunc

The second function is used internally in the first. What this does is it opens an IE window in the background and polls the google voice mobile page every 5 seconds be default. This can be extended or shortened via the $iChecktime variable. When it sees a new text, it retrieves the text and the number it came from in an array and passes it.

I use this in a service I wrote so that I can send various text commands to my computer to perform certain tasks while I'm away. Thought it would be useful.

Thanks again!

- Fett</a>

Edited by fett8802
[sub]My UDF[/sub][sub] - Basics and Time extensions. Great for those new at AutoIt, also contains some powerful time extensions for pros.[/sub][sub]ScrabbleIt[/sub][sub] - Scrabble done in pure AutoIt. (In Progress)[/sub][sub]Nerd Party Extreme | My Portfolio | [email="fett8802@gmail.com"]Contact Me[/email][/sub]
Link to comment
Share on other sites

  • 5 months later...
  • 1 year later...

DisabledMonkey,, SMS UDF is a great function! Thanks for your work on it!

The function is written to send the SMS message using the "Subject" field. Unfortunately on some smartphones, part of that field is consumed by the word "Subject:" A better solution is to send the SMS message using the TextBody Field.

I've made only a few changes to the SMS UDF script to send the SMS using $s_TextBody instead of $s_Subject. 

I sent the modifications to DisabledMonkey - hopefully he'll included them and republish the script.

--Chuck Eglinton

Link to comment
Share on other sites

  • 3 weeks later...

First off, I just wanted to say that I'm not resurrecting this topic to spam.

I wanted to say thanks for this UDF, it did exactly what I needed.

I also wanted to post a new portion of the UDF that I wrote. I needed a service to be run on a computer that could receive the texts into an AutoIt program running while I was away from the computer. So, I wrote the following two functions:

 

; #FUNCTION# ;===============================================================================
; Name...........: _GetGVSMS
; Description ...: Polls the Google Voice service for new texts
; Syntax.........: _GetGVSMS ( $FromGVAccount, $FromGVPassword [, $iCheckTime = 5000 ] )
; Parameters ....: $FromGVAccount   - Google Voice Account E-Mail to poll
;                  $FromGVPassword  - Google Voice Account Password to for the above account
;                  $iCheckTime      - The interval to poll the Google Voice account (in milliseconds)
; Return values .: Success          - Returns an array containing the phone number and text message
; Author ........: Fett8802, original IE code by GoogleDude
; Remarks .......: Requires a Valid Google Voice Account.
; Requires.......; IE.AU3 and a valid Google Voice Account
;============================================================================================
Func _GetGVSMS($FromGVAccount,$FromGVPassword, $iCheckTime = 5000)
    $GV_SMS_URL = _IECreate("https://www.google.com/voice/b/0/m/sms",0,0,1,1)
    $GV_Form = _IEFormGetObjByName($GV_SMS_URL, "gaia_loginform")
    $o_username = _IEFormElementGetObjByName($GV_Form, "Email")
    _IEFormElementSetValue($o_username, $FromGVAccount)
    $o_password = _IEFormElementGetObjByName($GV_Form, "Passwd")
    _IEFormElementSetValue($o_password, $FromGVPassword)
    _IEFormSubmit($GV_Form,1)
    Do
        _IENavigate($GV_SMS_URL,"https://www.google.com/voice/m",1)
        $objNewMsg = _IEPropertyGet($GV_SMS_URL,"outerhtml")
        $aText = _GetText($objNewMsg)
        Sleep($iCheckTime)
    Until IsArray($aText) = 1
    $iRefreshLink = StringRegExp($objNewMsg,"<A href=""/voice/m/archive(.*)"">archive",1)
    $iRefreshLink[0] = StringRegExpReplace($iRefreshLink[0],"&amp;","&")
    $sLink = "https://www.google.com/voice/m/archive" & $iRefreshLink[0]
    _IENavigate($GV_SMS_URL,$sLink,1)
    _IEQuit($GV_SMS_URL)
    Return $aText
EndFunc

Func _GetText($iText)
    $iMatches = StringRegExp($iText,"<DIV><SPAN class=sf>(.*)</SPAN>h</DIV>",3)
    If IsArray($iMatches) = 0 Then Return -1
    $iNumber = StringRegExp($iMatches[UBound($iMatches)-1],"<B>+(.*):h</B>",1)
    If IsArray($iNumber) = 0 Then Return -2
    $iText = StringRegExp($iMatches[UBound($iMatches)-1],"<SPAN>(.*)</SPAN>",1)
    If IsArray($iText) = 0 Then Return -3
    Dim $iReturn[2] = [$iNumber[0],$iText[0]]
    Return $iReturn
EndFunc

The second function is used internally in the first. What this does is it opens an IE window in the background and polls the google voice mobile page every 5 seconds be default. This can be extended or shortened via the $iChecktime variable. When it sees a new text, it retrieves the text and the number it came from in an array and passes it.

I use this in a service I wrote so that I can send various text commands to my computer to perform certain tasks while I'm away. Thought it would be useful.

Thanks again!

- Fett</a>

 

Hey could you please post all of the code you used. I'm new to AutoIT and have been experimenting with it the past few days... I have a small project I've been working of for a while and would really like to be able to send and receive texts through Google Voice while I'm away from my computer also. After finding out all of the different capabilities of AutoIT it seems like it would be a great solution for what I'm wanting to do, but I can't seem to get this working with Google Voice. I tried using all the code provided and had some errors. I made some changes and the errors went away but now the script doesn't appear to do anything. I would really appreciate any help whatsoever and thank you guys in advance! This seems like a great community.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...