Page tree

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 23 Next »

This page describes FacebookCallMe, a small App that allows anyone to place a call through a Facebook App.

The code is on GitHub

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

Overview

FacebookCallMe is an App written in PHP which allows anyone to place a call with a Facebook App using the UnifiedAPI of VoipNow 3.

It uses the PhoneCall resource exposed by UnifiedAPI and the following requests:

  • Create PhoneCall - Creates phone calls using any given source and destination
  • List PhoneCall - Fetches the list of phone calls that are in the system at a particular point in time

Installation

In order to be able to use the FacebookCallMe App, your system needs PHP 5.3 or higher and a web server (Apache 2, nginx, lighttpd, etc). Your VoipNow server must be at least version 3.0.0.

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

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

STEP 2: Proceed to allowing permissions and ownership rights.

You also need to give proper permissions and ownership to 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:

chmod -R 755 <PATH_TO_FacebookCallMe>
chown -R httpd:httpd <PATH_TO_FacebookCallMe>
 

STEP 3: Configure the App.

To be able to use the App, you must configure it. To do so, open the file config.php in the <PATH_TO_FacebookCallMe>/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.
REDIRECT_URIURL where Facebook redirects users when after logging in with facebook. Should be the URL where your index php is. Should be the same as in the App settings on facebook.
OAUTH_APP_IDOAuth App ID or key. A 32 char-long string used by the App to identify itself with the system.
Visit this page to see how 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 this page to see how the Secret can be obtained.
APP_IDThe application ID obtained from Facebook. You cannot obtain it unless you have registered the app with Facebook.
Click here for further details on how to make a Facebook App.
APP_SECRETThe application secret obtained from Facebook. You cannot obtain it unless you have registered the app with Facebook.
Click here for further details on how to make a Facebook App.

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

Behavior

User Interface

As soon as the setup process is complete, you can access the interface through the Facebook App. To do so, simply visit https://<IP>/<PATH_TO_FacebookCallMe>/. The page displays an input field with a button.

Enter a valid phone number and press call. The status of the call is displayed in this box. Errors are displayed as well. For a list of error messages, check the UnifiedAPI manual.

Internal Flow

Place a Phone Call

When the Call button is pressed, a Create PhoneCalls request is made through UnifiedAPI.

$reqUrl = 'https://'.$config['VN_SERVER_IP'].'/uapi/phoneCalls/@me/simple';

$request = new cURLRequest();
$request->setMethod(cURLRequest::METHOD_POST);
$request->setHeaders(array(
	'Content-type' => 'application/json',
	'Authorization' => $config['OAUTH_ACCESS_TOKEN']
));

$jsonRequest = array(
	'extension' => $config['VN_EXTENSION'],
	'phoneCallView' => array(array(
		'source' => array($config['VN_EXTENSION']),
		'destination' => $phoneNumber))
);
$request->setBody(json_encode($jsonRequest));
$response = $request->sendRequest($reqUrl);

Once the request has been made, if no error occurred, a JSON encoded response is returned. It contains a link to the newly created call. Check the example at the Create PhoneCalls page.

The HTTP Request to make a call looks as shown below:

POST /uapi/phoneCalls/@me/simple HTTP/1.1
HOST x.x.x.x
Content Type: application/json
Authorization: <OAUTH_ACCESS_TOKEN>
  
{
  "extension":"<VN_EXTENSION>",
  "phoneCallView":[
    {
       "source":["<VN_EXTENSION>"],
       "destination":["8887777"]
       "callerId":"Facebook CallMe <8887777>"
    }
  ]
}

List the Phone Call

Every 5 seconds, the javascript (lib.js) makes a request for information about the call. Such information is obtained through a UnifiedAPI request using the List PhoneCalls resource.

$request = new cURLRequest();
$request->setMethod(cURLRequest::METHOD_GET);
$request->setHeaders(array(
	'Content-type' => 'application/json',
	'Authorization' => $config['OAUTH_ACCESS_TOKEN']
));
$response = $request->sendRequest($url);

The HTTP Request to retrieve a call looks as shown below:

GET /uapi/phoneCalls/@me/<VN_EXTENSION>/<phoneCallID>
HOST x.x.x.x
Content Type: application/json
Authorization: <OAUTH_ACCESS_TOKEN>

#trackbackRdf ($trackbackUtils.getContentIdentifier($page) $page.title $trackbackUtils.getPingUrl($page))
  • No labels

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