OBiTALK Community

General Support => Feature Requests => Topic started by: giqcass on November 07, 2013, 01:12:22 AM

Title: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: giqcass on November 07, 2013, 01:12:22 AM
It's probably a longshot Getting Obi to support this but I have a partial work around that functions now and will continue to function after the XMPP cut off.  This trick requires the Obi device to call a url.  It would not require users to share their passwords either.  This ability to "call" a predefined url could also be used with other peoples Hacks to generate a callback as well.

I'm not talking about dialing an ip address with sip.  Instead the Obi opens a url similar to the way a browser would.  It would work in a fashion similar to my dynamic DNS hack (http://jr9.org/oYp).  In my testing it all works so far but I need to fine tune the code.  I would also need OBi to allow us to opem a url by dialing a number.  I envision a speed dial.


The very basics of how this works.

Set up a Google Call widget.  Under the options set the widget so the call goes directly to voicemail.  Plug the secret key into a small form that will post automatically when it's called.  

When the form is called you will receive a call that connects you to your own voicemail.
Now you can listen to your voicemail and dial outgoing calls for free.

I would also like to find a way to host the form on the actual Obi.  I think I might be able to do that with the OBi202.  I am testing code hosted on a USB drive on my Obi202 right now.

Using this trick you could also set up speed dials for other Google Voice users that would connect without going through your voicemail to place the call.

This would also help support services that provide callback.  It's a little complicated now but I'm simplifying it as we speak.  


Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: giqcass on November 07, 2013, 05:02:16 AM
I have made the fist OBi initiated call.  I have not yet been able to host the code on the Obi and make it work but when I host a PHP version of the code on a free webserver it works.

After I uploaded the code to the webserver I was able to paste that code into my obi just like I did for the Dynamic DNS hack.  I set the interval to 120 seconds for the sake of testing and the Obi initiated a Google Voice callback to my phone on schedule.  This connected me to my voicemail and I was able to place an outgoing call as expected.

If Obi would add the ability to post to a url by dialing a code this will workå
Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: sdb- on November 07, 2013, 06:39:11 AM
Clever!

I have not looked at using the google widget.
Is your PHP code downloadable or short enough to post?  (after obscuring your info)
Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: giqcass on November 07, 2013, 08:54:25 PM
It's not really my code.  I just re-purposed the code someone else wrote for a tutorial.   Only 2 variables must be set. I'm playing with an alternate technique as well.  It's going to be more difficult but it will work better when finished.  It will also use an http request but it allows you to dial any number without going through voicemail first.

Primary code came from here.
http://www.html-form-guide.com/php-form/php-form-submit.html

This article helped me with the variables.
http://razvangavril.com/web-development/custom-google-voice-widget/

I still don't have a version that will work when hosted on the Obi via usb drive.  The Obi can activate the code when hosted on a free web host by using a http request.  I have tested this code hosted on 000webhost.com.

<?php
 
//Replace the following two Variables.
$GoogleVoiceKey 'a3d34f94jf94jfj98f1da53jfiejgkej12710aa2'//This comes from the GV widget
$CallBackNumber =  '15555551212'//This is the number Google should call.

//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
//Leave this stuff alone don't make any changes below 
//unless you know what you are doing.
//This script will allow you to place a call
//from Google voice to another number.
//it uses the secret key from the Google call widget.
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////




//create array of data to be posted
$post_data['buttonId'] = $GoogleVoiceKey;
$post_data['callerNumber'] = $CallBackNumber;
$post_data['name'] = 'Me';
$post_data['showCallerNumber'] = '1';



 
//traverse array and prepare data for posting (key1=value1)
foreach ( $post_data as $key => $value) {
    
$post_items[] = $key '=' $value;
}
 
//create the final string to be posted using implode()
$post_string implode ('&'$post_items);
 
//create cURL connection
$curl_connection =
  
curl_init('https://clients4.google.com/voice/embed/webButtonConnect');
 
//set options
curl_setopt($curl_connectionCURLOPT_FRESH_CONNECT1);
curl_setopt($curl_connectionCURLOPT_CONNECTTIMEOUT30);
curl_setopt($curl_connectionCURLOPT_USERAGENT,
  
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connectionCURLOPT_RETURNTRANSFERtrue);
curl_setopt($curl_connectionCURLOPT_SSL_VERIFYPEERfalse);
//curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, true);
 
//set data to be posted
curl_setopt($curl_connectionCURLOPT_POSTFIELDS$post_string);
 
//perform our request
$result curl_exec($curl_connection);
 
//show information regarding the request
print_r(curl_getinfo($curl_connection));
echo 
curl_errno($curl_connection) . '-' .
                
curl_error($curl_connection);
 
//close the connection
curl_close($curl_connection);
 
?>


Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: giqcass on November 08, 2013, 08:30:03 AM
I'm done playing with solution number 1.  If anyone would like to test is then go ahead and try this live test version.  You need to supply your own secret key from a Google Voice widget.
I can think of a few creative ways to use this but the more complex version will be more versatile.

Replace "YOUR-SECRET-KEY" with the one from the widget and the number with your telephone number or the number of someone you want to call.  I would give them a heads up first before you call them.  It will call them and ask them to press 1 to connect with you.  Caller ID will show
QuoteMountain Vie CA  16502651193
http://gvtest.site88.net/?key=YOUR-SECRET-KEY&callback=15554441212&name=optional

This article (http://razvangavril.com/web-development/custom-google-voice-widget/) will help you find the key.  The key looks something like this. 4563a8e24f4009bcaf7122437e2f9bc0b15c192e

New code below.
<?php

echo 'This is a GV callback test page.<BR>';
echo 
'You must provide your secret key and callback number.<BR>';
echo 
'Add it to the url like this.<BR>';
echo 
'?key=YOUR-RANDOM-SECRET-KEY-FROM-WIDGET&callback=15552221212&name=OPTIONAL<BR><BR><BR>';
//
//////////////////////////////////////////////////////////
//There are 2 way to pass the variables. 
//
//Option 1 - In the URL
// http://www.yourdomain.com/ObigvTest.php?key=YOUR-RANDOM-SECRET-KEY-FROM-WIDGET&callback=15552221212&name=OPTIONAL
//
//Option 2 - Replace the following two Variables.
$GoogleVoiceKey 'YOUR RANDOM SECRET KEY FROM WIDGET';
$CallBackNumber =  '15552221212'//This is the number Google should call.

//This variable is optional
$Name 'Google Voice';

//////////////////////////////////////////////////////////
//Leave this stuff alone don't make any changes below 
//unless you know what you are doing.
//Any variable included in the url will replace variables 
//defined in option 2.
//This script will allow you to place a call
//from Google voice to another number.
//it uses the secret key from the Google call widget.
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////

///If variables are in the url then override pre defined variables
 
$Key htmlspecialchars($_GET["key"]) ;
 
$CallBack htmlspecialchars($_GET["callback"]) ;
 
$Name htmlspecialchars($_GET["name"]) ;

if (
$Key != null)
  
$GoogleVoiceKey $Key;

if (
$CallBack != null)
  
$CallBackNumber $CallBack;

if (
$Name != null)
  
$GvName $Name;

echo 
$GoogleVoiceKey ' ' $CallBackNumber ' ' $Key ' ' $CallBack  ;


//create array of data to be posted
$post_data['buttonId'] = $GoogleVoiceKey;
$post_data['callerNumber'] = $CallBackNumber;
$post_data['name'] = '$GvName';
$post_data['showCallerNumber'] = '1';



 
//traverse array and prepare data for posting (key1=value1)
foreach ( $post_data as $key => $value) {
    
$post_items[] = $key '=' $value;
}
 
//create the final string to be posted using implode()
$post_string implode ('&'$post_items);
 
//create cURL connection

if ($Key != null) {
  
$GoogleVoiceKey $Key;

  
$curl_connection =
    
curl_init('https://clients4.google.com/voice/embed/webButtonConnect');
 
}
//set options
curl_setopt($curl_connectionCURLOPT_FRESH_CONNECT1);
curl_setopt($curl_connectionCURLOPT_CONNECTTIMEOUT30);
curl_setopt($curl_connectionCURLOPT_USERAGENT,
  
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connectionCURLOPT_RETURNTRANSFERtrue);
curl_setopt($curl_connectionCURLOPT_SSL_VERIFYPEERfalse);
//curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, true);
 
//set data to be posted
curl_setopt($curl_connectionCURLOPT_POSTFIELDS$post_string);
 
//perform our request
$result curl_exec($curl_connection);
 
//show information regarding the request
print_r(curl_getinfo($curl_connection));
echo 
curl_errno($curl_connection) . '-' .
                
curl_error($curl_connection);
 
//close the connection
curl_close($curl_connection);
 
?>
Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: giqcass on November 28, 2013, 02:19:21 AM
I'm working on the callback script based on work found here (https://github.com/aaronpk/Google-Voice-PHP-API).  It's a better solution then the one above.  If I can get Obi to give us the ability to post a url Based on a speed dial then it should work as follows. 

1) Dial the speed dial.
2) Hang up.
3) You immediately receive an incoming call.
4) Pick up the phone and the call will ring the number defined in the speed dial.

Not as seamless as the current system but it's free and it will work after the 2014 cutoff date.
Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: azrobert on December 18, 2013, 01:19:30 PM
Quote from: giqcass on November 28, 2013, 02:19:21 AM
I'm working on the callback script based on work found here (https://github.com/aaronpk/Google-Voice-PHP-API).  It's a better solution then the one above.  If I can get Obi to give us the ability to post a url Based on a speed dial then it should work as follows. 

1) Dial the speed dial.
2) Hang up.
3) You immediately receive an incoming call.
4) Pick up the phone and the call will ring the number defined in the speed dial.

Not as seamless as the current system but it's free and it will work after the 2014 cutoff date.

I was testing this script with Tropo. I deleted my last post because Tropo doesn't support cookies and the script will not work. Since then I tried running the script without cookies. I actually got it to log into GV successfully, but instead of returning a key Google sent a message stating cookies must be enabled.

Are you testing this script? Are you having better results than me?

Can you recommend any free service that can host this script?

Thanks
Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: giqcass on December 19, 2013, 09:48:06 PM
Quote from: azrobert on December 18, 2013, 01:19:30 PM
Quote from: giqcass on November 28, 2013, 02:19:21 AM
I'm working on the callback script based on work found here (https://github.com/aaronpk/Google-Voice-PHP-API).  It's a better solution then the one above.  If I can get Obi to give us the ability to post a url Based on a speed dial then it should work as follows. 

1) Dial the speed dial.
2) Hang up.
3) You immediately receive an incoming call.
4) Pick up the phone and the call will ring the number defined in the speed dial.

Not as seamless as the current system but it's free and it will work after the 2014 cutoff date.

I was testing this script with Tropo. I deleted my last post because Tropo doesn't support cookies and the script will not work. Since then I tried running the script without cookies. I actually got it to log into GV successfully, but instead of returning a key Google sent a message stating cookies must be enabled.

Are you testing this script? Are you having better results than me?

Can you recommend any free service that can host this script?

Thanks


I'm having issues with it as well.  I always end up with errors.  It needs a rewrite to work with the free hosts.  I haven't dug in to it enough yet. 
Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: giqcass on January 02, 2014, 11:25:54 PM
I will have to figure out the code but I believe I have finally figured out a system to initiate a free outbound call.  It's a callback solution. Dial in to a sip number.  Leave a voicemail.  The voicemail is forwarded to a cloud service that initiates the GV callback or any number of other tasks.  This would of course be much simpler if obi would implement a way to send a url call with variable.  I will try to get some simple tasks going over the next week.  I see no reason why we couldn't dictate a text message using this system.
Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: giqcass on March 10, 2014, 11:13:51 PM
I haven't posted any update to this thread in a while but I have finally worked out a method to pass a variable to a url.  It is described in the Obi provisioning documentation but until recently I wasn't able to put the pieces together.
Currently I am refining the process.
Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: giqcass on March 11, 2014, 06:43:38 PM
Use Speed Dial 99 to store a variable representing the Phone number you want to call.  Pass that variable to a url that will initiate the call. 


System Management
>>>>>>>>>>>>>>>Auto Provisioning
>>>>>>>>>>>>>>>>>>>>>>>>>>>Auto Firmware Update
Method = Periodically
Interval = 5
FirmwareURL  =  IF ( $UDM0 >=1 ) FWU http://www.yourdomain.com/secretkey/$UDM0



System Management
>>>>>>>>>>>>>>>Auto Provisioning
>>>>>>>>>>>>>>>>>>>>>>>>>>User Defined Macro 0

Value = $SpeedDial.99
ExpandIn = X_DeviceManagement.FirmwareUpdate.FirmwareURL



Notes:   This works but I currently must reset speed dial 99 manually.  I have to work on the syntax to reset Speed dial 99 to 0 or empty after the url call.
Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: giqcass on March 15, 2014, 11:13:43 AM
Thanks to azrobert for this part of the setup.  I was having issues with this string.  This allows you to dial *0 and the number you want to dial to initiate the callback.  The Number you want to dial will be place in slot 99 of your speed dial.

Star Codes
>>>>>>>>>Star code profile A
>>>>>>>>>>>>>>>>>>>>>>Code 30  = *0(<99>), Set Speed Dial, coll($Spd[$Code])


Quote from: azrobert on March 15, 2014, 08:54:14 AM
Set StarCode#30 to:
*0(<99>), Set Speed Dial, coll($Spd[$Code])

Dial *018005551212

I will have to work on the logic that resets the variables after the call now.  Currently this must be done manually.
Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: giqcass on March 21, 2014, 11:54:51 PM
This is the state of my current best process for free Google Voice callback initiated via telephone. It requires a lot of setup and is not ready for everyone.  I have had a lot of help from azrobert. This involves using code found here (https://github.com/aaronpk/Google-Voice-PHP-API).  You must install it on your own web server.  I have not found a free host that is compatible yet however it can be run on a home web server and on some paid web servers.  The primary requirements are that the server does not have an open base directory and PHP is not running in safe mode.  I have hopes of modifying the script to work on a free web host.  Speed dial 99 must be left blank to use this trick.  That is where the number is stored for callback.  

Once everything is set up you can dial the number you want to call.  Using the *0 and then the number.
You will hear a confirmation tone then hang up.  
You will receive an incoming call and when you pick up the phone the number you dialed will be connected.

One limitation is that you can not dial the exact same number twice in a row.  If you wish to place a call to the last person you dialed you may redial the number with a different format then the one you used last time. If you dialed *014195551212 last time then this time you must dial *04195551212 to place the call.


http://192.168.1.100:5090 must be replaced with the address of the web server you uploaded  this code to. (https://github.com/aaronpk/Google-Voice-PHP-API)

Modifications to the Obi.
Star Codes
>>>>>>>>>Star code profile A
>>>>>>>>>>>>>>>>>>>>>>Set star code 30 as follows
*0(1xxxxxxxxxx|[2-9]xxxxxxxxx), Set Speed Dial, set($Spd[99],$code)


System Management
>>>>>>>>>>>>>>>Auto Provisioning
>>>>>>>>>>>>>>>>>>>>>>>>>>>Set ITSP Provisioning as follows.
Method = Periodically
Interval = 5
ConfigURL  = SET TPRM1 = $UDM0; @loop IF ( $TPRM1 != $UDM0 ) SYNC http://192.168.1.100:5090/gvcall.PHP?cancel=no&dialnum=$UDM0; SET TPRM1 = $UDM0; WAIT 5; GOTO loop;



System Management
>>>>>>>>>>>>>>>Auto Provisioning
>>>>>>>>>>>>>>>>>>>>>>>>>>Set User Defined Macro 0 as follows.

Value = $SpeedDial.99
ExpandIn = ALL



Thanks to azrobert for his latest help and thank you to Aaron Parecki (http://aaronparecki.com/) for the Google Voice API (https://github.com/aaronpk/Google-Voice-PHP-API).  Hopefully setup can eventually be simplified and the last few bugs ironed out.
Quote from: azrobert on March 21, 2014, 09:50:20 PM
The following works.

ITSP Provisioning:
Method: System Start
ConfigURL:
SET TPRM1 = $UDM0; @loop IF ( $TPRM1 != $UDM0 ) SYNC http://192.168.1.100:5090/gvcall.PHP?cancel=no&dialnum=$UDM0; SET TPRM1 = $UDM0; WAIT 5; GOTO loop;

Dial *01623594100
You don't have to reset Speed Dial 99.

The dialed number must be different than the last number dialed.
If you want to redial, dial the number with/without country code so it will be different than the last number dialed.

Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: giqcass on March 24, 2014, 01:01:13 AM
azrobert has made some upgrades that I plan to test myself.  I am currently running the same php code found here. (https://github.com/aaronpk/Google-Voice-PHP-API) I am running it on my Mac without adding any additional software.  Mac has apache built in so you just need to turn on the webserver and php.

Quote from: azrobert on March 22, 2014, 08:59:58 AM
I made some changes.
I didn't like *0, so I changed it to just *
I added 7 digit dialing. Change 480 in the StarCode30 to your local area code.
I added a redial feature (*00). It can only be used once after dialing a number.

StarCode30:
*(1xxxxxxxxxx|xxxxxxxxxx|<1480>xxxxxxx|00), Set Speed Dial, set($Spd[99],$code)

ITSP Provisioning:
Method: System Start
ConfigURL:
SET TPRM1 = $UDM0; @loop IF ( $UDM0 == 00 ) GOTO redial; SET TPRM2 = $UDM0; GOTO checkit; @redial SET TPRM2 = $TPRM1; @checkit IF ( $TPRM1 != $UDM0 ) SYNC http://192.168.1.100:5090/gvcall.PHP?cancel=no&dialnum=$TPRM2; SET TPRM1 = $UDM0; WAIT 5; GOTO loop;

I refined this method, but this was giqcass' idea. I would have never thought of this hack.
This is a better method than the one I was using with the Wamp Server.
Anyway, thank you giqcass.
Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: azrobert on March 27, 2014, 08:23:37 AM
giqcass,

In another thread you said you looked at Tropo.

Tropo is what I originally used to get the callback script to work. The callback script won't run under Tropo, but you can use it to bridge SIP to HTTP. I have 2 versions.

Version 1
Tropo initiates the callback via the Wamp Server.
The Tropo script waits 40 seconds.
You don't have to hang up.
When the callback arrives, you hear the Call Waiting tone.
Hit flash to connect to the call.
You can also hang up and wait for the callback to ring your phone.


Version 2
Tropo initiates the callback via the Wamp Server.
The Tropo script enters a Tropo conference.
You don't hang up.
The callback number is pointed to the same conference.
When the callback arrives you are connected without doing anything.
When you hang up the Tropo script issues a GV call cancel via Wamp.
If you didn't cancel the call and the callee didn't hang up, they would stay connected to the conference.


IMHO, the best way to run the callback script is under Asterisk. With Asterisk you can also merge the outgoing call with the callback.
Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: giqcass on March 28, 2014, 02:30:37 AM
Asterisk would be the most seamless option without an outside server or service.  I signed up for a Tropo account and spent some time poking around.  I have been more a Voxeo user.  I didn't use either for a callback script.  I mostly use Voxeo to route incoming Skype calls.  I have a Skype user name that forwards to the free +990 number that Voxeo(and tropo) provide. Should anyone try this only the older versions of Skype let you enter the +990 number as a forwarding number.  Skype doesn't charge to call or forward to +990 numbers.

I have yet to install my own Asterisk server but I'm considering a Raspberry Pi or Beagle bone black.  Once you have an Obi then Asterisk seems to be the logical next step if you want to upgrade.
Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: azrobert on March 28, 2014, 03:38:16 PM
You can run PBX in a Flash in a virtual machine. I know you have a Mac and there are versions that will run on your machine.
See: http://pbxinaflash.com/vm/

I'm running PIAF under VMWARE on an XP machine. On a virtual machine you can install a newer version of PIAF without deleting the old version. On a Raspberry Pi  you can do the same by buying another sdhc card.

This is my hardware. It' about the size of a large paperback book and the only moving part is the hard drive.
http://www.cnet.com/products/shuttle-xs35-702-atom-d510-1-66-ghz/specs/
Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: giqcass on March 30, 2014, 02:42:35 PM
That looks like a nice little unit.  The atom processor probably doesn't require a lot of juice either.
Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: corporate_gadfly on April 06, 2014, 02:00:22 PM
Quote from: azrobert on March 27, 2014, 08:23:37 AM
IMHO, the best way to run the callback script is under Asterisk. With Asterisk you can also merge the outgoing call with the callback.
I was able to use asterisk (using pygooglevoice for the callback script) and call bridging successfully. Feel like I am somewhat ready for May 15, 2014. The end user experience was a slightly longer ringing tone while the call bridging happens.
Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: Roger on April 10, 2014, 09:14:46 AM
I am trying this out.  I wasn't sure how to pass in my google credentials, so for now I just hard coded them into the php code.  When I try it I heard the numbers dialing, then it sounds like it hangs up and I hear a dial tone again.  When I check the speed dial the number I dialed was added to slot 99, so that part is working.  Is there any way to verify that the php code was loaded into the Obi?
Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: giqcass on April 10, 2014, 05:10:34 PM
Quote from: Roger on April 10, 2014, 09:14:46 AM
I am trying to implement this with Aaron's googlevoice.php code, but I don't see where to add my google voice credentials.
googlevoice.php remains completely untouched when you implement it.

Please have a look at example.php.  That's where all of the code you need to modify is.  Most of the code isn't needed.  Let us know if you need additional help.
Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: Roger on April 11, 2014, 06:57:51 PM
I have tested out the code and am able to place a call using the sample php code below, but not from the Obi.  What I don't understand is how the Obi sends my username and password to the php code and how the Obi knows to call the callNumber function within the php code. 

<?php

ini_set('display_errors', 'On');

include('gvcall.php');

// NOTE: Full email address required.
$gv = new GoogleVoice('username@gmail.com', 'passwd');

// Call a phone from one of your forwarding phones.
$gv->callNumber('12123334444', '16315971111', 'home');

?>

For anyone else trying this out, adding "ini_set('display_errors', 'On');" to the code will provide useful error messages.  I had to install php5-curl which didn't come with my basic php install.
Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: azrobert on April 11, 2014, 10:11:04 PM
FYI I deleted all the code in the script except Login, callnumber and cancelcall.
This is not necessary.

I added some code to the Example script.
I hard coded all the parms in the script except the outbound number.
From the OBi I sent the script the outbound number and another parm.
Based on the value of the extra parm I did a callnumber or a cancelcall.

Edit:
If you are running the script on a Web server you don't need the cancelcall. Always do a callnumber.

Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: azrobert on April 11, 2014, 11:05:59 PM
I re-read your post and I'm not sure I answered your question.
Are you asking how to pass parms to the script?

Call the script like this:
http://192.168.1.100:5060/gvcall.PHP?dialnum=18005551212

In the script do:
$dialnum = $_GET["dialnum"];
$gv->callNumber($dialnum, '3601234567', 'home');
Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: Roger on April 12, 2014, 06:11:07 AM
Thanks so much azrobert and giqcass for your help.  I didn't know I needed to add to the script.  I am now able to place a call via a URL as such:

http://localhost/gv.php?dialnum=12123334444

Please bear with me as I am learning PHP as I go, but I have a two more questions:

1) Do I use the configURL to get the Obi to execute the URL: http://localhost/gv.php?dialnum=12123334444?
Here is my configURL: 

SET TPRM1 = $UDM0; @loop IF ( $TPRM1 != $UDM0 ) SYNC http://192.168.1.145/gv.php?dialnum=$UDM0; SET TPRM1 = $UDM0; WAIT 5; GOTO loop;

Does that look okay?  192.168.1.145 is the server IP from my router, which sits behind my Obi.  Will the Obi be able to get to that address?

2) While I am able to place a call via a URL from my localhost, when I put the same php code on a website hosted by fatcow.com I get an error when placing a call.  Would you be able to guess the problem based on the error message below?

Fatal error: Uncaught exception 'Exception' with message 'Could not log in to Google Voice with username: username@gmail.com' in /hermes/waloraweb099/b1942/moo.xxxxx/gvcall.php:67 Stack trace: #0 /hermes/waloraweb099/b1942/moo.xxxxx/gvcall.php(89): GoogleVoice->_logIn() #1 /hermes/waloraweb099/b1942/moo.xxxxx/gv.php(15): GoogleVoice->callNumber('12123334444', '16314445555', 'home') #2 {main} thrown in /hermes/waloraweb099/b1942/moo.xxxxx/gvcall.php on line 67
Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: azrobert on April 12, 2014, 10:19:44 AM
1)
Try it and see what happens.
Don't forget "Method=System Start" under provisioning and the Star Code.

2)
In the script try changing the code under the Login section to: 
               $this->_ch = curl_init();
                curl_setopt($this->_ch, CURLOPT_COOKIEJAR, $this->_cookieFile);
                curl_setopt($this->_ch, CURLOPT_FOLLOWLOCATION, TRUE);
                curl_setopt($this->_ch, CURLOPT_RETURNTRANSFER, TRUE);
                // Withtout the next line I get cURL errors
                curl_setopt($this->_ch, CURLOPT_SSL_VERIFYPEER, false);

                curl_setopt($this->_ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 7.0; Windows

I never used a VPS, but you should install PBX in a Flash. I think Asterisk is a better solution. It's a harder install than a Web Server, but not that much. If you go this route, PHP retrieves parms differently under Asterisk.
Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: azrobert on April 12, 2014, 11:34:17 AM
I said:
QuoteI never used a VPS, but you should install PBX in a Flash. I think Asterisk is a better solution. It's a harder install than a Web Server, but not that much.

I think this is bad advice. I assume the VPS will require you to use their OS. PIAF installs CentOS, so you will need to install Asterisk by itself.

Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: Roger on April 12, 2014, 01:19:43 PM
Quote from: azrobert on April 12, 2014, 10:19:44 AM
1)
Try it and see what happens.
Don't forget "Method=System Start" under provisioning and the Star Code.

I did set Method to System Start and added the Star Code.  The number I want to call does show up in speed dial #99, so that part is working.   When I try it after it dials the number (*12124445555) it hangs up and gives me back a dial tone.  I hang up but never get a call back.

2)
In the script try changing the code under the Login section to: 
               $this->_ch = curl_init();
                curl_setopt($this->_ch, CURLOPT_COOKIEJAR, $this->_cookieFile);
                curl_setopt($this->_ch, CURLOPT_FOLLOWLOCATION, TRUE);
                curl_setopt($this->_ch, CURLOPT_RETURNTRANSFER, TRUE);
                // Withtout the next line I get cURL errors
                curl_setopt($this->_ch, CURLOPT_SSL_VERIFYPEER, false);

                curl_setopt($this->_ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 7.0; Windows

I added the line you suggested, but the problem is that google security is blocking the browser sign-in attempt.  I tried to dismiss it and say it was me, but google still blocks it and I can't figure out how to get it allowed.  I tried 2-step security with an application specific password, but that didn't work either.

Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: azrobert on April 12, 2014, 02:15:37 PM
Sign into Google once with this link:
https://accounts.google.com/ServiceLogin?passive=1209600&continue=https%3A%2F%2Faccounts.google.com%2FDisplayUnlockCaptcha&followup=https%3A%2F%2Faccounts.google.com%2FDisplayUnlockCaptcha

Edit:
When Google detects a new location accessing your account they require you to change your password

or

Use the above link to allow access without PW change.
Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: Roger on April 12, 2014, 02:26:01 PM
I was just going to post that.  DisplayUnlockCaptcha fixed issue #2.  I have updated my configURL to use the external server to eliminate any potential problem with the Obi not seeing the laptop.  When I dial I get a hang up and new dial tone.  I hang up, but don't get a call back.  Does the Obi have a log file or any way to see the error message.  I couldn't find one.
Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: danielbliss on April 17, 2014, 05:22:00 PM
I believe all of this can be done by registering sipsorcery.com and using their GV dial plan.  Does Sip Sorcery no longer offer free accounts (it's been awhile since I used them)?
Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: gderf on April 17, 2014, 05:30:18 PM
SipSorcery no longer offers free accounts.
Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: danielbliss on April 17, 2014, 05:49:34 PM
Yep, was just checking that out myself.  Bummer.  I was hoping to jump back on my old account there now that the free Obi-GV outbound solution is about to expire. 
Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: giqcass on April 19, 2014, 12:18:02 PM
Quote from: danielbliss on April 17, 2014, 05:49:34 PM
Yep, was just checking that out myself.  Bummer.  I was hoping to jump back on my old account there now that the free Obi-GV outbound solution is about to expire. 
Why can't you use your old free account?  I stopped using mine for at least a year.  Probably longer.  I only had to log in and update my dial plan to get it working again.
Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: danielbliss on April 19, 2014, 07:41:21 PM
Quote from: giqcass on April 19, 2014, 12:18:02 PM
Quote from: danielbliss on April 17, 2014, 05:49:34 PM
Yep, was just checking that out myself.  Bummer.  I was hoping to jump back on my old account there now that the free Obi-GV outbound solution is about to expire. 
Why can't you use your old free account?  I stopped using mine for at least a year.  Probably longer.  I only had to log in and update my dial plan to get it working again.
Before Aaron created paid plans, I donated a chunk of money to him because I enjoyed using his service and benefited from it.  A few months later, he came out with the paid plans and, because I had donated more than he was asking, he offered to freely promote my account to premium for 2 years.  I accepted.  A year later, I bought my Obi, unplugged my Linksys PAP2T and never signed back into SipSorcery: I no longer needed to use the dial plans.

Fast forward to now and the ending of GV's XMPP service.  I tried to log in to SipSorcery and was greeted by a message informing me that I could not log in until I paid some money (because the end of my premium period credit had expired).  I wrote an email to Aaron stating that I only needed a free account now, and asked if he preferred that I simply create a new account or have my existing account downgraded.  That was before I figured out that he was no longer offering free accounts as an option.

I never heard back from him.  I don't blame him.  I'm sure he's not getting rich off of his service: he's probably not even breaking even.  I suppose I could plead the case to him that if I had simply said "never mind, I'll just keep a free account" a few years ago, I'd still have my account... but I know from his forums that he's had to deal with quite a few whiners and I really don't want to add my voice to that chorus.

Bottom line: I don't want to pay $69 a year to keep the account, and will find another solution.  The Obi obviates the need for much of what SipSorcery's dial plans accomplish.  I rarely use my phone and will content myself with a cheap pay-as-you go outbound plan (while continuing to use a free Callcentric DID + GV forwarding for inbound).

UPDATE: Aaron emailed me this morning and reset my account to free.  I may just need to make another donation to SipSorcery.  Can't say enough good things about him and the service his site provides.
Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: Roger on April 27, 2014, 03:57:32 PM
Finally got this to work.  I don't want to admit how long it took me.  For me the problem was the User Defined Macro 0 "ExpandIn" parameter, which I had set to ALL, and wasn't valid on my obi.  The obitalk portal doesn't show the third line, so I didn't notice it, but if you log into the Obi device and look at it there the third line shows "SyntaxCheckResult" and ALL does not PASS.  I changed it to ANY and that shows PASS and now it works.

Thank you SO MUCH to giqcass and azrobert.  This is simply amazing creativity on your parts.

Regarding Sipsorcery, Yes Aaron is a really nice and helpful guy, but the service wasn't working reliably for me, and with the Obi I didn't need to dialplan, which is one of the main features of sipsorcery.
Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: Roger on April 29, 2014, 08:16:33 AM
While I am able to initiate a callback using this method, I am not sure if it is working as it should be.  Trying to understand the configURL it seems that the Obi should only sync when a different number is dialed.  Mine syncs up based on the wait internal.  If I set the weight interval at 5 it syncs up 11 times per minute and if I set the WAIT interval to 15 it syncs up 4 times per minute.  Can anyone clarify this for me?  I have tried to describe how I understand it below.  Maybe that will help highlight any misunderstanding:

Starcode 30 is configured to assign a number to speed dial #99, so when you dial *2125551212 speed dial #99 is populated with 2125551212.  User Defined Macro 0 (UDM0) is set to equal the value of speed dial #99.  Beyond that the main thing to study is the ConfigURL (broken up into lines):

    SET TPRM1 = $UDM0;
    @loop IF ( $UDM0 == 00 ) GOTO redial;
    SET TPRM2 = $UDM0;
    GOTO checkit;
    @redial SET TPRM2 = $TPRM1;
    @checkit IF ( $TPRM1 != $UDM0 ) SYNC http://www.abc.org/gv.php?dialnum=$TPRM2;
    SET TPRM1 = $UDM0;
    WAIT 5;
    GOTO loop;

Temprorary Macro 1 is set to User Defined Macro 0 the first time the Obi starts up.
Then a loop starts. It checks if redial (00) has bee pressed. If so, proceed to @redial.
Otherwise set Temporary Macro 2 to User Defined Macro 0.
So the first time a call is made Temporary Macro 2 will contain the number and Temporary Macro 1 will be blank because it has not been updated yet for the dialed number.
@checkit will find that Temporary Macro 1 will be blank and User Defined Macro 0 will have a number, so the Obi will SYNC and place the call.
The next line after @checkit sets Temporary Macro 1 to equal User Defined Macro 0, so the obi doesn't SYNC again.
Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: azrobert on April 29, 2014, 01:25:20 PM
Roger,

Do you just want to understand the script or is there something wrong?

Here is an explanation of the script:

$UDM0 is the current dialed number.
$TPRM1 is the last dialed number.
$TPRM2 contains the current dialed number or the last dialed number on a redial.

Forget about SYNC. It's just the syntax of the statement.
"SYNC http://www.abc.org/gv.php?dialnum=$TPRM2" executes the URL
"IF ( $TPRM1 != $UDM0 )" != is NOT EQUAL, so I'm checking if a new number has been dialed.
Therefore, the URL is only executed when the current number is not equal to the last number dialed.
You cannot repeat dial the same number, including the redial number.
If you do, the script will not recognize it because the $UDM0 will still be equal to $TPRM1.

The loop is basically doing nothing, except checking if you dialed a new number.
When it detects a new number, it executes the URL.
The wait is how long you want the script to pause before checking for a new number.

Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: Roger on April 29, 2014, 04:59:35 PM
I though there was something wrong because I included an email feature in my php code and I was getting 11 emails every minute, so the URL was getting executed every time through the loop.  By trial and error I seem to have figured out that after you reboot the Obi you have to dial a number and then dial redial to get all the parameters filled in.  After that the URL will only get executed when a call is placed.  So everything seems fine now.  Thanks again.
Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: azrobert on April 29, 2014, 09:07:28 PM
Roger,

What you describe shouldn't happen. The first command gets executed only on startup and sets TPRM1 to equal $UDM0, so the URL shouldn't be executed until you dial a new number. It also shouldn't matter if you set Method to Periodically instead of System Start. You would just execute the script additional times setting TPRM1 to $UDM0.

Even if there was a logic error on startup that I don't see, the script would only be executed once, because the next command sets TPRM1 to $UDM0. Maybe if Speed Dial #99 was set to a null value would cause a problem. I didn't test that condition.

I've been really busy the last few days. I'm trying to get a Raspberry Pi configured and I haven't had much time to spend on that project, so I probably won't look at this for awhile. Let me know if you discover anything.

   

Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: Roger on April 30, 2014, 05:45:08 AM
As my contribution to this effort I will post detailed instructions based on my experience setting this up:

How to Initiate a Google Callback from an Obi Device

Acknowledgements: This procedure uses php code by Aaronpk (https://github.com/aaronpk/Google-Voice-PHP-API). The Obi configuations were devised by giqcass and azroberts on the Obi forum. My role is solely documantary in nature.

Requirements: Besides needing an Obi device and a Google Voice Number, you will need access to a server where you can host php files on a webserver (herein called abc.org)

Step 1: Configure the Obi as follows

System Management > ITSP Provisioning

Method: System Start

ConfigURL: SET TPRM1 = $UDM0; @loop IF ( $UDM0 == 00 ) GOTO redial; SET TPRM2 = $UDM0; GOTO checkit; @redial SET TPRM2 = $TPRM1; @checkit IF ( $TPRM1 != $UDM0 ) SYNC http://www.abc.org/gv.php?dialnum=$TPRM2; SET TPRM1 = $UDM0; WAIT 5; GOTO loop;

System Management > User Defined Macro 0

Value: $SpeedDial.99

ExpandIn: ANY

Star Codes > Star Codes Profile A

Code30: *(1xxxxxxxxxx|xxxxxxxxxx|<212>xxxxxxx|00S0), Set Speed Dial, set($Spd[99],$code)

change <212> to whatever your area is if you want to use 7-digit dialing.

Step 2: Upload two PHP files to the root of your server

The first PHP file is a slimmed down version of the Google Voice API by Aaronpk that I will call gvcall.php. You may also use the original API file. You may call the file any name you like, but you have to include it in the second set of php code.

gvcall.php

<?php

class GoogleVoice {
    // Google account credentials.
    private $_login;
    private $_pass;

    // Special string that Google requires in our POST requests.
    private $_rnr_se;

    // File handle for PHP-Curl.
    private $_ch;

    // The location of our cookies.
    private $_cookieFile;

    // Are we logged in already?
    private $_loggedIn = FALSE;

    public function __construct($login, $pass) {
        $this->_login = $login;
        $this->_pass = $pass;
        $this->_cookieFile = '/tmp/gvCookies.txt';

        $this->_ch = curl_init();
        curl_setopt($this->_ch, CURLOPT_COOKIEJAR, $this->_cookieFile);
        curl_setopt($this->_ch, CURLOPT_FOLLOWLOCATION, TRUE);
        curl_setopt($this->_ch, CURLOPT_RETURNTRANSFER, TRUE);
                // Withtout the next line I get cURL errors
                curl_setopt($this->_ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($this->_ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)");
    }

    private function _logIn() {
        global $conf;

        if($this->_loggedIn)
            return TRUE;

        // Fetch the Google Voice login page.
        curl_setopt($this->_ch, CURLOPT_URL, 'https://accounts.google.com/ServiceLogin?service=grandcentral&passive=1209600&continue=https://www.google.com/voice&followup=https://www.google.com/voice&ltmpl=open');
        $html = curl_exec($this->_ch);

        // Parse the returned webpage for the "GALX" token, needed for POST requests.
        if (preg_match('/name="GALX"\s*type="hidden"\s*value="([^"]+)"/', $html, $match))
            $GALX = $match[1];
        else
            throw new Exception('Could not parse for GALX token');

        // Send HTTP POST service login request.
        curl_setopt($this->_ch, CURLOPT_URL, 'https://accounts.google.com/ServiceLoginAuth');
        curl_setopt($this->_ch, CURLOPT_POST, TRUE);
        curl_setopt($this->_ch, CURLOPT_POSTFIELDS, array(
            'Email' => $this->_login,
            'GALX' => $GALX,
            'Passwd' => $this->_pass,
                'continue' => 'https://www.google.com/voice',
            'followup' => 'https://www.google.com/voice',
            'service' => 'grandcentral',
            'signIn' => 'Sign in'));
        $html = curl_exec($this->_ch);

        // Test if the service login was successful.
        if(preg_match('/name="_rnr_se" (.*) value="(.*)"/', $html, $matches)) {
            $this->_rnr_se = $matches[2];
            $this->_loggedIn = TRUE;
        }
        else {
            throw new Exception("Could not log in to Google Voice with username: " . $this->_login);
        }
    }

    /**
     * Place a call to $number connecting first to $fromNumber.
     * @param $number The 10-digit phone number to call (formatted with parens and hyphens or none).
     * @param $fromNumber The 10-digit number on your account to connect the call (no hyphens or spaces).
     * @param $phoneType (mobile, work, home) The type of phone the $fromNumber is. The call will not be connected without this value.
     */
    public function callNumber($number, $from_number, $phone_type = 'mobile') {
        $types = array(
            'mobile' => 2,
            'work' => 3,
            'home' => 1
        );

        // Make sure phone type is set properly.
        if(!array_key_exists($phone_type, $types))
            throw new Exception('Phone type must be mobile, work, or home');

        // Login to the service if not already done.
        $this->_logIn();

        // Send HTTP POST request.
        curl_setopt($this->_ch, CURLOPT_URL, 'https://www.google.com/voice/call/connect/');
        curl_setopt($this->_ch, CURLOPT_POST, TRUE);
        curl_setopt($this->_ch, CURLOPT_POSTFIELDS, array(
            '_rnr_se' => $this->_rnr_se,
            'forwardingNumber' => '+1'.$from_number,
            'outgoingNumber' => $number,
            'phoneType' => $types[$phone_type],
            'remember' => 0,
            'subscriberNumber' => 'undefined'
            ));
        curl_exec($this->_ch);
    }

    /**
     * Cancel a call to $number connecting first to $fromNumber.
     * @param $number The 10-digit phone number to call (formatted with parens and hyphens or none).
     * @param $fromNumber The 10-digit number on your account to connect the call (no hyphens or spaces).
     * @param $phoneType (mobile, work, home) The type of phone the $fromNumber is. The call will not be connected without this value.
     */
    public function cancelCall($number, $from_number, $phone_type = 'mobile') {
        $types = array(
            'mobile' => 2,
            'work' => 3,
            'home' => 1
        );

        // Make sure phone type is set properly.
        if(!array_key_exists($phone_type, $types))
            throw new Exception('Phone type must be mobile, work, or home');

        // Login to the service if not already done.
        $this->_logIn();

        // Send HTTP POST request.
        curl_setopt($this->_ch, CURLOPT_URL, 'https://www.google.com/voice/call/cancel/');
        curl_setopt($this->_ch, CURLOPT_POST, TRUE);
        curl_setopt($this->_ch, CURLOPT_POSTFIELDS, array(
            '_rnr_se' => $this->_rnr_se,
            'forwardingNumber' => '+1'.$from_number,
            'outgoingNumber' => $number,
            'phoneType' => $types[$phone_type],
            'remember' => 0,
            'subscriberNumber' => 'undefined'
            ));
        curl_exec($this->_ch);
    }

}

?>
The second PHP file I will call gv.php. You can see that this was referred to in the ConfigURL above as http://www.abc.org/gv.php You will need to modify this code to contain your Google Voice credentials. You will also need to change 12223334444 to your callback number (the phone number in Google Voice settings that rings on your Obi device). I have added the line "ini_set('display_errors', 'On');" to provide valuable messages in case of errors. The messages could be removed after testing is complete. I have also added an email notification for each call. Again, this is primarily for testing purposes.

gv.php

<?php
ini_set('display_errors', 'On');
include('gvcall.php');
$dialnum = $_GET["dialnum"];
if ($dialnum != '') {
  $gv = new GoogleVoice('username@gmail.com', 'password');
  $gv->callNumber($dialnum, '12223334444', 'home');
  mail("webmaster@abc.org","gvcall made to $dialnum",$dialnum,"From:\n");
}
?>
As you can see the Google Voice username, password, and callback number are hard-coded into this second php file. You may wonder about the security of this, but my limited understanding–based on web searches–is that as long as the php files are being properly processed by the server, no one will be able to see your password. If, however, your server was not configured properly for php files, the code would be shown in plain text.

Step 3: Testing

Once the two php files have been uploaded to the server, try to access one of them from a browser by, for example, typing the following into your browser (replace abc.org with your server name): http://www.abc.org/gv.php If you get a blank screen that is a good sign because that means the server is processing the php code. If you are able to see the php code, that means the server is not processing the php code and instead just returning it. You need to have PHP5 and PHP5-Curl installed on the server and have it configured to process php code (left to other tutorials).

Testing the call using a browser

Once you believe the server is handling the php code properly you can test a call via the following URL: http://www.abc.org/gv.php?dialnum=12125551212 where 12125551212 is the number you want to call. If this works properly your phone should ring within a few seconds from enter this URL into your browser. If your phone does not ring, try entering just the first part and seeing if you get an error message: http://www.abc.org/gv.php

If you get a message that your Google Voice login failed, try clicking through the following link: https://accounts.google.com/ServiceLogin?passive=1209600&continue=https%3A%2F%2Faccounts.google.com%2FDisplayUnlockCaptcha&followup=https%3A%2F%2Faccounts.google.com%2FDisplayUnlockCaptcha That should re-enable your access. Try again until you are able to make a call with the URL.

Testing the call using the Obi

Now that you are able to make a call using the browser, you are ready to make a call using the Obi. Dial the number you want to call with a star in front of it. For example if you want to call 1-212-555-1212 dial *12125551212. You should hear a new dial tone, after which you can hang up and wait for the callback.

Step 4: Usage & Start-up

Once you get everything set up, usage is exactly the same as the final test. You place a call pre-pended with the * symbol and wait for the callback. There are, however, two caveats. You cannot dial the exact same number twice (study the ConfigURL to convince yourself why this is true). A redial has been built into the process, so dialing *00 will redial the last number, but it can only be used once, then you will have to dial the whole number again. Another workaround is to use 10 digit dialing one and and 11 digit dialing the second time, so you can call *2125551212 and then dial *12125551212 and both should work.

Under start-up, I will mention the following. When rebooting the Obi UDM0, TPRM1, and TPRM2 are all null and the Obi executes the configURL every 5 seconds (or whatever you set the WAIT interval to be). That is why I put the "if ($dialnum != '') " test in my gv.php file. Once I placed a callback request and then placed a redial the configURL behaves as intended and only executes the configURL when it sees a number number dialed. These two initial calls shouldn't be necessary, but for me they appeared to be.
Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: pinchpenny on May 05, 2014, 07:52:19 PM
Quote from: Roger on April 30, 2014, 05:45:08 AM
As my contribution to this effort I will post detailed instructions based on my experience setting this up:

How to Initiate a Google Callback from an Obi Device

Acknowledgements: This procedure uses php code by Aaronpk (https://github.com/aaronpk/Google-Voice-PHP-API). The Obi configuations were devised by giqcass and azroberts on the Obi forum. My role is solely documantary in nature.

Requirements: Besides needing an Obi device and a Google Voice Number, you will need access to a server where you can host php files on a webserver (herein called abc.org)

Step 1: Configure the Obi as follows

System Management > ITSP Provisioning

Method: System Start

ConfigURL: SET TPRM1 = $UDM0; @loop IF ( $UDM0 == 00 ) GOTO redial; SET TPRM2 = $UDM0; GOTO checkit; @redial SET TPRM2 = $TPRM1; @checkit IF ( $TPRM1 != $UDM0 ) SYNC http://www.abc.org/gv.php?dialnum=$TPRM2; SET TPRM1 = $UDM0; WAIT 5; GOTO loop;

System Management > User Defined Macro 0

Value: $SpeedDial.99

ExpandIn: ANY

Star Codes > Star Codes Profile A

Code30: *(1xxxxxxxxxx|xxxxxxxxxx|<212>xxxxxxx|00S0), Set Speed Dial, set($Spd[99],$code)

change <212> to whatever your area is if you want to use 7-digit dialing.

Step 2: Upload two PHP files to the root of your server

The first PHP file is a slimmed down version of the Google Voice API by Aaronpk that I will call gvcall.php. You may also use the original API file. You may call the file any name you like, but you have to include it in the second set of php code.

gvcall.php

<?php

class GoogleVoice {
    // Google account credentials.
    private $_login;
    private $_pass;

    // Special string that Google requires in our POST requests.
    private $_rnr_se;

    // File handle for PHP-Curl.
    private $_ch;

    // The location of our cookies.
    private $_cookieFile;

    // Are we logged in already?
    private $_loggedIn = FALSE;

    public function __construct($login, $pass) {
        $this->_login = $login;
        $this->_pass = $pass;
        $this->_cookieFile = '/tmp/gvCookies.txt';

        $this->_ch = curl_init();
        curl_setopt($this->_ch, CURLOPT_COOKIEJAR, $this->_cookieFile);
        curl_setopt($this->_ch, CURLOPT_FOLLOWLOCATION, TRUE);
        curl_setopt($this->_ch, CURLOPT_RETURNTRANSFER, TRUE);
                // Withtout the next line I get cURL errors
                curl_setopt($this->_ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($this->_ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)");
    }

    private function _logIn() {
        global $conf;

        if($this->_loggedIn)
            return TRUE;

        // Fetch the Google Voice login page.
        curl_setopt($this->_ch, CURLOPT_URL, 'https://accounts.google.com/ServiceLogin?service=grandcentral&passive=1209600&continue=https://www.google.com/voice&followup=https://www.google.com/voice&ltmpl=open');
        $html = curl_exec($this->_ch);

        // Parse the returned webpage for the "GALX" token, needed for POST requests.
        if (preg_match('/name="GALX"\s*type="hidden"\s*value="([^"]+)"/', $html, $match))
            $GALX = $match[1];
        else
            throw new Exception('Could not parse for GALX token');

        // Send HTTP POST service login request.
        curl_setopt($this->_ch, CURLOPT_URL, 'https://accounts.google.com/ServiceLoginAuth');
        curl_setopt($this->_ch, CURLOPT_POST, TRUE);
        curl_setopt($this->_ch, CURLOPT_POSTFIELDS, array(
            'Email' => $this->_login,
            'GALX' => $GALX,
            'Passwd' => $this->_pass,
                'continue' => 'https://www.google.com/voice',
            'followup' => 'https://www.google.com/voice',
            'service' => 'grandcentral',
            'signIn' => 'Sign in'));
        $html = curl_exec($this->_ch);

        // Test if the service login was successful.
        if(preg_match('/name="_rnr_se" (.*) value="(.*)"/', $html, $matches)) {
            $this->_rnr_se = $matches[2];
            $this->_loggedIn = TRUE;
        }
        else {
            throw new Exception("Could not log in to Google Voice with username: " . $this->_login);
        }
    }

    /**
     * Place a call to $number connecting first to $fromNumber.
     * @param $number The 10-digit phone number to call (formatted with parens and hyphens or none).
     * @param $fromNumber The 10-digit number on your account to connect the call (no hyphens or spaces).
     * @param $phoneType (mobile, work, home) The type of phone the $fromNumber is. The call will not be connected without this value.
     */
    public function callNumber($number, $from_number, $phone_type = 'mobile') {
        $types = array(
            'mobile' => 2,
            'work' => 3,
            'home' => 1
        );

        // Make sure phone type is set properly.
        if(!array_key_exists($phone_type, $types))
            throw new Exception('Phone type must be mobile, work, or home');

        // Login to the service if not already done.
        $this->_logIn();

        // Send HTTP POST request.
        curl_setopt($this->_ch, CURLOPT_URL, 'https://www.google.com/voice/call/connect/');
        curl_setopt($this->_ch, CURLOPT_POST, TRUE);
        curl_setopt($this->_ch, CURLOPT_POSTFIELDS, array(
            '_rnr_se' => $this->_rnr_se,
            'forwardingNumber' => '+1'.$from_number,
            'outgoingNumber' => $number,
            'phoneType' => $types[$phone_type],
            'remember' => 0,
            'subscriberNumber' => 'undefined'
            ));
        curl_exec($this->_ch);
    }

    /**
     * Cancel a call to $number connecting first to $fromNumber.
     * @param $number The 10-digit phone number to call (formatted with parens and hyphens or none).
     * @param $fromNumber The 10-digit number on your account to connect the call (no hyphens or spaces).
     * @param $phoneType (mobile, work, home) The type of phone the $fromNumber is. The call will not be connected without this value.
     */
    public function cancelCall($number, $from_number, $phone_type = 'mobile') {
        $types = array(
            'mobile' => 2,
            'work' => 3,
            'home' => 1
        );

        // Make sure phone type is set properly.
        if(!array_key_exists($phone_type, $types))
            throw new Exception('Phone type must be mobile, work, or home');

        // Login to the service if not already done.
        $this->_logIn();

        // Send HTTP POST request.
        curl_setopt($this->_ch, CURLOPT_URL, 'https://www.google.com/voice/call/cancel/');
        curl_setopt($this->_ch, CURLOPT_POST, TRUE);
        curl_setopt($this->_ch, CURLOPT_POSTFIELDS, array(
            '_rnr_se' => $this->_rnr_se,
            'forwardingNumber' => '+1'.$from_number,
            'outgoingNumber' => $number,
            'phoneType' => $types[$phone_type],
            'remember' => 0,
            'subscriberNumber' => 'undefined'
            ));
        curl_exec($this->_ch);
    }

}

?>
The second PHP file I will call gv.php. You can see that this was referred to in the ConfigURL above as http://www.abc.org/gv.php You will need to modify this code to contain your Google Voice credentials. You will also need to change 12223334444 to your callback number (the phone number in Google Voice settings that rings on your Obi device). I have added the line "ini_set('display_errors', 'On');" to provide valuable messages in case of errors. The messages could be removed after testing is complete. I have also added an email notification for each call. Again, this is primarily for testing purposes.

gv.php

<?php
ini_set('display_errors', 'On');
include('gvcall.php');
$dialnum = $_GET["dialnum"];
if ($dialnum != '') {
  $gv = new GoogleVoice('username@gmail.com', 'password');
  $gv->callNumber($dialnum, '12223334444', 'home');
  mail("webmaster@abc.org","gvcall made to $dialnum",$dialnum,"From:\n");
}
?>
As you can see the Google Voice username, password, and callback number are hard-coded into this second php file. You may wonder about the security of this, but my limited understanding–based on web searches–is that as long as the php files are being properly processed by the server, no one will be able to see your password. If, however, your server was not configured properly for php files, the code would be shown in plain text.

Step 3: Testing

Once the two php files have been uploaded to the server, try to access one of them from a browser by, for example, typing the following into your browser (replace abc.org with your server name): http://www.abc.org/gv.php If you get a blank screen that is a good sign because that means the server is processing the php code. If you are able to see the php code, that means the server is not processing the php code and instead just returning it. You need to have PHP5 and PHP5-Curl installed on the server and have it configured to process php code (left to other tutorials).

Testing the call using a browser

Once you believe the server is handling the php code properly you can test a call via the following URL: http://www.abc.org/gv.php?dialnum=12125551212 where 12125551212 is the number you want to call. If this works properly your phone should ring within a few seconds from enter this URL into your browser. If your phone does not ring, try entering just the first part and seeing if you get an error message: http://www.abc.org/gv.php

If you get a message that your Google Voice login failed, try clicking through the following link: https://accounts.google.com/ServiceLogin?passive=1209600&continue=https%3A%2F%2Faccounts.google.com%2FDisplayUnlockCaptcha&followup=https%3A%2F%2Faccounts.google.com%2FDisplayUnlockCaptcha That should re-enable your access. Try again until you are able to make a call with the URL.

Testing the call using the Obi

Now that you are able to make a call using the browser, you are ready to make a call using the Obi. Dial the number you want to call with a star in front of it. For example if you want to call 1-212-555-1212 dial *12125551212. You should hear a new dial tone, after which you can hang up and wait for the callback.

Step 4: Usage & Start-up

Once you get everything set up, usage is exactly the same as the final test. You place a call pre-pended with the * symbol and wait for the callback. There are, however, two caveats. You cannot dial the exact same number twice (study the ConfigURL to convince yourself why this is true). A redial has been built into the process, so dialing *00 will redial the last number, but it can only be used once, then you will have to dial the whole number again. Another workaround is to use 10 digit dialing one and and 11 digit dialing the second time, so you can call *2125551212 and then dial *12125551212 and both should work.

Under start-up, I will mention the following. When rebooting the Obi UDM0, TPRM1, and TPRM2 are all null and the Obi executes the configURL every 5 seconds (or whatever you set the WAIT interval to be). That is why I put the "if ($dialnum != '') " test in my gv.php file. Once I placed a callback request and then placed a redial the configURL behaves as intended and only executes the configURL when it sees a number number dialed. These two initial calls shouldn't be necessary, but for me they appeared to be.

In preparation for Doomsday on May 15th, I spotted this thread in giqcass' signature.

Ah, so in order for this to work you need 1)a webserver 2)dial * before the number you want to call and 3) wait for a callback to actually initiate the call.

Dialing a * before a number my grandmother wanted to call would enrage her. Having to wait for a callback to initiate a call is simply untenable for my grandmother.

Pretty neat work around for me, perhaps, though not grandma friendly.

Why do grandmothers need landlines when they have cellphones?
Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: giqcass on May 05, 2014, 08:54:20 PM
If Obihai would open up a few more options to us this project could be made completely seamless to the end user.

1) Give us a better way to pass a number as a variable.
2) Allow us to set an incoming call so it can join a call in process.  It would be nice to simulate ringing well waiting for the callback and then join the  incoming call.  That would give a natural experience.


It could be used with other services that do Callbacks like Localphone.  Many have an actual API.  I think we could even do basin text messaging.
Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: Roger on May 06, 2014, 12:04:36 PM
What would be really cool is if the firmware for the Obi was open source, like tomato for routers.  Then anyone could create mods of it to do whatever they wanted.  Imagine the possibilities!
Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: giqcass on May 06, 2014, 02:26:54 PM
Quote from: Roger on May 06, 2014, 12:04:36 PM
What would be really cool is if the firmware for the Obi was open source, like tomato for routers.  Then anyone could create mods of it to do whatever they wanted.  Imagine the possibilities!
I wish!
Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: Roger on May 07, 2014, 05:27:22 AM
Quote from: azrobert on April 29, 2014, 09:07:28 PM
Roger,

What you describe shouldn't happen. The first command gets executed only on startup and sets TPRM1 to equal $UDM0, so the URL shouldn't be executed until you dial a new number. It also shouldn't matter if you set Method to Periodically instead of System Start. You would just execute the script additional times setting TPRM1 to $UDM0.

Even if there was a logic error on startup that I don't see, the script would only be executed once, because the next command sets TPRM1 to $UDM0. Maybe if Speed Dial #99 was set to a null value would cause a problem. I didn't test that condition.

As I mentioned before the callback works great, but sometimes the configURL script would execute every 5 seconds even though I didn't dial a number (and the dialnum would be blank).  Now I guess I see why.  I usually use the obitalk portal and I didn't see anything wrong there, but yesterday I logged into the device itself and noticed that the Obitalk provisioning script uses TPRM1 as one of its variables, so that was probably the cause of my problems.  I changed all the TPRMn to GPRMn in my configURL and hopefully that will resolve the problem.
Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: sfcwtuOBI on May 11, 2014, 08:22:44 PM
"change 12223334444 to your callback number (the phone number in Google Voice settings that rings on your Obi device"

What number is this? Is it the GV number? I tried it with my GV number, but obi device did not ring. It only works when I use my mobile number. Can someone help pls?
Title: Re: Speed dial to post to url. Part of my Google voice 2014 workaround.
Post by: giqcass on May 12, 2014, 02:31:17 AM
You must set up an incoming phone number for your Obi by getting a free DID from Callcentric, IPkall, or anyone else that provides them.  You must then verify that number with Google Voice and set it up as a forwarding phone.  Then Use that number as the Callback number.