Koozali.org: home of the SME Server

click-to-call and egroupware [DONE]

Offline soprom

  • *
  • 589
  • +0/-0
    • www.logiciel-libre.org
click-to-call and egroupware [DONE]
« on: April 01, 2008, 01:29:08 AM »
(Note: this post has been modified)

Egroupware can be used to call a contact.
In addressbook -> Site configuration, set the link to something like:
http://selintra/pbx/call.php?number=%1&accountname=%u&accountphone=%t

Where http://selintra is you PBX box,
/pbx/call.php is the name of the script.

Use a script like this one to execute the call. It must be adapted though...
Code: [Select]
$strHost = "127.0.0.1";
$strWaitTime = "30";
$strPriority = "1";
$strMaxRetry = "2";

$strUser = "<as defined in manager.conf>";
$strSecret = "<as defined in manager.conf>";

# match context or cluster
$strContext = "internal";

# get parameters
$strChannel = "SIP/<YOUR_EXTENSION>;
$number=strtolower($_REQUEST['number']);
$number=ereg_replace("[^A-Za-z0-9]", "", $number);

# quick validation:

if ($number == null) :  exit() ; endif ;
$length = strlen($number); if ($length < 10):  exit() ; endif ;

# action:

$errno=0 ;
$errstr=0 ;
$strCallerId = "Web Call <$number>";
$oSocket = fsockopen ("localhost", 5038, &$errno, &$errstr, 20);

if (!$oSocket) {
  echo "$errstr ($errno)<br>\n";
} else {
fputs($oSocket, "Action: login\r\n");
fputs($oSocket, "Events: off\r\n");
fputs($oSocket, "Username: $strUser\r\n");
fputs($oSocket, "Secret: $strSecret\r\n\r\n");
fputs($oSocket, "Action: originate\r\n");
fputs($oSocket, "Channel: $strChannel\r\n");
fputs($oSocket, "WaitTime: $strWaitTime\r\n");
fputs($oSocket, "CallerId: $strCallerId\r\n");
fputs($oSocket, "Exten: $number\r\n");
fputs($oSocket, "Context: $strContext\r\n");
fputs($oSocket, "Priority: $strPriority\r\n\r\n");
fputs($oSocket, "Action: Logoff\r\n\r\n");
sleep(2);
fclose($oSocket);
}

« Last Edit: April 06, 2008, 07:34:43 PM by soprom »
Sophie from Montréal

Offline soprom

  • *
  • 589
  • +0/-0
    • www.logiciel-libre.org
Re: click-to-call
« Reply #1 on: April 01, 2008, 02:59:53 AM »
The code gives an error with
Code: [Select]
channel.c:2818 __ast_request_and_dial: Unable to request channel SIP/5100
Sophie from Montréal

Offline soprom

  • *
  • 589
  • +0/-0
    • www.logiciel-libre.org
Re: click-to-call
« Reply #2 on: April 05, 2008, 08:14:55 AM »

Nobody is using click-to-call ?
Sophie from Montréal

Offline SARK devs

  • *****
  • 2,806
  • +1/-0
    • http://sarkpbx.com
Re: click-to-call
« Reply #3 on: April 05, 2008, 08:26:57 AM »
This is standard php yes?

It isn't SAIL dependent, except for the context (which for an outbound call should be set to "internal").  It is using the asterisk manager interface to instigate a call.  Have you written this or has it come from a TBox site?  Either way it should work just fine in exactly the same way as it did wherever it came from.

Kind Regards

Offline soprom

  • *
  • 589
  • +0/-0
    • www.logiciel-libre.org
Re: click-to-call and egroupware [DONE]
« Reply #4 on: April 06, 2008, 05:31:37 PM »
it works...
I modified the first post.
Sophie from Montréal

Offline Franco

  • *
  • 1,171
  • +0/-0
    • http://contribs.org
Re: click-to-call and egroupware [DONE]
« Reply #5 on: April 08, 2008, 10:00:22 PM »
Hi,
This is very interesting!
Does the client uses a web application or does this script invokes a e-groupware app?

Offline soprom

  • *
  • 589
  • +0/-0
    • www.logiciel-libre.org
Re: click-to-call and egroupware [DONE]
« Reply #6 on: April 08, 2008, 11:00:40 PM »
The script in the first post is placed on the PBX.
I created an IBAY (no internet access) to store those scripts.
EGroupware is then configured to call it.

The way it works is that a click on the phonenumber in the address book is linked to the script. Then the specified extension is called (my phone). If I pickup the phone, the system then calls the number obtained from the address book.
« Last Edit: April 08, 2008, 11:02:47 PM by soprom »
Sophie from Montréal

Offline soprom

  • *
  • 589
  • +0/-0
    • www.logiciel-libre.org
Re: click-to-call and egroupware [DONE]
« Reply #7 on: April 09, 2008, 02:10:59 AM »
Corrections are needed on the script:

These lines:
$strHost = "127.0.0.1";
$oSocket = fsockopen ("localhost", 5038, &$errno, &$errstr, 20);

Are changed to:
$strHost = "192.168.X.Y"; // address of pbx as in manager.conf bindaddr=192.168.X.Y
$oSocket = fsockopen ($strHost, 5038, &$errno, &$errstr, 20);

Sophie from Montréal

Offline Franco

  • *
  • 1,171
  • +0/-0
    • http://contribs.org
Re: click-to-call and egroupware [DONE]
« Reply #8 on: April 09, 2008, 04:33:30 AM »
Hello,
I'm trying to get this to work.
Where do I find:
Code: [Select]
$strUser = "<as defined in manager.conf>";

Offline soprom

  • *
  • 589
  • +0/-0
    • www.logiciel-libre.org
Re: click-to-call and egroupware [DONE]
« Reply #9 on: April 09, 2008, 05:00:59 AM »
Look in manager.conf to see what is the username.
It should be remote_mgr between brackets ([remote_mgr]). Password will be the secret in the same section.

In other words, the usename is the title of the section (between brackets).

The bindaddr=x.x.x.x in the section [general] will tell you what to set as host.
This should your lan PBX's ip.
Sophie from Montréal

Offline soprom

  • *
  • 589
  • +0/-0
    • www.logiciel-libre.org
Re: click-to-call and egroupware [DONE]
« Reply #10 on: April 09, 2008, 06:11:32 AM »
If you define the link in EGroupware as shown in the first post, you can also create a custom field in the address book named pbx_extension to store a value for $strChannel.

Remember not to allow internet access to this script...

This code will get the extension for the user who clicked the link:
Code: [Select]
$strChannel = ""; // instead of $_REQUEST['exten'];
$accountname= $_REQUEST['accountname'];
$account= $_REQUEST['account'];

$egwHost="x.x.x.x"; // server running egroupware
$egwUser="xxxxx";  // username to access through lan
$egwPass="xxxxx";  // password for that user
$egwData="xxxxx";  // database name like egroupware

$connect = TRUE;
$connect = mysql_connect($egwHost,$egwUser,$egwPass) or die("Pas de connexion au serveur");
mysql_select_db($egwData, $connect) or die("Pas de connexion à la base");

$query = "
SELECT
egw_addressbook.account_id,
egw_addressbook_extra.contact_name,
egw_addressbook_extra.contact_value,
egw_accounts.account_lid
FROM
(egw_addressbook
INNER JOIN egw_addressbook_extra
ON egw_addressbook.contact_id =egw_addressbook_extra.contact_id)
INNER JOIN egw_accounts
ON egw_addressbook.account_id = egw_accounts.account_id
WHERE
(((egw_addressbook_extra.contact_name)='pbx_extension')
AND ((egw_accounts.account_lid)='".$accountname."'));";

//echo "<br>Requete:".$query;

$result = mysql_query($query) or die ("Exécution de la requête impossible");
$row = mysql_fetch_array($result);
$strChannel = $row[contact_value];
mysql_close();
//echo "<br>Extension : " .$strChannel;

I'm no expert in php but this works!
Sophie from Montréal

Offline soprom

  • *
  • 589
  • +0/-0
    • www.logiciel-libre.org
Re: click-to-call and egroupware [DONE]
« Reply #11 on: April 10, 2008, 06:13:39 AM »
Don't forget to enable mysql on the lan if using 2 different machines:
Code: [Select]
config setprop mysqld LocalNetworkingOnly no
 expand-template /etc/my.cnf
 /etc/rc.d/init.d/mysqld restart
Sophie from Montréal

Offline fpausp

  • *
  • 728
  • +0/-0
Re: click-to-call and egroupware [DONE]
« Reply #12 on: April 10, 2008, 09:23:55 PM »
Hi soprom,

I like to test click-to-call, i tried your description but something went wrong, can you please write a more detailed how to for us ?

regards
fpausp
Viribus unitis

Offline Franco

  • *
  • 1,171
  • +0/-0
    • http://contribs.org
Re: click-to-call and egroupware [DONE]
« Reply #13 on: April 10, 2008, 09:27:43 PM »
Hi soprom,

I like to test click-to-call, i tried your description but something went wrong, can you please write a more detailed how to for us ?

regards
fpausp

I couldn't get it to work either :(

Offline soprom

  • *
  • 589
  • +0/-0
    • www.logiciel-libre.org
Re: click-to-call and egroupware [DONE]
« Reply #14 on: April 11, 2008, 03:12:54 AM »
I'm sorry to see that you have problems with my posts. I know I was not very coherent.
Here is a howto I just wrote for you. The script I'm proposing is the script I currently use, edited for the howto.

The adress is:
http://www.logiciel-libre.org/?Produits:EGroupware:Int%E9gration_PBX:Howto

ps

1. Montréal is actually winning over Boston and the howto could have suffered from that!!!
2. And no, it's not me on the photo on my web site
Sophie from Montréal