Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Updated using 4PSA automated script

...

Excerpt

This page describes an App that uses UnifiedAPI to send faxes.

Table of Contents
maxLevel2

Note
titleThe code is on GitHub

Download here. Do not hesitate to contribute in order to make if you want to improve this example better - we welcome Pull Requests!

...

  • Your system needs to have PHP 5.3 installed or higher.
  • Your VoipNow server must be at least version 3.0.0
  • The extension should be able to send faxes.

Setup

STEP 1: Switch to the directory that can be accessed over web (e.g /var/www/html) and download the files.

Shell
 git clone https://github.com/4psa/app-click2fax.git

STEP 2: Proceed to allowing permissions and ownership rights.

You also need to give proper permissions and ownership to right for the files of the plugin - the plugin needs to be owned by the web server user and group. For example, if we use httpd as a webserver:

Shell
chmod -R 755 <PATH_TO_Click2Fax>
chown -R httpd:httpd <PATH_TO_Click2Fax>

 STEP 3: Configure the App.

In order to use the App, you must configure it. To do so, you must open the file config.php in the <PATH_TO_Click2FAX>/config/config.php and change the following settings:

NameDescription
VN_SERVER_IPThe IP or hostname of your VoipNow server;.
VN_EXTENSIONThe extended number of a phone terminal extension.
OAUTH_APP_IDOAuth App ID or key. A 32 char-long string used by the App to identify itself with the system.
Visit Check this page to see learn how to obtain the OAuth APP ID can be obtained.
OAUTH_APP_SECRETOAuth App Secret. A 32 char-long secret used by the system to establish ownership of the App ID or key.
Based on this pair, the system will recognize the new App and will allow it to generate an access token.
Visit Check this page to see learn how to obtain the Secret can be obtained.


Note
Please note that the newly created app will not work properly unless you check the App is trusted option in the Add App form.


STEP 4: Setup the system.

You also need to make sure the VoipNow system is setup set to receive faxes.

...

Behavior

User

...

interface

As soon as the setup process is complete, you can access the interface at https://<IP>/<PATH_TO_CLICK2FAX>/.

The page displays a single button that the user can click in order to send the faxes. Once the button is clicked the following form appears:for sending faxes. Click this button and a form similar to the one below will be displayed. 

 

 

 

 

 

 

 

 

 

To send the fax a user must enter the information , you must fill in the form fields as described below:following the explanations below.

Field name

Required

Description

To

Yes

A list of phone numbers separated by a comma. You can set here an a VoipNow extension from VoipNow that accepts faxes.

Attachments

Yes

Choose a file to send as the fax body of the fax .

After Once you have filled in the form is correctly filled, the user must click press the Send fax button to send the fax.

Internal

...

flow

When As soon as the Send Faxfax button is pressed, the scripts makes sends a Create Faxes request to the VoipNow server using UnifiedAPIthroughUnifiedAPI. It uses the extension defined in the global variable VN_EXTENSION as the source of the fax call.

First it sets the HTTP headers and the Request body accordingly:

Code Block
languagephp
// $token Fetch token
$token = getToken= generateToken();
 if (!$token) {
    return false;
 }

 $faxRequest = new FaxRequest();
$headers =  $faxRequest->initHeaders(array(
     'Authorization: ' =>. $token
 ));
 
$request = new cURLRequest();
				
//Fax Create uses POST
$request->setMethod(cURLRequest::METHOD_POST);
$request->setHeaders($headers);
$request->setBody(array('recipients' => array($_POST['to'])), cURLRequest::ENCODER_JSON); 				
$params = array(
    'recipients' => array($_POST['to'])
);


//Set fax information (ex. recipients list)
$this->_payload['request'] = json_encode($params);

// Set uploaded files to send them by fax
foreach ($files as $fileAlias => $fileInfo) {
    $this->_payload[$fileAlias] = new CURLFile($fileInfo['location'], $fileInfo['type'], $fileInfo['name']);
}


$response = $faxRequest->execute();

The HTTP Request made by the App looks like this:

...

Then sets the files which have been uploaded through the browser:

Code Block
languagephp
$files = array();

$numberOfFiles = count($_FILES['attachments']['name']);
$files = array();
				
forfor ($i = 0; $i < $numberOfFiles; $i++) {
	    if ($_FILES['attachments']['error'][$i] > 0) {
		        continue;
	    }
					
	//Renaming the file including the extension
	$fileext = pathinfo( $files[$_FILES['attachments']['name'][$i]], PATHINFO_EXTENSION);
	move_uploaded_file( = array(
        'location' => $_FILES['attachments']['tmp_name'][$i],
        'type' => $_FILES['attachments']['tmp_nametype'][$i].'.'.$fileext);
					
	$files[] = array($_FILES['attachments']['name'][$i],
        'name' => '@'.$_FILES['attachments']['tmp_name'][$i].'.'.$fileext
    );
	}
				
$request->setFiles($files);

Any errors will be displayed on the browser.

Note

Your Voipnow SSL certificate should be signed by a trusted certificate authority, otherwise the Click2Fax application will not be able to communicate safely with the server. You can use a self-signed certificate, but we do not recommend this on a production server.

For testing purposes only, you may add the following line into the generateToken() function available in /plib/util/.

Code Block
languagephp
curl_setopt($httpRequest, CURLOPT_SSL_VERIFYPEER, false);
// this should be added before curl_exec($httpRequest);



4psarelated
NameRelated Topics

Quick Examples

CallMeButton

Click2Conference

FacebookCallMe



Except where otherwise noted, content in this space is licensed under a Creative Commons Attribution 4.0 International.