News:

On Tuesday September 6th the forum will be down for maintenance from 9:30 PM to 11:59 PM PDT

Main Menu

Click-to-call url parameters

Started by eiznem, August 06, 2018, 09:05:20 AM

Previous topic - Next topic

eiznem

Hello fellow OBi users. This is my first post. I know there aren't any stupid questions, just stupid people asking questions (me). With that, here's the problem I'm looking to solve:

Since the Google Chrome browser extension for Google Voice click-to-call (converts phone numbers in web pages to URLs that are clickable to launch a call via your connected phone of choice) no longer works, I've been looking for another solution that will initiate the call from my browser by ringing my OBi1062 and then connecting to the phone number I clicked.

There is a browser extension (https://chrome.google.com/webstore/detail/url-networks-number2url/lndpiehcijmlgooadkonganjdnnaojhc) that would allow me to configure a URL with parameters, however I cannot seem to locate any parameters that would accomplish this on my OBi1062. I would expect something like http://192.168.1.100?CallPhoneNumber=5555555555&Line=sp1 (where 192.168.1.100 represents my OBi's IP address). Does anyone know of parameters I can use to initiate a call from my browser that will ring to my OBi on sp1 then dial out to the phone number I clicked when I answer that line?

Thanks in advance.

azrobert


eiznem


eiznem

For those that want the Google Voice click-to-call function in Google Chrome, follow these modified instructions from azrobert (taken from post at http://www.obitalk.com/forum/index.php?topic=14632.0) as well as my additional instructions below:

1. Obtain a SIP DID (CallCentric has free NY state DIDs with free inbound) and set it up on your GV account as a forwarding number as well as on your OBi device ...mine is an OBi1062).

2. Setup XAMPP (download here: https://www.apachefriends.org/index.html | install instructions here: https://undsgn.com/xampp-tutorial/ ...ignore the WordPress stuff but be sure to start Apache from the XAMPP Control Panel after installation)

3. Copy and paste the script below into Notepad. At the end of the script change Name to your GV name, change password to your GV password, and change 1xxxxxxxxxx to your CallCentric DID number (No + sign).

4. Save the file as gvcallback.php (Do NOT save it as a txt file, use type ALL FILES) then move the gvcallback.php file to folder XAMPP/htdocs.

5. Test the script, just enter the following in a web browser: http://192.168.1.xx/gvcallback.PHP?dialnum=8005551212 (192.168.1.xx is the IP address of the computer running XAMPP Web Server.
8005551212 is the number you're wanting to call). Your DID number will ring. After you answer, GV will call the number you specified.

6. Install URL Networks number2url Chrome Extension (https://chrome.google.com/webstore/detail/url-networks-number2url/lndpiehcijmlgooadkonganjdnnaojhc)

7. Alter the options of the number2url extension with the following:
     Profile: International (outside Australia)
     Mode: Active (left click actions)
     Protocol: Custom URL
     Custom URL: http://$1/gvcallback.PHP?dialnum=$0&outgoing_uri=$2
     Phone IP: 192.168.1.xx (this will be the IP address of the computer running XAMPP)
     Link Target: Default

Be sure to click save when you've finished. Now go find a phone number online and click it to call. This will work great for sales people using CRMs to call sales leads, etc.

Thank you for your help on this azrobert!

<?php

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

// Special string that Google Voice 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->_chCURLOPT_COOKIEJAR$this->_cookieFile);
curl_setopt($this->_chCURLOPT_FOLLOWLOCATIONTRUE);
curl_setopt($this->_chCURLOPT_RETURNTRANSFERTRUE);
curl_setopt($this->_chCURLOPT_USERAGENT"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)");  //was "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko"
}

private function _logIn() {
global $conf;

if($this->_loggedIn)
return TRUE;

// Fetch the Google Voice login page input fields
$URL='https://accounts.google.com/ServiceLogin?service=grandcentral&passive=1209600&continue=https://www.google.com/voice/b/0/redirection/voice&followup=https://www.google.com/voice/b/0/redirection/voice#inbox';  //adding login to GET prefills with username "&Email=$this->_login"
curl_setopt($this->_chCURLOPT_URL$URL);
$html curl_exec($this->_ch);

// Send HTTP POST service login request using captured input information.
$URL='https://accounts.google.com/signin/challenge/sl/password';  // This is the second page of the two page signin
curl_setopt($this->_chCURLOPT_URL$URL);
$postarray $this->dom_get_input_tags($html);  // Using DOM keeps the order of the name/value from breaking the code.

// Parse the returned webpage for the "GALX" token, needed for POST requests.
if((!isset($postarray['GALX']) || $postarray['GALX']=='') && (!isset($postarray['gxf']) || $postarray['gxf']=='')){
$pi1 var_export($postarrayTRUE);
error_log("Could not parse for GALX or gxf token. Inputs from page:\n" $pi1 "\n\nHTML from page:" $html);
throw new Exception("Could not parse for GALX or gxf token. Inputs from page:\n" $pi1);
}

$postarray['Email'] = $this->_login;  //Add login to POST array
$postarray['Passwd'] = $this->_pass;  //Add password to POST array
curl_setopt($this->_chCURLOPT_POSTTRUE);
curl_setopt($this->_chCURLOPT_POSTFIELDS$postarray);
$html curl_exec($this->_ch);

// Test if the service login was successful.
$postarray $this->dom_get_input_tags($html);  // Using DOM keeps the order of the name/value from breaking the code.
if(isset($postarray['_rnr_se']) && $postarray['_rnr_se']!='') {
$this->_rnr_se $postarray['_rnr_se'];
$this->_loggedIn TRUE;
} else {
$pi2 var_export($postarrayTRUE);
error_log("Could not log in to Google Voice with username: " $this->_login .
  "\n\nMay need to change scraping.  Here are the inputs from the page:\n"$pi2
 );  //add POST action information from DOM.  May help hunt down single or dual sign on page changes.
throw new Exception("Could not log in to Google Voice with username: " $this->_login "\nLook at error log for detailed input information.\n");
}
}

/**
 * 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->_chCURLOPT_URL'https://www.google.com/voice/call/connect/');
curl_setopt($this->_chCURLOPT_POSTTRUE);
curl_setopt($this->_chCURLOPT_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->_chCURLOPT_URL'https://www.google.com/voice/call/cancel/');
curl_setopt($this->_chCURLOPT_POSTTRUE);
curl_setopt($this->_chCURLOPT_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);
}

/**
 * Source from http://www.binarytides.com/php-get-name-and-value-of-all-input-tags-on-a-page-with-domdocument/
 * Generic function to fetch all input tags (name and value) on a page
 * Useful when writing automatic login bots/scrapers
 */
private function dom_get_input_tags($html)
{
    $post_data = array();

    // a new dom object
    $dom = new DomDocument;

    //load the html into the object
    @$dom->loadHTML($html);  //@suppresses warnings
    //discard white space
    $dom->preserveWhiteSpace FALSE;

    //all input tags as a list
    $input_tags $dom->getElementsByTagName('input');

    //get all rows from the table
    for ($i 0$i $input_tags->length$i++)
    {
        if( is_object($input_tags->item($i)) )
        {
            $name $value '';
            $name_o $input_tags->item($i)->attributes->getNamedItem('name');
            if(is_object($name_o))
            {
                $name $name_o->value;

                $value_o $input_tags->item($i)->attributes->getNamedItem('value');
                if(is_object($value_o))
                {
                    $value $input_tags->item($i)->attributes->getNamedItem('value')->value;
                }

                $post_data[$name] = $value;
            }
        }
    }

    return $post_data;
}

}

// NOTE: Full email address required.

$gv = new GoogleVoice('Name@gmail.com''password');

// Call a phone from one of your forwarding phones.

$dialnum $_GET["dialnum"];

$gv->callNumber($dialnum'1xxxxxxxxxx''home');

?>