The cheapest way to make international calls from your own phone

PokeTALK API Documentation.

Welcome to PokeTALK's developer wiki. This documentation site aims to guide you on how to both create additional features onto the PokeTALK site, as well as using our telephony API to create your own standalone applications.

Please note that this documentation site is still under development as we add more to the API.

For any questions please do not hesitate to contact our dev team at: developers@poketalk.com

Getting Started

poketalk.base.js

Core module

few helper functions

poketalk.addressbook.js (optional)

Use user contacts list

poketalk.report.js (optional)

User billing report


 

additional services


Setting up

Overview

Getting up and running with the PokeTALK API takes no more than a few minutes.

  • Register your API to receive an API Key. We're putting together a registration for this, but for now you'll need to shoot us an email at developers@poketalk.com with the request for an API key. Please include a short description of the application you will be developing/integrating.
  • Download the PokeTALK Proxy and unzip it in your root directory. i.e /var/www/my_website.
  • Create a new HTML file, including both JQuery and the poketalk.base.js API in the header. You'll need to initialize the API by setting the path to your proxy file and your API key. Below is some sample code outlining this process.
    <html>
 
       <head>
          <title>PokeTALK API example</title>
          <script type="text/javascript" src="http://www.poketalk.biz/apijs/jquery-1.3.2.min.js"></script>
          <script type="text/javascript" src="http://www.poketalk.biz/apijs/poketalk.base.js"></script>
       </head>
 
      <script type="text/javascript">
         ptBase.init('http://www.example.com/pt_proxy_curl.php', 'YOUR_API_KEY');  
      </script>
 
      <body>
          PokeTALK API Example
      </body>
 
   </html>
  • That's all folks!

Minimum requirements

Minimum Requirements

Please make sure you meet the following technical requirements:


Optionally you may choose to include PokeTALK's JQuery version (already bundled with the cookie plugin) directly from PokeTALK, using the following line in the HEAD section of your HTML:

<script type="text/javascript" src="http://www.poketalk.biz/apijs/jquery-1.3.2.min.js"></script>

Creating Features

Add your feature/application to PokeTALK

The PokeTALK API allows you to add on features to the PokeTALK site, for other users to enjoy. Every feature you create will be made available for all users in the Services Manager.

Getting Started

To get started you will need register your feature. Please send an email to developers@poketalk.com with the following information (this will be an automated procedure soon):


Setting up

Once you've registered your information you'll receive an API Key from us for this specific feature. We'll add the feature to your services list so you'll be able to begin testing things out. Once a user clicks on your feature, PokeTALK will request the page located at the Callback URL which you've specified at registration. This needs to be a clean HTML page without the HEAD,BODY,or HTML tags included, for example the following would be acceptable:

 
    <div> Hello world! </div>


The following would NOT be acceptable:

 
    <html>
        <head><title>not acceptable</title></head>
        <body>
           <div> Hello world! </div>
        </body>
    </html>

The space you have available for the feature is 540px wide, and its recommended you use a max height of 400-500px.


Add contact

Contents

Description

Add new contact to user addressbook

Usage

    ptAddressbook.add_contact(contact_name, company, prefix, number, prefix_1, number_1, prefix_2, number_2, email, callback);

or

    var result = ptAddressbook.add_contact(contact_name, company, prefix, number, prefix_1, number_1, prefix_2, number_2, email);

Parameters

Required Name Type Description
required contact_name string new contact name
optional company string contact company
optional prefix string first phone country prefix
optional number string first phone number (landline)
optional prefix_1 string second phone country prefix
optional number_1 string second phone number (mobile)
optional prefix_2 string third phone country prefix
optional number_2 string third phone number (office)
optional email string contact e-mail
optional callback function optional callback function to call after execution

Response

object (JSON)

 
    {"result":boolean}
Parameter Type Description
result boolean returns true if new contact added, false otherwise.

Example

Use result object

var data = ptAddressbook.add_contact(contact_name, company, prefix, number, prefix_1, number_1, prefix_2, number_2, email);
if(data.result){
    alert("New contact added");
}else{
    alert("Can`t add new contact");
}

Use callback function

ptAddressbook.add_contact(contact_name, company, prefix, number, prefix_1, number_1, prefix_2, number_2, email, function(data){
    if(data.result){
        alert("New contact added");
    }else{
        alert("Can`t add new contact");
    }
});

Check login

Contents

Description

This method allows you to determine if a user is logged in or not.

Usage

    ptBase.check_login(callback);

or

    var result = ptBase.check_login();

Parameters

Required Name Type Description
optional callback function optional callback function to call after execution

Response

Parameter Type Description
result boolean returns true if the user is logged in, false otherwise.

object

 
   {"result":true}

Example

 
   ptBase.check_login(function(data){
      if (!data.result) {	
         alert ('not logged in');
      } else {
         alert ('logged in');
      }
   });

Click-2-call

Contents

Description

The Click-2-Call API allows you to trigger calls from any application by sending a few POST parameters to http://www.poketalk.com/index.php/api/click2call


Getting started

- Make sure you have a positive balance in your PokeTALK account to be able to place calls.

- Register for an API-Key with PokeTALK. You will need to supply the IP address which call requests will be triggered from (for help with this email developers@poketalk.com)


Parameters

Required Name Type Description
required to string full e164 phone number in international format (i.e 1212xxxxxxx)
required from string full e164 phone number in international format (i.e 1212xxxxxxx)
required api_key string Your API-Key as supplied to you by PokeTALK
not required custom string Custom string which you can query to find this specific record. (max 255 chars)
not required eventurl string URL for sending events about changes of call status (max 255 chars), see EventURL section.

Response

 
Parameter Type Description
00 int OK
10 int ERROR. Empty 'api_key' parameter.
20 int ERROR. Empty 'from' parameter.
30 int ERROR. Empty 'to' parameter.
40 int ERROR. Unknown API user.
50 int ERROR. Can`t get service provider.
60 int ERROR. 'from' or 'to' number in blacklist.
70 int ERROR. Can`t get gateway list.
90 int ERROR. Can`t calculate timeout.
100 int ERROR. Unknown API IP address.

Good Practice

- In many countries the leading zero needs to be removed from the number before adding the country prefix, for example, 972054xxxxxxx would be incorrect, whilst 97254xxxxxx would be correct

- For your security, it is good practice to send the call request using "from" or "to" numbers which are pre-stored in your database, and NOT via client-side forms which can be manipulated.


from users of your application it is important that requests sent to PokeTALK containing the "from"


EventURL

Using EventURL you may check status of the initiated call and terminate call, if cost was exceeded or for any other reason.

EventURL may contain following run-time variables in the query part of the URL, which will be replaced with current values:

$webcallid - unique id of the call, set in 'custom' parameter to identify specific call

$status - status of the call, may have one of the following values:

0 - unknown state (indicate some issue)

1 - CallA initiated

2 - CallA failed

3 - CallA answered

4 - CallA disconnected (before CallB was answered)

5 - CallB initiated

6 - CallB failed

7 - CallB answered

8 - CallAB disconnected (after CallB was answered)

$duration - duration of the call (sec)

$debit - current debit corresponding to duration


Server sends HTTP 'GET' request to specified URL each time when status is changing or every 60 sec after CallA was answered

Format of EventURL:

http://<host>[:<port>]/call_report.php?webcallid=$webcallid&status=$status&duration=$duration&debit=$debit

where <port> is optional, and any variable may be omitted


Example of HTTP request and positive response:

GET /call_report.php?webcallid=web1323041193&status=1&duration=0&debit=0.000 HTTP/1.0
Host: my.host.com
User-Agent: ARS 0.1
Accept: */*

HTTP/1.1 200 OK
Date: Sun, 04 Dec 2011 23:26:33 GMT
Server: Apache/2.2.3 (CentOS)
X-Powered-By: PHP/5.1.6
Content-Length: 0
Connection: close
Content-Type: text/html; charset=UTF-8


If you want to terminate call, then HTML code '412 Precondition Failed' should be returned.

Example of HTTP request and negative response (terminate call):

GET /call_report.php?webcallid=web1323041193&status=7&duration=300&debit=0.515 HTTP/1.0
Host: my.host.com
User-Agent: ARS 0.1
Accept: */*

HTTP/1.1 412 Precondition Failed
Date: Sun, 04 Dec 2011 23:31:33 GMT
Server: Apache/2.2.3 (CentOS)
X-Powered-By: PHP/5.1.6
Content-Length: 0
Connection: close
Content-Type: text/html; charset=UTF-8

NOTE: it may take few seconds until call will be really disconnected


Example PHP code, which terminate each call longer than 5 min:

<?php
$status = $_REQUEST['status'];
$duration = $_REQUEST['duration'];
$max_duration = 300;
if ($status == '7' && $duration >= $max_duration)
{
       //disconnect any call longer than $max_duration sec
       header('HTTP/1.1 412 Precondition Failed');
}
else
{
       header('HTTP/1.1 200 OK');
}

?>

Create

Contents

Description

Returns user billing data

Usage

    ptReport.create(from_date, to_date, callback);

or

    var result = ptReport.create(from_date, to_date);

Parameters

Required Name Type Description
required from_date date MySQL date formatted YY-mm-dd, i.e 2009-01-25
required to_date date MySQL date formatted YY-mm-dd, i.e 2009-01-25
optional callback function optional callback function to call after execution

Response

object (JSON)

 
    {"start_balance":float,
     "result":[
               {"date":date,
                "from":string,
                "to":string,
                "billsec":integer,
                "credit":float,
                "debit":float
                 },
            {...},
            {...},
            {...}
        ]
    }
Parameter Type Description
start_balance float returns user balance to start date.
result variable returns user billing items array, false otherwise.
Array
Parameter Type Description
date date date of .
from string from phone number.
to string to phone number.
billsec integer call duration (sec).
credit float deposit sum ($).
debit float call cost ($).

Example

Use result object

var item;
var html   = "";
// Get billing records for January 2009
var report = ptReport.create("2008-12-31", "2009-02-01");
if(!report.result){
    html = 'No billing records for this period';
}else{
    // Get report length
    var len = report.result.length;
    // Create report HTML
    for(var i=0; i<len; i++){
        item = report.result[i];
        // Print calls records only
        if(item.debit != 0){
            html += item.date+" "+item.from+" "+item.to+" "item.billsec+" "+item.debit+"<br />";
        }
    }
}
// Print HTML
document.write(html);

Use callback function

ptReport.create("2008-12-31", "2009-02-01", function(report){
    if(!report.result){
        alert('No billing records for this period');
        return;
    }
    var item;
    var html = "";
    // get report length
    var len = report.result.length;
    // create contact list HTML
    for(var i=0; i<len; i++){
        item = report.result[i];
        // Print calls records only
        if(item.debit != 0){
            html += item.date+" "+item.from+" "+item.to+" "item.billsec+" "+item.debit+"<br />";
        }
    }
    // print HTML
    document.write(html);
});

Get contacts

Contents

Description

Returns user contact list

Usage

    ptAddressbook.get_contacts(callback);

or

    var result = ptAddressbook.get_contacts();

Parameters

Required Name Type Description
optional callback function optional callback function to call after execution

Response

object (JSON)

 
    {"result":[
            {"id":integer,
             "contact_name":string,
             "company":string,
             "code":string,
             "value":string,
             "code_1":string,
             "value_1":string,
             "code_2":string,
             "value_2":string,
             "email":string },
            {...},
            {...},
            {...}
        ]
    }
Parameter Type Description
result variable returns user addressbook items array, false otherwise.
Array
Parameter Type Description
id integer contact ID.
contact_name string contact name.
company string contact company.
code string first phone number country prefix.
value string first phone number (landline).
code_1 string second phone number country prefix.
value_1 string second phone number (mobile).
code_2 string third phone number country prefix.
value_2 string third phone number (office).
email string contact e-mail.

Example

Use result object

function print_contacts(){
    var item;
    var html = "";
    // insert user contact list into data object
    var data = ptAddressbook.get_contacts();
    if(!data.result){
        alert('Your addressbook is empty');
        return;
    }
    // get contact list length
    var len = data.result.length;
    // create contact list HTML
    for(var i=0; i<len; i++){
        item = data.result[i];
        html += "Name: "+item.contact_name+" Phone:+"+item.code+"-"+item.value+"<br />";
    }
    // print HTML
    document.write(html);
}

Use callback function

/* insert user contact list into data object */
ptAddressbook.get_contacts(function(data){
    if(!data.result){
        alert('Your addressbook is empty');
        return;
    }
    var item;
    var html = "";
    // get contact list length
    var len = data.result.length;
    // create contact list HTML
    for(var i=0; i<len; i++){
        item = data.result[i];
        html += "Name: "+item.contact_name+" Phone:+"+item.code+"-"+item.value+"<br />";
    }
    // print HTML
    document.write(html);
});

Is email

Contents

Description

Validate e-mail address

Usage

    var is_mail = ptBase.is_email(address);

Parameters

Required Name Type Description
required address string e-mail address

Return

boolean

Parameter Type Description
result boolean returns true if parameter is valid e-mail address, false otherwise.

Example

Check number with extention

if(ptBase.is_email("lala@nana.com")){
    alert("Is valid address");
}else{
    alert("Not valid address");
}

Login

Contents

Description

This method submits login credentials to the server

Usage

    ptBase.login(email,password,remember_me,callback);

or

    var result = ptBase.check_login(email,password,remember_me);

Parameters

Required Name Type Description
required email string users email address
required password string users password (min 4, max 50 characters)
required remember_me string set to 1 to allow user to stay logged in
optional callback function function to callback after execution

Response

Parameter Type Description
result boolean returns true if the user logged in, false otherwise.
code int error code
msg string error/info message returned

object (JSON)

 
   {"result":false,"code":1,"msg":"please enter a valid email address"}

Example

 
   ptBase.login('example@poketalk.com','password', '1' , function(data){
       if (!data.result){
          alert (data.msg); //error
       } else {
          alert ('do something'); //user logged in successfully
       }
   });

Logout

Contents

Description

This method ends the users session

Usage

    ptBase.logout();

or

    var result = ptBase.logout();

Parameters

Required Name Type Description
none

Response

Parameter Type Description
result boolean returns true if the session ended properly, false otherwise

object (JSON)

 
   {"result":boolean}

Example

 
function logout(){
     ptBase.logout();
}

Make call

Contents

Description

Triggers a callback from the users phone number to a given destination

Usage

    ptBase.make_call(to_prefix,to_number,callback);

or

    var result = ptBase.make_call(to_prefix,to_number);

Parameters

Required Name Type Description
required to_prefix string destination country prefix (i.e. "1" for USA, "44" for UK, etc)
required to_number string destination phone number without the country prefix
optional callback function optional function to callback after execution

Response

object (JSON)

 
    [{"result":boolean,"code":intiger,"msg":string}]
Parameter Type Description
result boolean returns true if call triggered, false if otherwise
code integer error code
msg string error/success message

Example

ptBase.make_call('1','5551234567',function(data){
     if (!data.result) {
	 alert(data.msg);
     } else {
         alert("Now connecting");
     }
});

Remove contact

Contents

Description

Remove contact from user addressbook

Usage

    ptAddressbook.remove_contact(id, callback);

or

    var result = ptAddressbook.remove_contact(id);

Parameters

Required Name Type Description
required id integer contact ID
optional callback function optional callback function to call after execution

Response

object (JSON)

 
    {"result":boolean}
Parameter Type Description
result boolean returns true if contact removed, false otherwise.

Example

Use result object

var data = ptAddressbook.remove_contact(id);
if(data.result){
    alert("Rmoved");
}else{
    alert("Can`t remove contact");
}

Use callback function

ptAddressbook.remove_contact(id, function(data){
    if(data.result){
        alert("Removed");
    }else{
        alert("Can`t remove contact");
    }
});

Set number

Contents

Description

Update the users own phone number

Usage

    ptBase.set_number(prefix,number,callback);

or

    var result = ptBase.set_number(prefix,number);

Parameters

Required Name Type Description
required prefix string country prefix
required number string phone number (without the country prefix)
optional callback function optional callback function to call after execution

Response

object (JSON)

 
    {"result":boolean}
Parameter Type Description
result boolean returns true if phone number has been updated, false otherwise.

Example

Use result object

ptBase.set_number(prefix,phone,function(data){
     if (data.result==true) {
	alert ("New phone number set");
     } else {
        alert ("Oops, something went wrong");
     }
});

Test number

Contents

Description

Validate phone number include extention

Usage

    var is_number = ptBase.test_number(phone_number);

Parameters

Required Name Type Description
required phone_number string phone number include extention, i.e. "97231234567#321"

Return

boolean

Parameter Type Description
result boolean returns true if parameter is a phone number, false otherwise.

Example

Check number with extention

if(ptBase.test_number("97231234567#321")){
    alert("Is number");
}else{
    alert("Not number");
}