Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Excerpt

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

Table of Contents
maxLevel2
indent1

Note
title

This demonstrative code SHOULD NOT be used in production. It is designed to simply show how an App interacts with UnifiedAPI. From this perspective, validations and error-checks aiming to demonstrate the most common mistakes are minimal and can be done easily.

Overview

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 FacebookCallMe is an App written in PHP which allows anyone to place a call with a Facebook App using using the UnifiedAPI of VoipNow 3.

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

  • Create PhoneCall -  Creates 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

...

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

STEP 1:  Download the files.Download the archive, extract the files, and copy them to a Switch to the directory that can be accessed over the Web (where your web server resides).web (e.g /var/www/html) and clone the Git repository:

Shell
languagebash
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:

...

Shell
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 file config.php in the  in the <PATH_TO_FacebookCallMe>/interface/plibconfig/config.php and 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 Appa 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 Appa Facebook App.

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.

Behavior

User Interface Interface

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

...

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

...

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

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

Code Block
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 Every 5 seconds, the javascript (lib.js)  makes a request for information about the call. Such information is obtained through a UnifiedAPI request makes a request for information about the call. Such information is obtained through a UnifiedAPI request using the List PhoneCalls resource.

Code Block
$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 The HTTP Request to retrieve a call looks as shown below:

...

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